Python:
import random
import pygame
# Initialize Pygame
pygame.init()
score=0
# Set up the game window
window_width = 1280
window_height = 900
game_window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("My Game")
#спрайт врагов
target_image = pygame.image.load("banan.png")
# Set up the clock
clock = pygame.time.Clock()
# Set up the target coordinates and timer
target_x = random.randint(0,1280)
target_y = random.randint(0, 900)
target_timer = 0
# Define the bullet class
class Bullet:
def __init__(self, x, y, velocity):
self.x = x
self.y = y
self.velocity = velocity
self.image = pygame.image.load('pula.jpg')
# Create an empty list to store active bullets
bullets = []
#столкновение с препят 0, 540, 900, 70
class Obstacle(pygame.sprite.Sprite):
def __init__(self, x, y, width, height):
super().__init__()
self.rect = pygame.Rect(x, y, width, height)
self.color = (165, 42, 42)
def draw(self,game_window):
pygame.draw.rect(game_window, self.color, self.rect)
# Create the obstacle objects
obstacle1 = Obstacle(0, 850, 1300, 100)
obstacle2 = Obstacle(0, 0, 10, 1000)
obstacles = pygame.sprite.Group(obstacle1,obstacle2)
# Set up the game loop
clock = pygame.time.Clock()
game_running = True
# Game objects
player_x = 400
player_y = 300
player_width = 50
player_height = 50
player_color = (255, 0, 0)
player_speed=5
image=pygame.image.load('petux.png')
image_flipped = pygame.transform.flip (image, True, False)
rectangle = pygame.Rect(0, 540, 900, 70)
brown = (165, 42, 42)
# Main game loop
background = pygame.image.load( 'ostrov.jpg')
background_rect = background.get_rect()
while game_running:
pygame.display.update()
game_window.blit(background, background_rect)
bullet = Bullet(player_x, player_y+3, (0, -10))
player_y+=2 #гравитация
#рисуем петуха
petux=game_window.blit(image_flipped,(player_x, player_y,) )
key = pygame.key.get_pressed()
bullet.y=-100
# Update the position of each active bullet and draw it to the screen
for bullet in bullets:
bullet.x += bullet.velocity[0]
bullet.y += bullet.velocity[1]
game_window.blit(bullet.image, (bullet.x, bullet.y))
# When the player presses the shoot button, create a new bullet object and add it to the list
pressed = pygame.mouse.get_pressed()
if bullet.y<50:
if pressed[0]:
bullet = Bullet(player_x, player_y, (0, -10))
bullets.append(bullet)
pygame.display.update()
# Handle events
#проверка на столкновение
if player_y>=670:
player_y-=2
pygame.display.update()
for obstacle in obstacles:
if petux.colliderect(obstacle.rect):
# Prevent the player from moving in the direction of the obstacle
if key[pygame.K_LEFT]:
player_x += 5
pygame.display.update()
if key[pygame.K_RIGHT]:
player_x -= 5
pygame.display.update()
if key[pygame.K_DOWN]:
player_y -= 1
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_running = False
target_timer += clock.tick(60)
# Check if it's time to show a new target
if target_timer >= 1500:
target_x = random.randint(0, 640)
target_y = random.randint(0, 480)
target_timer = 0
pygame.display.update()
# Draw the screen
game_window.blit(target_image, (target_x, target_y))
pygame.display.update()
# Update game objects
if key[pygame.K_UP]:
player_y -= 10
pygame.display.update()
if key[pygame.K_LEFT]:
player_x -= 10
pygame.display.update()
if key[pygame.K_RIGHT]:
player_x += 10
game_window.blit(image_flipped,(player_x, player_y,) )
pygame.display.update()
clock.tick(60)
pygame.display.update()
# Draw game objects
"""
draw(obstacle2,game_window)
draw(obstacle1,game_window)
pygame.display.update()
"""
# Limit the frame rate
# Quit Pygame
pygame.quit()
Буду очень признателен за помощь.