• API
• FAQ
• Tools
• Archive
daily pastebin goal
16%
SHARE
TWEET

# Untitled

a guest Feb 13th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from kivy.app import App
2. from kivy.uix.widget import Widget
3. from kivy.properties import NumericProperty, ReferenceListProperty,\
4.     ObjectProperty, ListProperty
5. from kivy.vector import Vector
6. from kivy.clock import Clock
7. from random import randint
8. from kivy.factory import Factory
9.
10.
11. class PongGame(Widget):
12.
13.     def PongBall(Widget):
14.         velocity_x = NumericProperty(0)
15.         velocity_y = NumericProperty(0)
16.         velocity = ReferenceListProperty(velocity_x, velocity_y)
17.         with self.canvas:
18.             Color(0,1,1,1)
19.             self.size=(50, 5)
20.             self.elip = Ellipse(pos=self.pos, size=self.size)
21.
22.     balls = ListProperty()
23.
24.     def move(self):
25.         self.pos = Vector(*self.velocity) + self.pos
26.
28.         ball = Factory.PongBall()
29.         ball.center = self.center
30.         ball.velocity = Vector(2, 0).rotate(randint(-45, 45))
32.         self.balls.append(ball)
33.
34.     def update(self, dt):
35.
36.         for ball in self.balls:
37.
38.             self.ball.move()
39.
40.             #bounce off top and bottom
41.             if (self.ball.y < 0) or (self.ball.top > self.height):
42.                 self.ball.velocity_y *= -1.00
43.
44.             #bounce off left and right
45.             if (self.ball.x < 0) or (self.ball.right > self.width):
46.                 self.ball.velocity_x *= -1.00
47.
48. class PongApp(App):
49.     def build(self):
50.         game = PongGame()