Permalink
Browse files

Merge branch 'master' of github.com:andrewsmedina/pyweek2010

Conflicts:
	jailbreakerz/jailbreakerz.py
  • Loading branch information...
2 parents 7baa7f9 + 77e1302 commit 89b238fa51eaeb6bd0cc0eed9eac7b98c072c395 Osvaldo Santana committed Aug 27, 2010
View
@@ -1,27 +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)
- print 'updating..'
+
+ 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)
@@ -36,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
@@ -1,5 +1,3 @@
-import random
-import cocos
from cocos.sprite import *
from cocos.director import director
from cocos.layer import Layer
@@ -10,59 +8,73 @@
from cocos.menu import *
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()
- def load_sprites(self):
+ score.score_points = 100
+
+ 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_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)
self.kombi = Sprite('media/imgs/kombi.png')
- self.kombi.position = 750,120
+ 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)
-
-class Catcher(Layer):
-
- is_event_handler = True
-
- MOVEMENT_RATE = 50 # 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:
- self.catcher.position = self.catcher.position[0] - self.MOVEMENT_RATE, self.catcher.position[1]
- elif key == pyglet.window.key.RIGHT:
- self.catcher.position = self.catcher.position[0] + self.MOVEMENT_RATE, self.catcher.position[1]
+ pyglet.resource.media('media/sounds/yupi.mp3').play()
if __name__ == '__main__':
director.init(resizable=False, width=800, height=600)
- scene = Scene(Game(), Catcher(), FallingThief() )
- director.run(scene)
+ director.run(Game())
@@ -10,8 +10,11 @@
from cocos.text import *
from pyglet import font
+from score import ScoreLayer
+
import pyglet
+import sound
import credits
import game
@@ -93,10 +96,14 @@ def __init__(self):
self.create_menu(items)
+ sound.player.queue(pyglet.resource.media('media/sounds/fundogame.mp3'))
+ sound.player.eos_action = 'loop'
+ sound.player.play()
+
def on_start(self):
- game_scene = Scene(game.Game(), game.Catcher(), \
- game.FallingThief())
- director.push( FlipAngular3DTransition(game_scene, 1.5) )
+ game_scene = game.Game()
+ game_scene.add(ScoreLayer(), z=2)
+ director.push( game_scene )
def on_credits(self):
scene = Scene(Background())
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,24 @@
+from cocos.layer import *
+from cocos.text import *
+from cocos.actions import *
+
+import pyglet
+from pyglet.gl import *
+
+score_points = 0
+
+class ScoreLayer(Layer):
+ def __init__(self):
+ super(ScoreLayer, self).__init__()
+
+ self.score = Label('score:',
+ font_size=12,
+ color=(255,255,255,255))
+
+ self.position = (700, 580)
+ self.score.position = (0,0)
+ self.add(self.score)
+
+ def draw(self):
+ super(ScoreLayer, self).draw()
+ self.score.element.text = 'Score: %d' % score_points
View
@@ -0,0 +1,3 @@
+import pyglet
+
+player = pyglet.media.Player()

0 comments on commit 89b238f

Please sign in to comment.