def dice_equal(player, _enemy): if player.cri_dice == 2: show_message(const.BATTLE_MESSAGE['DiceDueceThirdTime']) player.cri_dice = 0 player.hp = player.hp / 2 _enemy.hp = _enemy.hp / 2 if player.hp < 1: player.hp = 1 if _enemy.hp < 1: _enemy.hp = 1 materials.sprites['strike'].visible = True materials.sprites['strike'].position = 400, 234 materials.sprites['strike'].image = (const.image_from_file( const.EXPLODE_IMG_FILE, const.GUI_ZIP_FILE)) materials.sprites['strike'].do( actions.MoveBy((0, 100), 1.3) + actions.MoveBy((0, -100), 1.3) + actions.FadeOut(0.5)) battle.show_hp_change(player, _enemy, 2, 0 - int(player.hp / 2), 0 - int(_enemy.hp / 2)) enemy.show_enemy(_enemy) elif player.cri_dice == 1: show_message(const.BATTLE_MESSAGE['DiceDueceTwice']) elif player.cri_dice == 0: show_message(const.BATTLE_MESSAGE['DiceDuece']) player.cri_dice += 1
def win(self): self.winSprite = cocos.sprite.Sprite('assets/winscreen.PNG', position=(g.screenWidth / 2, g.screenHeight / 2)) self.add(self.winSprite) action = ac.Delay(4) + ac.FadeOut(3) self.winSprite.do(action)
def __init__(self, *args, **kwargs): time = kwargs.pop('time', 1.5) action_container = kwargs.pop('action_container', self) super().__init__(*args, **kwargs) action_container.do(actions.FadeOut(time) + actions.CallFunc(self.remove_self), target=self)
def show_hp_increase(_player, _regen=0, _absorb=0): # the hp regen/absorb visual effect if _regen: _label = materials.front_layer.labels['player_hp_regen_label'] _label.element.color = const.GREEN_COLOR _label.element.text = '+ ' + str(_regen) _label.visible = True _label.do(actions.MoveBy((0, 60), 0.5) + actions.FadeOut(0.3) + actions.MoveBy((0, -60), 0.2)) return None if _absorb: _label = materials.front_layer.labels['player_hp_absorb_label'] _label.element.color = const.GREEN_COLOR _label.element.text = '+ ' + str(int(_absorb)) _label.visible = True _label.do(actions.JumpBy((50,30),35,1,0.7) + actions.FadeOut(0.3) + actions.MoveBy((-50,-30),0.3)) return None
def show_under_attack(self, cri_dice): '''show the action and the sprites when the player is attacked ''' _action = actions.RotateBy(15, 0.1) + actions.RotateBy(-15, 0.1) self.sprite.do(_action) _sprite = materials.sprites['strike'] _sprite.visible = True _sprite.position = 200, 340 if cri_dice == 1: _sprite.image = const.image_from_file( const.CRITICAL_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1.5)) elif cri_dice == 0: _sprite.image = const.image_from_file(const.STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1)) elif cri_dice == 2: _sprite.image = const.image_from_file(const.SUPER_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(2.5))
def on_key_press(self, k, modifiers): if (k in g.keyBindings): hitbox = self.hitBoxes[g.keyBindings.index(k)] hitbox.do( ac.ScaleTo(spriteScale * 1.2, 0.05) + ac.ScaleTo(spriteScale, 0.1)) keySprite = self.keyIndicators[g.keyBindings.index(k)] if (keySprite): self.keyIndicators[g.keyBindings.index(k)] = {} action = (ac.FadeOut(2.25)) + ac.CallFuncS(self.remove_child) keySprite.do(action)
def show_under_attack(self, cri_dice=False): '''Show the action of enemy when attacked (shake) and the corresponding strike-sprite ''' _action = actions.RotateBy(-15, 0.1) + actions.RotateBy(15, 0.1) self.sprite.do(_action) _sprite = materials.sprites['strike'] _sprite.visible = True _sprite.position = 650,340 if cri_dice==1: _sprite.image = const.image_from_file( const.CRITICAL_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1.5)) elif cri_dice==0: _sprite.image = const.image_from_file( const.STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(1)) elif cri_dice==2: _sprite.image = const.image_from_file( const.SUPER_STRIKE_IMG_FILE, const.GUI_ZIP_FILE) _sprite.do(actions.FadeOut(2.5))
def on_key_press (self, k, modifiers): if (k in g.keyBindings): self.s.timeLastKeyPress = time.time() children = self.boxes[g.keyBindings.index(k)] if(children): bestOne = min([abs(child.y - g.hitBoxHeight) for child in children]) bestChild = [child for child in children if abs(child.y - g.hitBoxHeight) == bestOne][0] #yuck if(bestChild): if(bestOne < 8.5): children.remove(bestChild) action = (ac.MoveTo((bestChild.x, g.hitBoxHeight)) | ac.FadeOut(0.25) | ac.ScaleBy(1.75, 0.25) ) + ac.CallFuncS(self.remove_child) bestChild.do(action) self.s.currentSpeed += 2.5 self.sounds[g.keyBindings.index(k)].play() # Play right now elif (bestOne < 20): children.remove(bestChild) action = (ac.FadeOut(0.25)) + ac.CallFuncS(self.remove_child) bestChild.do(action) self.s.currentSpeed += 1 self.missSounds[g.keyBindings.index(k)].play() # Play right now else: #apply penalty! (to stop spamming) self.s.currentSpeed -= 5
def __onTie(self): u""" Execução dos efeitos quando houver empate """ # Para o jogo para execução dos efeitos self.ableToPlay = False # Definição dos efeitos fade = actions.FadeOut(1) for i in xrange(9): # Faz todos sprites desaparecerem self.sprites[i].do(fade) # Define um atraso de 1 segundo pro jogo reiniciar self.do(actions.Delay(1) + actions.CallFunc(self.newGame))
def __onWin(self): u""" Execução dos efeitos quando alguém ganhar """ # Para o jogo para execução dos efeitos self.ableToPlay = False # Definição dos efeitos blink = actions.Blink(10, 1.5) fade = actions.FadeOut(1) for i in xrange(9): if self.game.values[i] == self.game.lastTurn: # Se o sprite é do jogador vencedor então fazer ele piscar self.sprites[i].do(blink) else: # Se o sprite é do jogador perdedor então fazer ele desaparecer self.sprites[i].do(fade) # Define um atraso de 2 segundos pro jogo reiniciar self.do(actions.Delay(1.5) + actions.CallFunc(self.newGame))
def show_hp_change(_player=None, _enemy=None, cri_dice=0, _player_dmg=0, _enemy_dmg=0): if _player: _label = materials.front_layer.labels['player_hp_change_label'] if cri_dice==1: _label.element.font_size = 30 _label.element.color = const.ORANGE_COLOR _label.element.text = str(_player_dmg) _label.element.x = 150 _label.element.y = 320 _label.visible = True _label.do(actions.MoveBy((-100,0),0.3) + actions.FadeOut(0.3) + actions.MoveBy((100,0),0.3)) elif cri_dice==0: _label.element.font_size = 26 _label.element.color = const.DEFAULT_COLOR _label.element.text = str(_player_dmg) _label.element.x = 150 _label.element.y = 320 _label.visible = True _label.do(actions.JumpBy((-80,10),35,1,0.7) + actions.FadeOut(0.3) + actions.MoveBy((80,-10),0.3)) elif cri_dice==2: _label.element.font_size = 36 _label.element.color = const.HIGHLIGHT_COLOR _label.element.text = str(_player_dmg) _label.element.x = 150 _label.element.y = 320 _label.visible = True _label.do(actions.MoveBy((-100,0),0.3) + actions.FadeOut(0.3) + actions.MoveBy((100,0),0.3)) if _enemy: _label = materials.front_layer.labels['enemy_hp_change_label'] if cri_dice==1: _label.element.font_size = 30 _label.element.color = const.ORANGE_COLOR _label.element.text = str(_enemy_dmg) _label.element.x = 600 _label.element.y = 320 _label.visible = True _label.do(actions.MoveBy((100,0),0.3) + actions.FadeOut(0.3) + actions.MoveBy((-100,0),0.3)) elif cri_dice==0: _label.element.font_size = 26 _label.element.color = const.DEFAULT_COLOR _label.element.text = str(_enemy_dmg) _label.element.x = 600 _label.element.y = 320 _label.visible = True _label.do(actions.JumpBy((80,10),35,1,0.7) + actions.FadeOut(0.3) + actions.MoveBy((-80,-10),0.3)) elif cri_dice==2: _label.element.font_size = 36 _label.element.color = const.HIGHLIGHT_COLOR _label.element.text = str(_enemy_dmg) _label.element.x = 600 _label.element.y = 320 _label.visible = True _label.do(actions.MoveBy((100,0),0.3) + actions.FadeOut(0.3) + actions.MoveBy((-100,0),0.3)) return None
def __init__(self, pos): super().__init__('explode.png', pos) self.do(cac.ScaleBy(1.3, 0.1) + cac.Delay(0.05) + cac.FadeOut(0.05) + cac.CallFuncS(lambda e: e.kill()))