Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import arcade
- class Ball(arcade.Sprite):
- def update(self):
- self.center_x += self.change_x
- if self.right > 800 or self.left < 0:
- self.change_x = - self.change_x
- self.center_y += self.change_y
- if self.bottom < 0 or self.top > 600:
- self.change_y = - self.change_y
- class Paddle(arcade.Sprite):
- def update(self):
- self.center_x += self.change_x
- class GameWindow(arcade.Window):
- # конструктор - вызывается при создании объекта
- def __init__(self, width, height, title):
- super().__init__(width, height, title)
- self.ball = Ball("ping-pong/ball.png", 0.1)
- self.paddle = Paddle("ping-pong/plat.png", 0.3)
- # начальные координаты
- def setup(self):
- self.ball.center_x = 400
- self.ball.center_y = 300
- self.ball.change_x = 5
- self.ball.change_y = -3
- self.paddle.center_x = 400
- self.paddle.center_y = 100
- # отрисовка
- def on_draw(self):
- arcade.start_render() # начало отрисовки
- arcade.set_background_color((107, 78, 135))
- self.ball.draw()
- self.paddle.draw()
- # смена кадров, игровая логика
- def on_update(self, delta_time: float):
- self.ball.update()
- self.paddle.update()
- window = GameWindow(800, 600, "Пинг-понг")
- window.setup()
- arcade.run() # запускает цикл обработки событий
Advertisement
Add Comment
Please, Sign In to add comment