Class: Sprite_Battler

Inherits:
Sprite_Base show all
Defined in:
Sprite_Battler.rb

Overview

** Sprite_Battler


This sprite is used to display battlers. It observes an instance of the

Game_Battler class and automatically changes sprite states.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Sprite_Base

#animation?, #animation_process_timing, #animation_set_sprites, #dispose_animation, #end_animation, #load_animation_bitmap, #make_animation_sprites, #set_animation_origin, #set_animation_rate, #start_animation, #update_animation

Constructor Details

- (Sprite_Battler) initialize(viewport, battler = nil)


  • Object Initialization




16
17
18
19
20
21
22
# File 'Sprite_Battler.rb', line 16

def initialize(viewport, battler = nil)
  super(viewport)
  @battler = battler
  @battler_visible = false
  @effect_type = nil
  @effect_duration = 0
end

Instance Attribute Details

- (Object) battler


  • Public Instance Variables




12
13
14
# File 'Sprite_Battler.rb', line 12

def battler
  @battler
end

Instance Method Details

- (Object) dispose


  • Free




26
27
28
29
# File 'Sprite_Battler.rb', line 26

def dispose
  bitmap.dispose if bitmap
  super
end

- (Boolean) effect?


  • Determine if Effect Is Executing


Returns:

  • (Boolean)


152
153
154
# File 'Sprite_Battler.rb', line 152

def effect?
  @effect_type != nil
end

- (Object) init_visibility


  • Initialize Visibility




63
64
65
66
# File 'Sprite_Battler.rb', line 63

def init_visibility
  @battler_visible = @battler.alive?
  self.opacity = 0 unless @battler_visible
end

- (Object) revert_to_normal


  • Revert to Normal Settings




131
132
133
134
135
136
137
# File 'Sprite_Battler.rb', line 131

def revert_to_normal
  self.blend_type = 0
  self.color.set(0, 0, 0, 0)
  self.opacity = 255
  self.ox = bitmap.width / 2 if bitmap
  self.src_rect.y = 0
end

- (Object) setup_new_animation


  • Set New Animation




141
142
143
144
145
146
147
148
# File 'Sprite_Battler.rb', line 141

def setup_new_animation
  if @battler.animation_id > 0
    animation = $data_animations[@battler.animation_id]
    mirror = @battler.animation_mirror
    start_animation(animation, mirror)
    @battler.animation_id = 0
  end
end

- (Object) setup_new_effect


  • Set New Effect




87
88
89
90
91
92
93
94
95
96
97
# File 'Sprite_Battler.rb', line 87

def setup_new_effect
  if !@battler_visible && @battler.alive?
    start_effect(:appear)
  elsif @battler_visible && @battler.hidden?
    start_effect(:disappear)
  end
  if @battler_visible && @battler.sprite_effect_type
    start_effect(@battler.sprite_effect_type)
    @battler.sprite_effect_type = nil
  end
end

- (Object) start_effect(effect_type)


  • Start Effect




101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'Sprite_Battler.rb', line 101

def start_effect(effect_type)
  @effect_type = effect_type
  case @effect_type
  when :appear
    @effect_duration = 16
    @battler_visible = true
  when :disappear
    @effect_duration = 32
    @battler_visible = false
  when :whiten
    @effect_duration = 16
    @battler_visible = true
  when :blink
    @effect_duration = 20
    @battler_visible = true
  when :collapse
    @effect_duration = 48
    @battler_visible = false
  when :boss_collapse
    @effect_duration = bitmap.height
    @battler_visible = false
  when :instant_collapse
    @effect_duration = 16
    @battler_visible = false
  end
  revert_to_normal
end

- (Object) update


  • Frame Update




33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'Sprite_Battler.rb', line 33

def update
  super
  if @battler
    @use_sprite = @battler.use_sprite?
    if @use_sprite
      update_bitmap
      update_origin
      update_position
    end
    setup_new_effect
    setup_new_animation
    update_effect
  else
    self.bitmap = nil
    @effect_type = nil
  end
end

- (Object) update_appear


  • Update Appearance Effect




196
197
198
# File 'Sprite_Battler.rb', line 196

def update_appear
  self.opacity = (16 - @effect_duration) * 16
end

- (Object) update_bitmap


  • Update Transfer Origin Bitmap




53
54
55
56
57
58
59
# File 'Sprite_Battler.rb', line 53

def update_bitmap
  new_bitmap = Cache.battler(@battler.battler_name, @battler.battler_hue)
  if bitmap != new_bitmap
    self.bitmap = new_bitmap
    init_visibility
  end
end

  • Update Blink Effect




190
191
192
# File 'Sprite_Battler.rb', line 190

def update_blink
  self.opacity = (@effect_duration % 10 < 5) ? 255 : 0
end

- (Object) update_boss_collapse


  • Update Boss Collapse Effect




216
217
218
219
220
221
222
223
224
# File 'Sprite_Battler.rb', line 216

def update_boss_collapse
  alpha = @effect_duration * 120 / bitmap.height
  self.ox = bitmap.width / 2 + @effect_duration % 2 * 4 - 2
  self.blend_type = 1
  self.color.set(255, 255, 255, 255 - alpha)
  self.opacity = alpha
  self.src_rect.y -= 1
  Sound.play_boss_collapse2 if @effect_duration % 20 == 19
end

- (Object) update_collapse


  • Update Collapse Effect




208
209
210
211
212
# File 'Sprite_Battler.rb', line 208

def update_collapse
  self.blend_type = 1
  self.color.set(255, 128, 128, 128)
  self.opacity = 256 - (48 - @effect_duration) * 6
end

- (Object) update_disappear


  • Updated Disappear Effect




202
203
204
# File 'Sprite_Battler.rb', line 202

def update_disappear
  self.opacity = 256 - (32 - @effect_duration) * 10
end

- (Object) update_effect


  • Update Effect




158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'Sprite_Battler.rb', line 158

def update_effect
  if @effect_duration > 0
    @effect_duration -= 1
    case @effect_type
    when :whiten
      update_whiten
    when :blink
      update_blink
    when :appear
      update_appear
    when :disappear
      update_disappear
    when :collapse
      update_collapse
    when :boss_collapse
      update_boss_collapse
    when :instant_collapse
      update_instant_collapse
    end
    @effect_type = nil if @effect_duration == 0
  end
end

- (Object) update_instant_collapse


  • Update Instant Collapse Effect




228
229
230
# File 'Sprite_Battler.rb', line 228

def update_instant_collapse
  self.opacity = 0
end

- (Object) update_origin


  • Update Origin




70
71
72
73
74
75
# File 'Sprite_Battler.rb', line 70

def update_origin
  if bitmap
    self.ox = bitmap.width / 2
    self.oy = bitmap.height
  end
end

- (Object) update_position


  • Update Position




79
80
81
82
83
# File 'Sprite_Battler.rb', line 79

def update_position
  self.x = @battler.screen_x
  self.y = @battler.screen_y
  self.z = @battler.screen_z
end

- (Object) update_whiten


  • Update White Flash Effect




183
184
185
186
# File 'Sprite_Battler.rb', line 183

def update_whiten
  self.color.set(255, 255, 255, 0)
  self.color.alpha = 128 - (16 - @effect_duration) * 10
end