OtsoSilver

Untitled

Aug 22nd, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #pgzero
  2.  
  3. WIDTH = 600 # Ширина окна
  4. HEIGHT = 300 # Высота окна
  5.  
  6. TITLE = "Инопланетный раннер" # Заголовок окна игры
  7. FPS = 30 # Количество кадров в секунду
  8.  
  9. # Объекты
  10. alien = Actor('alien', (50, 240))
  11. fon = Actor("fon")
  12. box = Actor('box', (550, 265))
  13. bee = Actor('bee', (850, 175))
  14. go = Actor("GO")
  15. game_over = 0
  16. count = 0
  17.  
  18. def draw():
  19. fon.draw()
  20. alien.draw()
  21. box.draw()
  22. bee.draw()
  23. screen.draw.text(count, pos=(10, 10), color="white", fontsize = 24)
  24. if game_over == 1:
  25. go.draw()
  26. screen.draw.text('Нажмите Enter', pos=(170, 150), color="white", fontsize = 36)
  27.  
  28. def update(dt):
  29. global game_over
  30. global count
  31. # Движение пчелы
  32. if bee.x > -20:
  33. bee.x = bee.x - 5
  34. else:
  35. bee.x = WIDTH + 20
  36. count = count + 1
  37.  
  38. # Движение коробки
  39. if box.x > -20:
  40. box.x = box.x - 5
  41. box.angle = box.angle + 5
  42. else:
  43. box.x = WIDTH + 20
  44. count = count + 1
  45.  
  46. # Управление
  47. if keyboard.left or keyboard.a and alien.x > 20:
  48. alien.x = alien.x - 5
  49. alien.image = 'left'
  50. elif keyboard.right or keyboard.d and alien.x < 580:
  51. alien.x = alien.x + 5
  52. alien.image = 'right'
  53. elif keyboard.down or keyboard.s:
  54. alien.image = 'duck'
  55. alien.y = 250
  56. else:
  57. alien.image = 'alien'
  58. if alien.y > 240:
  59. alien.y = 240
  60.  
  61. if game_over == 1 and keyboard.enter:
  62. game_over = 0
  63. count = 0
  64. alien.pos = (50, 240)
  65. box.pos =(550, 265)
  66. bee.pos = (850, 175)
  67.  
  68. # Столкновение
  69. if alien.colliderect(box) or alien.colliderect(bee):
  70. game_over = 1
  71.  
  72. def on_key_down(key):
  73. # Прыжок
  74. if keyboard.space or keyboard.up or keyboard.w:
  75. alien.y = 100
  76. animate(alien, tween='bounce_end', duration=2, y=240)
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment