1
from kivy.app import App
2
from kivy.uix.widget import Widget
3
from kivy.properties import NumericProperty, ReferenceListProperty,\
5
from kivy.vector import Vector
6
from kivy.clock import Clock
7
from random import randint
10
class PongBall(Widget):
11
velocity_x = NumericProperty(0)
12
velocity_y = NumericProperty(0)
13
velocity = ReferenceListProperty(velocity_x, velocity_y)
16
self.pos = Vector(*self.velocity) + self.pos
19
class PongGame(Widget):
20
ball = ObjectProperty(None)
23
self.ball.center = self.center
24
self.ball.velocity = Vector(4, 0).rotate(randint(0, 360))
29
#bounce off top and bottom
30
if (self.ball.y < 0) or (self.ball.top > self.height):
31
self.ball.velocity_y *= -1
33
#bounce off left and right
34
if (self.ball.x < 0) or (self.ball.right > self.width):
35
self.ball.velocity_x *= -1
42
Clock.schedule_interval(game.update, 1.0 / 60.0)
46
if __name__ == '__main__':