-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbouncingBall.py
43 lines (34 loc) · 1.13 KB
/
bouncingBall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pygame
import pygameFramework
class bouncingBall(pygameFramework.PygameGame):
def init(self):
super(bouncingBall, self).__init__()
self.color = (0,255,0)
self.cx = 100
self.cy = 100
self.r = 5
self.dy = 5
self.currDy = 0
self.upHeight = 10
self.jump = False
self.ball = ((self.cx, self.cy), self.r, self.color)
self.image = pygame.Surface((2*self.r, 2*self.r), pygame.SRCALPHA)
def getBall(self):
self.ball = ((self.cx, self.cy), self.r, self.color)
def drawBall(self, screen):
pygame.draw.circle(screen, self.color, (self.cx, self.cy), self.r)
def keyPressed(self, keyCode, modifier):
if not self.jump: self.jump = True
def redrawAll(self, screen):
self.drawBall(screen)
def timerFired(self, dt):
if self.currDy >= self.upHeight:
self.currDy = 0
self.jump = False
if self.jump:
self.cy -= self.dy
self.currDy += 1/2
else:
self.cy += self.dy
game = bouncingBall()
game.run()