Permalink
Browse files

animation hack

  • Loading branch information...
1 parent 8c64dda commit 28cddc638d88d376bc6d6dceee79aca0c5242999 @oneup committed Nov 28, 2008
Showing with 37 additions and 13 deletions.
  1. +5 −4 activeresource.rb
  2. +1 −1 backend/output/gosu.rb
  3. BIN mm9/blue/stand.png
  4. +31 −8 mm9/mm9.rb
View
@@ -25,8 +25,8 @@ def is_yml?
"#{self}.yml".is_file?
end
- def anim(tile_width, tile_height)
- Animation.cache(self, tile_width, tile_height)
+ def anim(tile_width, tile_height, duration=1)
+ Animation.cache(self, tile_width, tile_height, duration)
end
def img
@@ -50,15 +50,16 @@ def initialize file_name, tile_width=nil, tile_height=nil, duration=1
@frames = []
@yml['frames'].each do |frame|
- @frames << [frame['duration'] || 3, Image.cache(frame['image'])]
+ @frames << [frame['duration'] || duration, Image.cache(frame['image'])]
end
end
# rescue
# raise "error while loading animation config #{file_name}"
end
def draw x, y, order=0, zoom_x=1, zoom_y=1
- @frames[Gosu::milliseconds / 100 % @frames.size][1].draw(x, y, order, zoom_x, zoom_y)
+ current_frame = (Gosu::milliseconds / (100*@frames[0][0]) % @frames.size) # hackish
+ @frames[current_frame][1].draw(x, y, order, zoom_x, zoom_y)
end
end
View
@@ -9,7 +9,7 @@ def self.resolution r
@@resolution = r
end
- def self.fullscreen= f
+ def self.fullscreen f
@@fullscreen = f
end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -5,32 +5,55 @@
# thx http://youtube.com/watch?v=9pUmfxM9h54
class Mm9 < Game
+ fullscreen false
+
def setup
- @objects << Ball.new
+ @objects << Player.new
end
def draw
super
- "mm9/blue/run".anim(24,24).draw(mouse_x,mouse_y) # zoom
end
end
-class Ball < Gameobject
+class Player < Gameobject
def initialize
@x = 0
@y = 0
- @velocity_x = 10
- @velocity_y = 10
+ @velocity_x = 0
+ @velocity_y = 0
+ @speed = 4
+
+ set_keys(Gosu::Button::KbRight => :run_right,
+ Gosu::Button::KbLeft => :run_left)
+ end
+
+ def run_right(down)
+ if down
+ @velocity_x = @speed
+ else
+ @velocity_x = 0
+ end
+ end
+
+ def run_left(down)
+ if down
+ @velocity_x = -@speed
+ else
+ @velocity_x = 0
+ end
end
def update
@x += @velocity_x
@y += @velocity_y
- @velocity_x = -@velocity_x if @x > $game.width or @x < 0
- @velocity_y = -@velocity_y if @y > $game.height or @y < 0
end
def draw
- "mm9/green_standing".img.draw(@x, @y, 0, 1+(@y.to_f/$game.height)*2, 1+(@y.to_f/$game.height)*2)
+ if @velocity_x > 0
+ "mm9/blue/run".anim(24,24).draw(@x, @y) # zoom
+ else
+ "mm9/blue/stand".anim(24,24,50).draw(@x, @y)
+ end
end
end

0 comments on commit 28cddc6

Please sign in to comment.