-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e666d83
commit 6c0531a
Showing
1 changed file
with
38 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,69 @@ | ||
import cocos | ||
from cocos.sprite import * | ||
from cocos.director import director | ||
from cocos.layer import Layer | ||
from cocos.scene import Scene | ||
from cocos.scenes.transitions import * | ||
from cocos.actions import * | ||
from cocos.sprite import * | ||
from cocos.menu import * | ||
from cocos.text import * | ||
from pyglet import font | ||
|
||
import pyglet | ||
|
||
class Game(cocos.layer.Layer): | ||
class Game(Layer): | ||
|
||
def __init__(self): | ||
super(Game, self).__init__() | ||
self.load_sprites() | ||
|
||
def load_sprites(self): | ||
self.prison = cocos.sprite.Sprite('media/imgs/prison.png') | ||
self.prison = Sprite('media/imgs/prison.png') | ||
self.prison.position = 100,170 | ||
self.add(self.prison) | ||
|
||
self.thief = cocos.sprite.Sprite('media/imgs/tall_thief.png') | ||
self.thief.position = 250,440 | ||
self.kombi = Sprite('media/imgs/kombi.png') | ||
self.kombi.position = 750,120 | ||
self.add(self.kombi) | ||
|
||
class FallingThief(Layer): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(FallingThief, self).__init__() | ||
self.thief = Sprite('media/imgs/tall_thief.png') | ||
self.thief.position = 100, 190 | ||
self.add(self.thief) | ||
self.fall() | ||
|
||
self.kombi = cocos.sprite.Sprite('media/imgs/kombi.png') | ||
self.kombi.position = 750, 120 | ||
self.add(self.kombi) | ||
def fall(self): | ||
action = JumpBy((500,0), height=100, jumps=10, duration=7) | ||
self.thief.do(action) | ||
|
||
class Catcher(Layer): | ||
|
||
class Catcher(cocos.layer.Layer): | ||
|
||
is_event_handler = True | ||
MOVEMENT_RATE = 100 # Constant used to move sprite | ||
|
||
MOVEMENT_RATE = 50 # Constant used to move sprite | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(Catcher, self).__init__() | ||
self.catcher = cocos.sprite.Sprite('media/imgs/catcher.png') | ||
self.catcher = Sprite('media/imgs/catcher.png') | ||
self.catcher.position = 300,100 | ||
self.add(self.catcher) | ||
|
||
def on_key_press(self, key, modifiers): | ||
""" | ||
Catcher movement | ||
@param key: int | ||
""" | ||
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] | ||
self.catcher.position = self.catcher.position[0] + self.MOVEMENT_RATE, self.catcher.position[1] | ||
|
||
|
||
if __name__ == '__main__': | ||
cocos.director.director.init(resizable=False, width=800, height=600) | ||
director.init(resizable=False, width=800, height=600) | ||
|
||
scene = cocos.scene.Scene(Game(), Catcher()) | ||
cocos.director.director.run(scene) | ||
scene = Scene(Game(), Catcher(), FallingThief()) | ||
director.run(scene) |