Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.uix.widget import Widget
- class PongGame(Widget):
- pass
- class PongApp(App):
- def build(self):
- return PongGame()
- if __name__ == '__main__':
- PongApp().run()
- <PongGame>:
- canvas:
- Rectangle:
- pos: self.center_x - 5, 0
- size: 10, self.height
- Label:
- font_size: 70
- center_x: root.width / 4
- top: root.top - 50
- text: "0"
- Label:
- font_size: 70
- center_x: root.width * 3 / 4
- top: root.top - 50
- text: "0"
- class PongBall(Widget):
- # velocity of the ball on x and y axis
- velocity_x = NumericProperty(0)
- velocity_y = NumericProperty(0)
- # referencelist property so we can use ball.velocity as
- # a shorthand, just like e.g. w.pos for w.x and w.y
- velocity = ReferenceListProperty(velocity_x, velocity_y)
- # ``move`` function will move the ball one step. This
- # will be called in equal intervals to animate the ball
- def move(self):
- self.pos = Vector(*self.velocity) + self.pos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement