Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Created August 7, 2025 07:02
Show Gist options
  • Save amirrajan/67c40f69968f8a73dfbc7c6ad9a0a195 to your computer and use it in GitHub Desktop.
Save amirrajan/67c40f69968f8a73dfbc7c6ad9a0a195 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit: Easing Fubar
def tick args
duration = 120
args.state.after_image_queue ||= []
args.state.start_at = if Kernel.tick_count == 0
0
elsif Kernel.tick_count.zmod?(duration.idiv(2))
args.state.start_at + duration.idiv(2)
else
args.state.start_at
end
# fiddle with these numbers
fiddle_x_1 = 1
fiddle_x_2 = 5
if Kernel.tick_count % duration < duration.idiv(2)
perc = Easing.smooth_stop(start_at: args.state.start_at,
duration: duration.idiv(2),
tick_count: Kernel.tick_count,
power: 1)
start_x = 0
add_x = 320
pow_x = fiddle_x_1 + fiddle_x_2 * perc
start_y = 0
add_y = 320
else
perc = Easing.smooth_stop(start_at: args.state.start_at,
duration: duration.idiv(2),
tick_count: Kernel.tick_count,
power: 1, flip: true)
start_x = 640
add_x = -320
pow_x = fiddle_x_1 + fiddle_x_2 * perc
start_y = 0
add_y = 320
end
s = { x: start_x + add_x * perc ** pow_x,
y: start_y + add_y * perc,
w: 32,
h: 32,
path: :solid,
r: 0,
g: 0,
b: 0,
anchor_x: 0.5,
anchor_y: 0.5 }
if Kernel.tick_count.zmod?(2)
args.state.after_image_queue << { at: Kernel.tick_count,
sprite: s,
duration: 60 }
end
args.state.after_image_queue.reject! { |h| h.at.elapsed_time > h.duration }
args.outputs.sprites << s
args.outputs.sprites << args.state.after_image_queue.map do |h|
perc = Easing.smooth_start(start_at: h.at,
duration: h.duration,
tick_count: Kernel.tick_count,
power: 2,
flip: 1)
h.sprite.merge(a: perc * 255)
end
en
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment