mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-08 13:44:59 +00:00
Anim Editor: Added smart angle property to particles
This commit is contained in:
@@ -127,6 +127,17 @@ class AnimationPlayer
|
||||
particle_sprite.foe_invert_y = particle[:foe_invert_y]
|
||||
particle_sprite.foe_flip = particle[:foe_flip]
|
||||
end
|
||||
particle_sprite.base_angle = 0
|
||||
case particle[:angle_override]
|
||||
when :initial_angle_to_focus
|
||||
target_x = (focus_xy.length == 2) ? focus_xy[1][0] : focus_xy[0][0]
|
||||
target_x += offset_xy[0]
|
||||
target_y = (focus_xy.length == 2) ? focus_xy[1][1] : focus_xy[0][1]
|
||||
target_y += offset_xy[1]
|
||||
particle_sprite.base_angle = AnimationPlayer::Helper.initial_angle_between(particle, focus_xy, offset_xy)
|
||||
when :always_point_at_focus
|
||||
particle_sprite.angle_override = particle[:angle_override] if relative_to_index >= 0
|
||||
end
|
||||
# Find earliest command and add a "make visible" command then
|
||||
delay = AnimationPlayer::Helper.get_particle_delay(particle, instance)
|
||||
if sprite && !particle_sprite.battler_sprite?
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
class AnimationPlayer::ParticleSprite
|
||||
attr_accessor :sprite
|
||||
attr_accessor :focus_xy, :offset_xy, :focus_z
|
||||
attr_accessor :base_angle, :angle_override
|
||||
attr_accessor :foe_invert_x, :foe_invert_y, :foe_flip
|
||||
|
||||
FRAMES_PER_SECOND = 20.0
|
||||
@@ -109,16 +110,24 @@ class AnimationPlayer::ParticleSprite
|
||||
value *= -1 if @foe_invert_x
|
||||
AnimationPlayer::Helper.apply_xy_focus_to_sprite(@sprite, :x, value, @focus_xy)
|
||||
@sprite.x += @offset_xy[0]
|
||||
update_angle_pointing_at_focus
|
||||
when :y
|
||||
value = value.round
|
||||
value *= -1 if @foe_invert_y
|
||||
AnimationPlayer::Helper.apply_xy_focus_to_sprite(@sprite, :y, value, @focus_xy)
|
||||
@sprite.y += @offset_xy[1]
|
||||
update_angle_pointing_at_focus
|
||||
when :z
|
||||
AnimationPlayer::Helper.apply_z_focus_to_sprite(@sprite, value, @focus_z)
|
||||
when :zoom_x then @sprite.zoom_x = value / 100.0
|
||||
when :zoom_y then @sprite.zoom_y = value / 100.0
|
||||
when :angle then @sprite.angle = value
|
||||
when :angle
|
||||
if @angle_override == :always_point_at_focus
|
||||
update_angle_pointing_at_focus
|
||||
@sprite.angle += value
|
||||
else
|
||||
@sprite.angle = value + (@base_angle || 0)
|
||||
end
|
||||
when :visible then @sprite.visible = value
|
||||
when :opacity then @sprite.opacity = value
|
||||
when :color_red then @sprite.color.red = value
|
||||
@@ -132,6 +141,21 @@ class AnimationPlayer::ParticleSprite
|
||||
end
|
||||
end
|
||||
|
||||
# This assumes vertically up is an angle of 0, and the angle increases
|
||||
# anticlockwise.
|
||||
def update_angle_pointing_at_focus
|
||||
return if @angle_override != :always_point_at_focus
|
||||
# Get coordinates
|
||||
sprite_x = @sprite.x
|
||||
sprite_y = @sprite.y
|
||||
target_x = (@focus_xy.length == 2) ? @focus_xy[1][0] : @focus_xy[0][0]
|
||||
target_x += @offset_xy[0]
|
||||
target_y = (@focus_xy.length == 2) ? @focus_xy[1][1] : @focus_xy[0][1]
|
||||
target_y += @offset_xy[1]
|
||||
@sprite.angle = AnimationPlayer::Helper.angle_between(sprite_x, sprite_y, target_x, target_y)
|
||||
@sprite.angle += (@base_angle || 0)
|
||||
end
|
||||
|
||||
def update(elapsed_time)
|
||||
frame = (elapsed_time * FRAMES_PER_SECOND).floor
|
||||
changed_properties = []
|
||||
|
||||
@@ -77,7 +77,7 @@ module AnimationPlayer::Helper
|
||||
when :user_side_foreground, :user_side_background
|
||||
ret = [Battle::Scene.pbBattlerPosition(user_index)]
|
||||
when :target_side_foreground, :target_side_background
|
||||
ret = [Battle::Scene.pbBattlerPosition(target_idx)]
|
||||
ret = [Battle::Scene.pbBattlerPosition(target_index)]
|
||||
end
|
||||
return ret
|
||||
end
|
||||
@@ -168,6 +168,48 @@ module AnimationPlayer::Helper
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def angle_between(x1, y1, x2, y2)
|
||||
diff_x = x1 - x2
|
||||
diff_y = y1 - y2
|
||||
ret = Math.atan(diff_x.to_f / diff_y) * 180 / Math::PI
|
||||
ret += 180 if diff_y < 0
|
||||
return ret
|
||||
end
|
||||
|
||||
def initial_angle_between(particle, focus, offset)
|
||||
x1 = 0
|
||||
y1 = 0
|
||||
x2 = (focus.length == 2) ? focus[1][0] : focus[0][0]
|
||||
y2 = (focus.length == 2) ? focus[1][1] : focus[0][1]
|
||||
[:x, :y].each do |property|
|
||||
next if !particle[property]
|
||||
particle[property].each do |cmd|
|
||||
break if cmd[1] > 0
|
||||
if property == :x
|
||||
x1 = cmd[2]
|
||||
else
|
||||
y1 = cmd[2]
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
if focus
|
||||
if focus.length == 2
|
||||
distance = GameData::Animation::USER_AND_TARGET_SEPARATION
|
||||
x1 = focus[0][0] + ((x1.to_f / distance[0]) * (focus[1][0] - focus[0][0])).to_i
|
||||
y1 = focus[0][1] + ((y1.to_f / distance[1]) * (focus[1][1] - focus[0][1])).to_i
|
||||
else
|
||||
x1 += focus[0][0]
|
||||
y1 += focus[0][1]
|
||||
end
|
||||
end
|
||||
x1 += offset[0]
|
||||
y1 += offset[1]
|
||||
return angle_between(x1, y1, x2, y2)
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# user_sprites, target_sprites = [front sprite, back sprite]
|
||||
def set_bitmap_and_origin(particle, sprite, user_index, target_index, user_sprites, target_sprites)
|
||||
return if sprite&.is_a?(Battle::Scene::BattlerSprite)
|
||||
|
||||
Reference in New Issue
Block a user