Advertisement
Roman9234

Untitled

Mar 23rd, 2024
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. import arcade
  2.  
  3. SCREEN_WIDTH = 900  # ширина экрана
  4. SCREEN_HEIGHT = 600  # высота экрана
  5. SCREEN_TITLE = "Пинг-понг"
  6. BG_COLOR = (161, 183, 56)
  7.  
  8. SPEEDX = 5
  9. SPEEDY = 5
  10. BALL_IMG = "ping-pong/images/ball.png"
  11. BALL_SCALE = 0.1
  12.  
  13. PLAT_IMG = "ping-pong/images/platform.png"
  14. PLAT_SCALE = 0.1
  15.  
  16.  
  17. class Ball(arcade.Sprite):
  18.     def update(self):
  19.         self.center_x += self.change_x
  20.         if self.right > SCREEN_WIDTH or self.left < 0:
  21.             self.change_x = - self.change_x
  22.         self.center_y += self.change_y
  23.         if self.top > SCREEN_HEIGHT or self.bottom < 0:
  24.             self.change_y = - self.change_y
  25.  
  26.  
  27. class Platform(arcade.Sprite):
  28.     def update(self):
  29.         self.center_x += self.change_x
  30.  
  31.  
  32. class GameWindow(arcade.Window):
  33.     # конструктор
  34.     def __init__(self, width, height, title):
  35.         super().__init__(width, height, title)
  36.         self.ball = Ball(BALL_IMG, BALL_SCALE)
  37.         self.ball.center_x = SCREEN_WIDTH/2
  38.         self.ball.center_y = SCREEN_HEIGHT/2
  39.         self.ball.change_x = SPEEDX
  40.         self.ball.change_y = SPEEDY
  41.         self.platform = Platform(PLAT_IMG, PLAT_SCALE)
  42.         self.platform.center_x = SCREEN_WIDTH/2
  43.         self.platform.center_y = SCREEN_HEIGHT/12
  44.  
  45.     # отрисовка
  46.     def on_draw(self):
  47.         arcade.start_render()  # начало отрисовка
  48.         arcade.set_background_color(BG_COLOR)
  49.         self.ball.draw()
  50.         self.platform.draw()
  51.  
  52.     # обновление окна, игровая логика
  53.     def on_update(self, delta_time: float):
  54.         self.ball.update()
  55.         self.platform.update()
  56.         if self.ball.bottom < self.platform.top :
  57.             self.ball.change_y = - self.ball.change_y
  58.  
  59.  
  60. window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
  61. arcade.run()
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement