diff options
author | Tim Ansell <mithro@mithis.com> | 2009-01-22 13:19:51 (GMT) |
---|---|---|
committer | Tim Ansell <mithro@mithis.com> | 2009-01-22 13:19:51 (GMT) |
commit | 894e5e43eaf957d47be73ee2823eb5f3fe4a6df2 (patch) | |
tree | b92b7cf4d69ca3024df69137875be81fa77ce8ea | |
parent | befe9effe57774d3cc583b44624b34455007efa2 (diff) |
Added a score. Added code to make it harder.
-rw-r--r-- | ovpc.py | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -26,11 +26,30 @@ raptor_anim = pyglet.image.Animation.from_image_sequence( [pyglet.resource.image(x) for x in raptor_anim_files], 0.1, True) -pack = [pyglet.sprite.Sprite(raptor_anim, batch=batch) for x in range(0, 20)] +pack = [] child = pyglet.sprite.Sprite(pyglet.resource.image('child.png'), batch=batch) +score = 0 + +t = pyglet.text.Label("Score: %.1f" % score, color=(255,0,0,255), batch=batch, font_size=16) +t.x = 10 +t.y = window.height-40 + def update(dt): - global child + global child, score, t + + t.begin_update() + if type(score) in (int, float, long): + if len(pack)-2 < score: + pack.append(pyglet.sprite.Sprite(raptor_anim, batch=batch)) + reset_enemy(pack[-1]) + + score += dt + t.text = "Score: %.1f" % score + else: + t.text = score + t.end_update() + if keys[key.ESCAPE]: import sys @@ -76,9 +95,9 @@ def update(dt): if child.image is child_death: continue - child.image = child_death - + score = "You died! Score: %.1f" % score + child.image = child_death @window.event def on_draw(): @@ -87,13 +106,10 @@ def on_draw(): batch.draw() def reset_enemy(raptor): + raptor.scale = 0.5 raptor.x = window.width + randrange(0,window.width*2) raptor.y = window.height * random() -for raptor in pack: - raptor.scale = 0.5 - reset_enemy(raptor) - child.scale = 0.5 pyglet.clock.schedule(update) pyglet.app.run() |