forked from nvmao/bouncing-ball-pybox2d-part-5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
63 lines (48 loc) · 1.65 KB
/
Game.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pygame import Vector2
from Ball import Ball
from Ring import Ring
from Sounds import sounds
from utils import utils
class Game:
def __init__(self):
self.center = Vector2(utils.width/2,utils.height/2)
self.ball = Ball(Vector2(utils.width / 2, utils.height / 2), 1, (255, 255, 255))
self.particles = []
self.rings = [
]
radius = 5
numRings = 16
rotateSpeed = 1
hue = 0
for i in range(numRings):
ring = Ring(self.center, radius, rotateSpeed, 50,hue)
radius += 1.4
rotateSpeed *= 1.2
hue += 1/numRings
self.rings.append(ring)
def update(self):
utils.world.Step(1.0 / 60.0, 6, 2)
if utils.contactListener:
for bodyA,bodyB in utils.contactListener.collisions:
sounds.play()
break
utils.contactListener.collisions = []
if len(self.rings) > 0:
if self.center.distance_to(self.ball.getPos()) > self.rings[0].radius * 10:
self.rings[0].destroyFlag = True
utils.world.DestroyBody(self.rings[0].body)
for ring in self.rings:
if ring.destroyFlag:
self.particles += ring.spawParticles()
self.rings.remove(ring)
sounds.playDestroySound()
for exp in self.particles:
exp.update()
if len(exp.particles) == 0:
self.particles.remove(exp)
def draw(self):
for ring in self.rings:
ring.draw()
self.ball.draw()
for exp in self.particles:
exp.draw()