Advertisement
ateyevtm

Untitled

Mar 23rd, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. import pygame
  2. import random
  3. import sys
  4.  
  5. # Инициализируем pygame
  6. pygame.init()
  7.  
  8. # Параметры окна
  9. WIDTH, HEIGHT = 980, 860
  10. FPS = 60
  11.  
  12. # Настраиваем окно
  13. screen = pygame.display.set_mode((WIDTH, HEIGHT))
  14. pygame.display.set_caption("Game of Ers")
  15.  
  16. clock = pygame.time.Clock()
  17.  
  18. # Цвета
  19. BLACK = (255, 255, 255)
  20.  
  21. # Шрифты
  22. font = pygame.font.SysFont("Arial", 32)
  23.  
  24. # Параметры корзины
  25. basket_width = 100
  26. basket_height = 50
  27. basket_speed = 15
  28.  
  29. # Параметры яиц
  30. egg_radius = 15
  31. egg_fall_speed = 10
  32. spawn_delay = 60
  33.  
  34. # Количество жизней
  35. lives = 1000
  36. score = 0
  37.  
  38. # Стартовая позиция корзины
  39. basket_x = WIDTH // 2 - basket_width // 2
  40. basket_y = HEIGHT - basket_height - 10
  41.  
  42. # Список яиц
  43. eggs = []
  44.  
  45. frame_count = 0
  46.  
  47. # === Загрузка изображений ===
  48. basket_img = pygame.image.load("basket.png")
  49. egg_img = pygame.image.load("egg.png")
  50. background_img = pygame.image.load("background.jpg")
  51.  
  52. # Масштабирование
  53. basket_img = pygame.transform.scale(basket_img, (basket_width, basket_height))
  54. egg_img = pygame.transform.scale(egg_img, (egg_radius * 2, egg_radius * 2))
  55. background_img = pygame.transform.scale(background_img, (WIDTH, HEIGHT))
  56.  
  57.  
  58. def draw_basket(x, y):
  59. screen.blit(basket_img, (x, y))
  60.  
  61.  
  62. def draw_egg(egg):
  63. egg_rect = egg_img.get_rect(center=(egg["x"], egg["y"]))
  64. screen.blit(egg_img, egg_rect)
  65.  
  66.  
  67. def main():
  68. global basket_x, basket_y
  69. global score, lives, frame_count
  70.  
  71. running = True
  72.  
  73. while running:
  74. clock.tick(FPS)
  75. screen.blit(background_img, (0, 0)) # Рисуем фон
  76.  
  77. for event in pygame.event.get():
  78. if event.type == pygame.QUIT:
  79. running = False
  80.  
  81. # Управление
  82. keys = pygame.key.get_pressed()
  83. if keys[pygame.K_LEFT] and basket_x > 0:
  84. basket_x -= basket_speed
  85. if keys[pygame.K_RIGHT] and basket_x < WIDTH - basket_width:
  86. basket_x += basket_speed
  87.  
  88. # Создание яйца
  89. frame_count += 1
  90. if frame_count % spawn_delay == 0:
  91. eggs.append({
  92. "x": random.randint(egg_radius, WIDTH - egg_radius),
  93. "y": 0
  94. })
  95.  
  96. # Обработка яиц
  97. for egg in eggs[:]:
  98. egg["y"] += egg_fall_speed
  99.  
  100. if (basket_y <= egg["y"] + egg_radius <= basket_y + basket_height and
  101. basket_x <= egg["x"] <= basket_x + basket_width):
  102. score += 1
  103. eggs.remove(egg)
  104. elif egg["y"] - egg_radius > HEIGHT:
  105. lives -= 1
  106. eggs.remove(egg)
  107.  
  108. # Отрисовка
  109. for egg in eggs:
  110. draw_egg(egg)
  111.  
  112. draw_basket(basket_x, basket_y)
  113.  
  114. score_text = font.render(f"Score: {score}", True, BLACK)
  115. lives_text = font.render(f"Lives: {lives}", True, BLACK)
  116. screen.blit(score_text, (10, 10))
  117. screen.blit(lives_text, (10, 50))
  118.  
  119. # Проверка на game over
  120. if lives <= 0:
  121. game_over_text = font.render("GAME OVER", True, (200, 0, 0))
  122. screen.blit(game_over_text, (WIDTH // 2 - 80, HEIGHT // 2 - 20))
  123. pygame.display.flip()
  124. pygame.time.wait(3000)
  125. running = False
  126.  
  127. pygame.display.flip()
  128.  
  129. pygame.quit()
  130. sys.exit()
  131.  
  132.  
  133. if __name__ == "__main__":
  134. main()
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement