diff options
Diffstat (limited to 'test/sprite.rb')
| -rw-r--r-- | test/sprite.rb | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/test/sprite.rb b/test/sprite.rb index 713375a..e62488b 100644 --- a/test/sprite.rb +++ b/test/sprite.rb @@ -6,17 +6,28 @@ else media = "media" end -set title: "Ruby 2D — Sprite", width: 350, height: 150 +set title: "Ruby 2D — Sprite", width: 400, height: 300 +coin1 = Sprite.new( + "#{media}/coin.png", + clip_width: 84, + time: 300, + loop: true +) + +coin1.play -coin = Sprite.new( +coin2 = Sprite.new( "#{media}/coin.png", + y: 90, + width: 42, + height: 42, clip_width: 84, time: 300, loop: true ) -coin.play +coin2.play boom = Sprite.new( "#{media}/boom.png", @@ -28,6 +39,8 @@ boom = Sprite.new( hero = Sprite.new( "#{media}/hero.png", x: 261, + width: 78, + height: 99, clip_width: 78, time: 250, animations: { @@ -39,7 +52,7 @@ hero = Sprite.new( atlas = Sprite.new( "#{media}/texture_atlas.png", - x: 10, y: 100, + x: 50, y: 90, animations: { count: [ { @@ -79,21 +92,58 @@ on :key_down do |e| case e.key when 'p' - coin.play + coin1.play + coin2.play boom.play atlas.play :count + when 'b' + boom.play nil, nil, nil do + puts "Boom animation finished!" + end when 's' - coin.stop + coin1.stop + coin2.stop hero.stop atlas.stop + when 'left' + hero.play :walk, :loop, :flip_h when 'right' hero.play :walk, :loop when 'up' hero.play :climb, :loop when 'down' + hero.play :climb, :loop, :flip_v + when 'h' + hero.play :climb, :loop, :flip_hv + when 'c' hero.play :cheer end end +on :key_held do |e| + case e.key + when 'a' + hero.play :walk, :loop, :flip_h + hero.x -= 1 + when 'd' + hero.play :walk, :loop + hero.x += 1 + when 'w' + hero.play :climb, :loop + hero.y -= 1 + when 's' + hero.play :climb, :loop, :flip_v + hero.y += 1 + when 'z' + hero.width = get(:mouse_x) + hero.height = get(:mouse_y) + end +end + +on :key_up do |e| + if ['w', 'a', 's', 'd'].include? e.key + hero.stop + end +end show |
