Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge

  • Loading branch information...
commit 77e130285ff760559247d83e96a989febf6c83c2 2 parents afd05f1 + 595c6de
@andrewsmedina authored
View
56 jailbreakerz/actions.py
@@ -1,26 +1,48 @@
from cocos.euclid import *
from cocos.actions import *
from cocos.director import director
+from pyglet.window import key
import math
class CustomJump(IntervalAction):
- def init(self, position, height, jumps, duration):
+ def init(self, thief_type=None):
- self.position = position
- self.height = height
- self.duration = duration
- self.jumps = jumps
+ if thief_type == 'fat':
+ self.position = (500, 0)
+ self.height = 50
+ self.duration = 10
+ self.jumps = 4
+
+ elif thief_type == 'small':
+ self.position = (500, 0)
+ self.height = 200
+ self.duration = 5
+ self.jumps = 2
+
+ elif thief_type == 'tall':
+ self.position = (500, 0)
+ self.height = 100
+ self.duration = 15
+ self.jumps = 3
def start( self ):
self.start_position = self.target.position
self.delta = Vector2(*self.position)
def update(self, t):
- y = self.height * abs( math.sin( t * math.pi * self.jumps ) )
- y = int(y+self.delta[1] * t)
- x = self.delta[0] * t
- self.target.position = self.start_position + Point2(x,y)
+
+ self.target.alive = self.collide( self.target.position, \
+ director.scene.catcher.position )
+
+ if self.target.alive:
+ y = self.height * abs( math.sin( t * math.pi * self.jumps ) )
+ y = int(y+self.delta[1] * t)
+ x = self.delta[0] * t
+ self.target.position = self.start_position + Point2(x,y)
+
+ else:
+ self.target_position = self.target_position[0], self.target_position[1]-10
def __reversed__(self):
return CustomJump( (-self.position[0],-self.position[1]), self.height, self.jumps, self.duration)
@@ -35,4 +57,20 @@ def step(self, dt):
def done(self):
return self._elapsed >= self.duration
+ def collide(self, thief_pos, catcher_pos):
+ print 'Thief pos: ', thief_pos
+ print 'Catcherpos: ', catcher_pos
+ return True
+
+class CustomMove(Move):
+
+ def step(self, dt):
+ keys = director.scene.keys
+ catcher = director.scene.catcher
+ if keys[key.LEFT] and catcher.position[0] > 300:
+ catcher.position = (catcher.position[0] - catcher.mov_rate, \
+ catcher.position[1])
+ elif keys[key.RIGHT] and catcher.position[0] < 500:
+ catcher.position = (catcher.position[0] + catcher.mov_rate, \
+ catcher.position[1])
View
66 jailbreakerz/game.py
@@ -9,6 +9,8 @@
from cocos.text import *
from pyglet import font
+from pyglet.window import key
+
from actions import *
import score
@@ -16,22 +18,34 @@
import random
import cocos
-class Game(Layer):
+class Game(Scene):
+
+ is_event_handler = True
def __init__(self):
super(Game, self).__init__()
- self.load_sprites()
-
+
score.score_points = 100
-
- # THIEF BUILDER
- # TODO : And how we gonna do in hard levels?
- self.schedule_interval(self.thief_builder, 2)
- def thief_builder(self, dt):
+ self.load_scenario()
+ self.load_catcher()
+
+ self.keys = key.KeyStateHandler()
+ director.window.push_handlers(self.keys)
+
+ self.schedule_interval(self.thiefs_builder, 1)
+
+ def thiefs_builder(self, dt):
self.add(FallingThief())
- def load_sprites(self):
+ def load_catcher(self):
+ self.catcher = Sprite('media/imgs/catcher.png')
+ self.catcher.position = 300,100
+ self.catcher.mov_rate = 20
+ self.catcher.do( CustomMove(300, 500) )
+ self.add(self.catcher)
+
+ def load_scenario(self):
self.prison = Sprite('media/imgs/prison.png')
self.prison.position = 100,170
self.add(self.prison)
@@ -40,43 +54,27 @@ def load_sprites(self):
self.kombi.position = 790,90
self.add(self.kombi)
-
class FallingThief(Layer):
def __init__(self, *args, **kwargs):
super(FallingThief, self).__init__()
- thief_sprites = ['media/imgs/tall_thief.png', 'media/imgs/small_thief.png', 'media/imgs/fat_thief.png']
- self.thief = Sprite(random.sample(thief_sprites, 1)[0])
+ thiefs = {'tall': 'media/imgs/tall_thief.png', \
+ 'small' : 'media/imgs/small_thief.png', \
+ 'fat' : 'media/imgs/fat_thief.png'}
+
+ self.thief_type = random.choice(thiefs.items())
+ self.thief = Sprite(self.thief_type[1])
+ self.thief.alive = True
self.thief.position = 100, 190
self.add(self.thief)
self.fall()
def fall(self):
- action = CustomJump((500,0), 100, 10, 7)
+ action = CustomJump( self.thief_type[0] )
self.thief.do(action)
pyglet.resource.media('media/sounds/yupi.mp3').play()
-
-class Catcher(Layer):
-
- is_event_handler = True
-
- MOVEMENT_RATE = 100 # Constant used to move sprite
-
- def __init__(self, *args, **kwargs):
- super(Catcher, self).__init__()
- self.catcher = Sprite('media/imgs/catcher.png')
- self.catcher.position = 300,100
- self.add(self.catcher)
-
- def on_key_press(self, key, modifiers):
- if key == pyglet.window.key.LEFT and self.catcher.position[0] > 300:
- self.catcher.position = self.catcher.position[0] - self.MOVEMENT_RATE, self.catcher.position[1]
- elif key == pyglet.window.key.RIGHT and self.catcher.position[0] < 500:
- self.catcher.position = self.catcher.position[0] + self.MOVEMENT_RATE, self.catcher.position[1]
-
if __name__ == '__main__':
director.init(resizable=False, width=800, height=600)
- scene = Scene(Game(), Catcher(), FallingThief() )
- director.run(scene)
+ director.run(Game())
View
11 jailbreakerz/jailbreakerz.py
@@ -29,7 +29,6 @@ def draw(self):
self.img.blit(0,0)
glPopMatrix()
-
class MainMenu(Menu):
def __init__(self):
@@ -57,17 +56,15 @@ def __init__(self):
items.append(MenuItem('QUIT', self.on_quit))
self.create_menu(items)
-
+
sound.player.queue(pyglet.resource.media('media/sounds/fundogame.mp3'))
sound.player.eos_action = 'loop'
- sound.player.play()
+ sound.player.play()
def on_start(self):
- game_scene = Scene(game.Game(), game.Catcher())
-
+ game_scene = game.Game()
game_scene.add(ScoreLayer(), z=2)
-
- director.push( FlipAngular3DTransition(game_scene, 1.5) )
+ director.push( game_scene )
def on_credits(self):
scene = Scene(Background())
Please sign in to comment.
Something went wrong with that request. Please try again.