def __init__(self): super(BackgroundLayer, self).__init__() self.image = cocos.sprite.Sprite(resources.background) self.image.position = 400, 325 self.add(self.image, z=0) self.player = cocos.sprite.Sprite(resources.player) self.player.position = 200, 75 self.add(self.player, z=1) self.enemy = cocos.sprite.Sprite(resources.enemy) self.enemy.position = 400, 75 self.add(self.enemy, z=1) self.boss = cocos.sprite.Sprite(resources.boss) self.boss.scale = 0.4 rect = self.boss.get_rect() rect.midbottom = 600, 50 self.boss.position = rect.center self.add(self.boss, z=1) self.player.do(Repeat(JumpBy((0, 0), 100, 1, 1))) self.enemy.do( Repeat( MoveBy((-25, 0), 0.25) + MoveBy((50, 0), 0.5) + MoveBy((-25, 0), 0.25))) self.boss.do(Repeat(FadeTo(155, 0.5) + FadeTo(255, 0.5)))
def __init__(self): super(Game, self).__init__(102, 102, 225, 255) self.collision_manager = cm.CollisionManagerBruteForce() self.player = cocos.sprite.Sprite('eleph2.png') self.player.position = 400, 25 self.player.velocity = 0, 0 self.player.speed = 150 self.player.scale = .5 self.add(self.player, z=2) self.player.cshape = cm.AARectShape(self.player.position, self.player.width // 2, self.player.height // 2) self.collision_manager.add(self.player) self.boss = cocos.sprite.Sprite('flaregun.png') self.boss.position = 400, 600 self.boss.scale = 0.4 self.add(self.boss, z=1) self.boss.cshape = cm.AARectShape(self.boss.position, self.boss.width // 2, self.boss.height // 2) self.collision_manager.add(self.boss) self.batch = cocos.batch.BatchNode() self.enemies = [cocos.sprite.Sprite('compass.png') for i in range(6)] positions = ((250, 125), (550, 125), (300, 325), (500, 325), (150, 475), (650, 475)) for num, enem in enumerate(self.enemies): enem.position = positions[num] enem.cshape = cm.AARectShape(enem.position, enem.width // 2, enem.height // 2) self.collision_manager.add(enem) self.batch.add(enem) self.add(self.batch, z=1) self.player.do(Move()) move_basic = MoveBy((120, 0), 1) self.enemies[0].do(Repeat(move_basic + Reverse(move_basic))) self.enemies[1].do(Repeat(Reverse(move_basic) + move_basic)) move_complex = (MoveBy((-75, 75), 1) + Delay(0.5) + MoveBy( (-75, -75), 1) + Delay(0.5) + MoveBy( (75, -75), 1) + Delay(0.5) + MoveBy((75, 75), 1) + Delay(0.5)) self.enemies[2].do(Repeat(move_complex)) self.enemies[3].do(Repeat(Reverse(move_complex))) move_jump = AccelDeccel(JumpBy((200, 0), 75, 3, 3)) move_jump_rot = AccelDeccel(RotateBy(360, 3)) self.enemies[4].do(Repeat(move_jump + Reverse(move_jump))) self.enemies[4].do(Repeat(move_jump_rot + Reverse(move_jump_rot))) self.enemies[5].do(Repeat(Reverse(move_jump) + move_jump)) self.enemies[5].do(Repeat(Reverse(move_jump_rot) + move_jump_rot)) self.schedule(self.update)
def __init__(self, name, pos): if name == "unknown": image = Image.unknown_brick else: image = Image.normal_brick super().__init__(image) self.position = pos self.do(JumpBy((0, 0), 8, 1, 0.2) + CallFunc(self.kill))
def __init__(self): super( TestLayer, self ).__init__() x,y = director.get_window_size() self.sprite = Sprite( 'grossini.png', (x/5, y/3*2) ) self.add( self.sprite ) self.sprite.do( JumpTo( (x/5*4, 100), 100, 10, 6 ) ) self.sprite2 = Sprite( 'grossini.png', (x/5, y/3) ) self.add( self.sprite2 ) self.sprite2.do( JumpBy( (x/5*4, 100), 100, 10, 6 ) )
def __init__(self): super(JumpByTest, self).__init__() sprite = cocos.sprite.Sprite('icon.jpg') sprite.position = 240, 320 sprite.scale = 0.5 self.add(sprite) jump = JumpBy((50, 100), duration=2) sprite.do(Repeat(Reverse(jump) + jump))
def collide_enemy(self, obj): if self.mario.collide_bottom_obj(obj): Sound.play("stomp") stats.score += 100 obj.die() self.mario.do(JumpBy((0, 0), 16, 1, 0.3)) else: if self.mario.state == Mario.SMALL: self.game_over("enemy") elif self.mario.state == Mario.BIG: self.mario.state = Mario.SMALL elif self.mario.state == Mario.FIRE: self.mario.state = Mario.BIG self.enemies.remove(obj)
def __init__(self): super(Game, self).__init__(102, 102, 225, 255) self.player = cocos.sprite.Sprite(resources.player) self.player.position = 400, 25 self.player.velocity = 0, 0 self.player.speed = 150 self.add(self.player, z=2) self.boss = cocos.sprite.Sprite(resources.boss) self.boss.position = 400, 600 self.boss.scale = 0.4 self.add(self.boss, z=1) self.batch = cocos.batch.BatchNode() self.enemies = [cocos.sprite.Sprite(resources.enemy) for i in range(6)] positions = ((250, 125), (550, 125), (300, 325), (500, 325), (150, 475), (650, 475)) for num, enem in enumerate(self.enemies): enem.position = positions[num] self.batch.add(enem) self.add(self.batch, z=1) self.player.do(Move()) move_basic = MoveBy((120, 0), 1) self.enemies[0].do(Repeat(move_basic + Reverse(move_basic))) self.enemies[1].do(Repeat(Reverse(move_basic) + move_basic)) move_complex = (MoveBy((-75, 75), 1) + Delay(0.5) + MoveBy( (-75, -75), 1) + Delay(0.5) + MoveBy( (75, -75), 1) + Delay(0.5) + MoveBy((75, 75), 1) + Delay(0.5)) self.enemies[2].do(Repeat(move_complex)) self.enemies[3].do(Repeat(Reverse(move_complex))) move_jump = AccelDeccel(JumpBy((200, 0), 75, 3, 3)) move_jump_rot = AccelDeccel(RotateBy(360, 3)) self.enemies[4].do(Repeat(move_jump + Reverse(move_jump))) self.enemies[4].do(Repeat(move_jump_rot + Reverse(move_jump_rot))) self.enemies[5].do(Repeat(Reverse(move_jump) + move_jump)) self.enemies[5].do(Repeat(Reverse(move_jump_rot) + move_jump_rot))
# lens_effect: 0.7, a strong "lens". 0 means no effect at all. 1 means very strong # center: center of the lens # grid=(20,16): create a grid of 20 tiles x 16 tiles. More tiles will # look better but the performance will decraese # duration=10: 10 seconds lens = Lens3D(radius=150, lens_effect=0.7, center=(150, 150), grid=(20, 16), duration=50) # create a Jump action # Jump to the right 360 pixels doing: # 3 jumps # of height 170 pixels # in 4 seconds jump = JumpBy((360, 0), 170, 3, 4) # do and get the cloned action of lens' action = scene.do(lens) # perform the Jump action using as target the lens effect. # the Jump action will modify the 'position' attribute, and # the lens action uses the 'position' attribute as the center of the lens # # The action Jump + Reverse(Jump) will be repeated 5 times scene.do((jump + Reverse(jump)) * 5, target=action) # Run! director.run(scene)
def die(self): self.image = Image.mario_die self.do(JumpBy((0, -100), 100, 1, 1))