~ubuntu-branches/debian/stretch/electrum/stretch

« back to all changes in this revision

Viewing changes to gui/kivy/tools/.buildozer/android/platform/python-for-android/dist/kivy/python-install/share/kivy-examples/tutorials/pong/steps/step4/main.py

  • Committer: Package Import Robot
  • Author(s): Tristan Seligmann
  • Date: 2016-04-04 03:02:39 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20160404030239-0szgkio8yryjv7c9
Tags: 2.6.3-1
* New upstream release.
  - Drop backported install-wizard-connect.patch.
* Add Suggests: python-zbar and update the installation hint to suggest
  apt-get instead of pip (closes: #819517).
* Bump Standards-Version to 3.9.7 (no changes).
* Update Vcs-* links.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from kivy.app import App
 
2
from kivy.uix.widget import Widget
 
3
from kivy.properties import NumericProperty, ReferenceListProperty,\
 
4
    ObjectProperty
 
5
from kivy.vector import Vector
 
6
from kivy.clock import Clock
 
7
from random import randint
 
8
 
 
9
 
 
10
class PongBall(Widget):
 
11
    velocity_x = NumericProperty(0)
 
12
    velocity_y = NumericProperty(0)
 
13
    velocity = ReferenceListProperty(velocity_x, velocity_y)
 
14
 
 
15
    def move(self):
 
16
        self.pos = Vector(*self.velocity) + self.pos
 
17
 
 
18
 
 
19
class PongGame(Widget):
 
20
    ball = ObjectProperty(None)
 
21
 
 
22
    def serve_ball(self):
 
23
        self.ball.center = self.center
 
24
        self.ball.velocity = Vector(4, 0).rotate(randint(0, 360))
 
25
 
 
26
    def update(self, dt):
 
27
        self.ball.move()
 
28
 
 
29
        #bounce off top and bottom
 
30
        if (self.ball.y < 0) or (self.ball.top > self.height):
 
31
            self.ball.velocity_y *= -1
 
32
 
 
33
        #bounce off left and right
 
34
        if (self.ball.x < 0) or (self.ball.right > self.width):
 
35
            self.ball.velocity_x *= -1
 
36
 
 
37
 
 
38
class PongApp(App):
 
39
    def build(self):
 
40
        game = PongGame()
 
41
        game.serve_ball()
 
42
        Clock.schedule_interval(game.update, 1.0 / 60.0)
 
43
        return game
 
44
 
 
45
 
 
46
if __name__ == '__main__':
 
47
    PongApp().run()