Created
January 9, 2015 20:07
-
-
Save shawn42/acd0e39ad57d9fa35a6e to your computer and use it in GitHub Desktop.
Shadow effect in Gamebox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define_behavior :faded do | |
requires :timer_manager | |
setup do | |
actor.has_attributes shadows: [], shadows_to_render: opts[:shadows_to_render] | |
timer_manager.add_timer timer_name, 100 do | |
new_shadow = {x: actor.x, y: actor.y} | |
actor.shadows << new_shadow | |
actor.shadows.shift if actor.shadows.size > actor.shadows_to_render | |
end | |
reacts_with :remove | |
end | |
helpers do | |
def timer_name | |
"actor_shadow_#{actor.object_id}" | |
end | |
def remove | |
timer_manager.remove_timer timer_name | |
end | |
end | |
end | |
define_actor :player do | |
has_behaviors do | |
positioned | |
faded shadows_to_render: 10 | |
end | |
view do | |
draw do |target, x_off, y_off, z| | |
c = Color::RED | |
scale = 255.0/actor.shadows.size | |
actor.shadows.each.with_index do |s, i| | |
x = s[:x] + x_off | |
y = s[:y] + y_off | |
alpha = i * scale | |
shadow_color = [c.red,c.green,c.blue,alpha] | |
target.draw_box x,y, x+20, y+20, shadow_color, 1 | |
end | |
# draw current | |
x = actor.x + x_off | |
y = actor.y + y_off | |
target.draw_box x,y, x+20, y+20, Color::RED, 1 | |
end | |
end | |
end | |
define_stage :demo do | |
requires :tween_manager | |
curtain_up do | |
@player = spawn :player, x: 10, y:30 | |
tween = tween_manager.tween_properties @player, {x: 600, y:750}, 6_000, Tween::Sine::InOut | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment