Advertisement
Guest User

new

a guest
Apr 30th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.uix.widget import Widget
  3.  
  4.  
  5. class PongGame(Widget):
  6.     pass
  7.  
  8.  
  9. class PongApp(App):
  10.     def build(self):
  11.         return PongGame()
  12.  
  13.  
  14. if __name__ == '__main__':
  15.     PongApp().run()
  16.    
  17.   <PongGame>:    
  18.     canvas:
  19.         Rectangle:
  20.             pos: self.center_x - 5, 0
  21.             size: 10, self.height
  22.            
  23.     Label:
  24.         font_size: 70  
  25.         center_x: root.width / 4
  26.         top: root.top - 50
  27.         text: "0"
  28.        
  29.     Label:
  30.         font_size: 70  
  31.         center_x: root.width * 3 / 4
  32.         top: root.top - 50
  33.         text: "0"
  34.    
  35.     class PongBall(Widget):
  36.  
  37.     # velocity of the ball on x and y axis
  38.     velocity_x = NumericProperty(0)
  39.     velocity_y = NumericProperty(0)
  40.  
  41.     # referencelist property so we can use ball.velocity as
  42.     # a shorthand, just like e.g. w.pos for w.x and w.y
  43.     velocity = ReferenceListProperty(velocity_x, velocity_y)
  44.  
  45.     # ``move`` function will move the ball one step. This
  46.     #  will be called in equal intervals to animate the ball
  47.     def move(self):
  48.         self.pos = Vector(*self.velocity) + self.pos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement