Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import sys
- # Инициализируем pygame
- pygame.init()
- # Параметры окна
- WIDTH, HEIGHT = 980, 860
- FPS = 60
- # Настраиваем окно
- screen = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption("Game of Ers")
- clock = pygame.time.Clock()
- # Цвета
- BLACK = (255, 255, 255)
- # Шрифты
- font = pygame.font.SysFont("Arial", 32)
- # Параметры корзины
- basket_width = 100
- basket_height = 50
- basket_speed = 15
- # Параметры яиц
- egg_radius = 15
- egg_fall_speed = 10
- spawn_delay = 60
- # Количество жизней
- lives = 1000
- score = 0
- # Стартовая позиция корзины
- basket_x = WIDTH // 2 - basket_width // 2
- basket_y = HEIGHT - basket_height - 10
- # Список яиц
- eggs = []
- frame_count = 0
- # === Загрузка изображений ===
- basket_img = pygame.image.load("basket.png")
- egg_img = pygame.image.load("egg.png")
- background_img = pygame.image.load("background.jpg")
- # Масштабирование
- basket_img = pygame.transform.scale(basket_img, (basket_width, basket_height))
- egg_img = pygame.transform.scale(egg_img, (egg_radius * 2, egg_radius * 2))
- background_img = pygame.transform.scale(background_img, (WIDTH, HEIGHT))
- def draw_basket(x, y):
- screen.blit(basket_img, (x, y))
- def draw_egg(egg):
- egg_rect = egg_img.get_rect(center=(egg["x"], egg["y"]))
- screen.blit(egg_img, egg_rect)
- def main():
- global basket_x, basket_y
- global score, lives, frame_count
- running = True
- while running:
- clock.tick(FPS)
- screen.blit(background_img, (0, 0)) # Рисуем фон
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- # Управление
- keys = pygame.key.get_pressed()
- if keys[pygame.K_LEFT] and basket_x > 0:
- basket_x -= basket_speed
- if keys[pygame.K_RIGHT] and basket_x < WIDTH - basket_width:
- basket_x += basket_speed
- # Создание яйца
- frame_count += 1
- if frame_count % spawn_delay == 0:
- eggs.append({
- "x": random.randint(egg_radius, WIDTH - egg_radius),
- "y": 0
- })
- # Обработка яиц
- for egg in eggs[:]:
- egg["y"] += egg_fall_speed
- if (basket_y <= egg["y"] + egg_radius <= basket_y + basket_height and
- basket_x <= egg["x"] <= basket_x + basket_width):
- score += 1
- eggs.remove(egg)
- elif egg["y"] - egg_radius > HEIGHT:
- lives -= 1
- eggs.remove(egg)
- # Отрисовка
- for egg in eggs:
- draw_egg(egg)
- draw_basket(basket_x, basket_y)
- score_text = font.render(f"Score: {score}", True, BLACK)
- lives_text = font.render(f"Lives: {lives}", True, BLACK)
- screen.blit(score_text, (10, 10))
- screen.blit(lives_text, (10, 50))
- # Проверка на game over
- if lives <= 0:
- game_over_text = font.render("GAME OVER", True, (200, 0, 0))
- screen.blit(game_over_text, (WIDTH // 2 - 80, HEIGHT // 2 - 20))
- pygame.display.flip()
- pygame.time.wait(3000)
- running = False
- pygame.display.flip()
- pygame.quit()
- sys.exit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement