Permalink
Browse files

collision, score points, game over and message scene

  • Loading branch information...
1 parent 89b238f commit 4ab588c4c20c377fab99e53b3d4e253e743879ff @andrewsmedina committed Aug 28, 2010
Showing with 81 additions and 3 deletions.
  1. +38 −0 jailbreakerz/actions.py
  2. +5 −3 jailbreakerz/game.py
  3. +38 −0 jailbreakerz/message.py
View
@@ -1,9 +1,47 @@
from cocos.euclid import *
from cocos.actions import *
from cocos.director import director
+
from pyglet.window import key
+
+from message import MessageScene
+
+import score
import math
+def collide(a, b):
+ distance = math.sqrt((a.x-b.x)**2 + (a.y-b.y)**2)
+ return distance < (a.width/2 + b.width/2)
+
+class ThiefJump(JumpBy):
+
+ def __init__(self, *args, **kwargs):
+ super(ThiefJump, self).__init__(*args, **kwargs)
+ self.freedom = False
+ self.is_dead = False
+
+ def freedom_checking(self):
+ if not self.freedom and collide(self.target, director.scene.kombi):
+ score.score_points += 10
+ self.freedom = True
+
+ def dead_checking(self):
+ if not self.freedom and not self.is_dead and self.target.y < -30:
+ director.replace(MessageScene('GAME OVER'))
+ self.is_dead = True
+
+ def saved(self):
+ if not self.freedom and collide(self.target, director.scene.catcher):
+ pass
+ #self.stop()
+
+ def step(self, dt):
+ super(ThiefJump, self).step(dt)
+ self.saved()
+ self.dead_checking()
+ self.freedom_checking()
+
+
class CustomJump(IntervalAction):
def init(self, thief_type=None):
View
@@ -33,7 +33,8 @@ def __init__(self):
self.keys = key.KeyStateHandler()
director.window.push_handlers(self.keys)
- self.schedule_interval(self.thiefs_builder, 1)
+ #self.schedule_interval(self.thiefs_builder, 1)
+ self.thiefs_builder(1)
def thiefs_builder(self, dt):
self.add(FallingThief())
@@ -71,8 +72,9 @@ def __init__(self, *args, **kwargs):
self.fall()
def fall(self):
- action = CustomJump( self.thief_type[0] )
- self.thief.do(action)
+ #action = CustomJump( self.thief_type[0] )
+ #self.thief.do(action)
+ self.thief.do(ThiefJump((200,-250), 200, 1, 3))
pyglet.resource.media('media/sounds/yupi.mp3').play()
if __name__ == '__main__':
View
@@ -0,0 +1,38 @@
+from jailbreakerz import Background
+from cocos.director import director
+
+import cocos
+
+class MessageScene(cocos.scene.Scene):
+
+ def __init__(self, text):
+ super(MessageScene, self).__init__()
+
+ self.add(Background())
+
+ class UserActivity(cocos.layer.Layer):
+ is_event_handler = True
+
+ def on_mouse_press(*args):
+ director.pop()
+
+ def on_text(*args):
+ director.pop()
+
+ layer = UserActivity()
+ self.add(layer)
+
+ opts = {
+ 'font_name': 'against myself',
+ 'font_size': 70,
+ 'anchor_x': 'center',
+ 'anchor_y': 'center',
+ }
+
+ label = cocos.text.Label(text, color=(0x00, 0x00, 0x00, 0xff), **opts)
+ label.position = 400, 500
+ layer.add(label, z=1)
+
+ label = cocos.text.Label(text, color=(0xff, 0xff, 0xff, 0xff), **opts)
+ label.position = 400, 503
+ layer.add(label, z=2)

0 comments on commit 4ab588c

Please sign in to comment.