Roman9234

Untitled

Mar 27th, 2024
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import arcade
  2.  
  3.  
  4. class Ball(arcade.Sprite):
  5.     def update(self):
  6.         self.center_x += self.change_x
  7.         if self.right > 800 or self.left < 0:
  8.             self.change_x = - self.change_x
  9.         self.center_y += self.change_y
  10.         if self.bottom < 0 or self.top > 600:
  11.             self.change_y = - self.change_y
  12.  
  13.  
  14. class Paddle(arcade.Sprite):
  15.     def update(self):
  16.         self.center_x += self.change_x
  17.  
  18.  
  19. class GameWindow(arcade.Window):
  20.     # конструктор - вызывается при создании объекта
  21.     def __init__(self, width, height, title):
  22.         super().__init__(width, height, title)
  23.         self.ball = Ball("ping-pong/ball.png", 0.1)
  24.         self.paddle = Paddle("ping-pong/plat.png", 0.3)
  25.    
  26.     # начальные координаты    
  27.     def setup(self):
  28.         self.ball.center_x = 400
  29.         self.ball.center_y = 300
  30.         self.ball.change_x = 5
  31.         self.ball.change_y = -3
  32.         self.paddle.center_x = 400
  33.         self.paddle.center_y = 100
  34.  
  35.     # отрисовка
  36.     def on_draw(self):
  37.         arcade.start_render()  # начало отрисовки
  38.         arcade.set_background_color((107, 78, 135))
  39.         self.ball.draw()
  40.         self.paddle.draw()
  41.  
  42.     # смена кадров, игровая логика
  43.     def on_update(self, delta_time: float):
  44.         self.ball.update()
  45.         self.paddle.update()
  46.  
  47.  
  48. window = GameWindow(800, 600, "Пинг-понг")
  49. window.setup()
  50. arcade.run()  # запускает цикл обработки событий
  51.  
Advertisement
Add Comment
Please, Sign In to add comment