Permalink
Browse files

Try to put things on the right place.

It impacted the gameplay.
  • Loading branch information...
flavioribeiro committed Aug 27, 2010
1 parent 7ad10d9 commit 2834a78e266fdffd17f0ee30ec65dc60ec7fa57d
Showing with 40 additions and 38 deletions.
  1. +12 −0 jailbreakerz/actions.py
  2. +24 −31 jailbreakerz/game.py
  3. +4 −7 jailbreakerz/jailbreakerz.py
View
@@ -1,6 +1,7 @@
from cocos.euclid import *
from cocos.actions import *
from cocos.director import director
+from pyglet.window import key
import math
class CustomJump(IntervalAction):
@@ -35,4 +36,15 @@ def step(self, dt):
def done(self):
return self._elapsed >= self.duration
+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
@@ -9,29 +9,43 @@
from cocos.text import *
from pyglet import font
+from pyglet.window import key
+
from actions import *
import score
import pyglet
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, 10)
+
+ 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,7 +54,6 @@ def load_sprites(self):
self.kombi.position = 790,90
self.add(self.kombi)
-
class FallingThief(Layer):
def __init__(self, *args, **kwargs):
@@ -57,26 +70,6 @@ def fall(self):
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())
@@ -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())

0 comments on commit 2834a78

Please sign in to comment.