Class: Battle::Visual::HPAnimation

Inherits:
Yuki::Animation::DiscreetAnimation
  • Object
show all
Defined in:
scripts/01600 Alpha 25 Battle Engine/00002 Battle_Visual/00001 Animations/01001 HPAnimation.rb

Overview

Animation of HP getting down/up

Instance Method Summary collapse

Constructor Details

#initialize(scene, target, quantity, effectiveness = nil) ⇒ HPAnimation

Create the HP Animation

Parameters:

  • scene (Battle::Scene)

    scene responsive of holding all the battle information

  • target (PFM::PokemonBattler)

    Pokemon getting its HP down/up

  • quantity (Integer)

    quantity of HP the Pokemon is getting

  • effectiveness (Integer, nil) (defaults to: nil)

    optional param to play the effectiveness sound if that comes from using a move



10
11
12
13
14
15
16
17
18
19
# File 'scripts/01600 Alpha 25 Battle Engine/00002 Battle_Visual/00001 Animations/01001 HPAnimation.rb', line 10

def initialize(scene, target, quantity, effectiveness = nil)
  @scene = scene
  @target = target
  @target_hp = (target.hp + (quantity == 0 ? -1 : quantity)).clamp(0, target.max_hp)
  time = (quantity.clamp(-target.hp, target.max_hp).abs.to_f / 60).clamp(0.2, 1) # TODO: Add config & option for all those values
  super(time, target, :hp=, target.hp, @target_hp)
  create_sub_animation
  start
  effectiveness_sound(effectiveness) if quantity != 0 && effectiveness
end

Instance Method Details

#done?Boolean

Detect if the animation if done

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'scripts/01600 Alpha 25 Battle Engine/00002 Battle_Visual/00001 Animations/01001 HPAnimation.rb', line 29

def done?
  return false unless super

  final_hp_refresh
  return true
end

#effectiveness_sound(effectiveness)

Play the effectiveness sound



37
38
39
40
41
42
43
44
45
# File 'scripts/01600 Alpha 25 Battle Engine/00002 Battle_Visual/00001 Animations/01001 HPAnimation.rb', line 37

def effectiveness_sound(effectiveness)
  if effectiveness == 1
    Audio.se_play('Audio/SE/hit')
  elsif effectiveness > 1
    Audio.se_play('Audio/SE/hitplus')
  else
    Audio.se_play('Audio/SE/hitlow')
  end
end

#update

Update the animation



22
23
24
25
# File 'scripts/01600 Alpha 25 Battle Engine/00002 Battle_Visual/00001 Animations/01001 HPAnimation.rb', line 22

def update
  super
  @scene.visual.refresh_info_bar(@target)
end