Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Little main_game movements refactor

  • Loading branch information...
commit 5be41f08617a2172c3f3e1a3612683b5bdc93404 1 parent b14196a
@divins divins authored
Showing with 31 additions and 16 deletions.
  1. +31 −16 lib/rpg/scenes/main_game.rb
View
47 lib/rpg/scenes/main_game.rb
@@ -13,7 +13,6 @@ def setup
@sprite = sprite path_of("../resources/sprite.png")
@sprite.sheet_size = [4, 4]
@camera = Ray::View.new @sprite.pos, window.size
- @text = text "Oh Man", :size => 30
end
def register
@@ -23,7 +22,6 @@ def register
def render(win)
always
win.draw @sky
- win.draw @text
win.with_view @camera do # Apply scrolling
win.draw @sprite
@@ -34,7 +32,7 @@ def clean_up
end
def always
- movements
+ movement
end
def in_game_options
@@ -43,24 +41,16 @@ def in_game_options
end
end
- def movements
+ def movement
if animations.empty?
if holding? :down
- animations << sprite_animation(:from => [0, 0], :to => [4, 0],
- :duration => 0.3).start(@sprite)
- animations << translation(:of => [0, 32], :duration => 0.3).start(@sprite)
+ move_towards :down
elsif holding? :left
- animations << sprite_animation(:from => [0, 1], :to => [4, 1],
- :duration => 0.3).start(@sprite)
- animations << translation(:of => [-32, 0], :duration => 0.3).start(@sprite)
+ move_towards :left
elsif holding? :right
- animations << sprite_animation(:from => [0, 2], :to => [4, 2],
- :duration => 0.3).start(@sprite)
- animations << translation(:of => [32, 0], :duration => 0.3).start(@sprite)
+ move_towards :right
elsif holding? :up
- animations << sprite_animation(:from => [0, 3], :to => [4, 3],
- :duration => 0.3).start(@sprite)
- animations << translation(:of => [0, -32], :duration => 0.3).start(@sprite)
+ move_towards :up
end
end
@@ -72,5 +62,30 @@ def movements
@camera.center = [camera_x, camera_y]
end
+
+ def move_towards(dir)
+ case dir
+ when :up
+ from = [0, 3]
+ to = [4, 3]
+ of = [0, -32]
+ when :down
+ from = [0, 0]
+ to = [4, 0]
+ of = [0, 32]
+ when :right
+ from = [0, 2]
+ to = [4, 2]
+ of = [32, 0]
+ when :left
+ from = [0, 1]
+ to = [4, 1]
+ of = [-32, 0]
+ end
+
+ animations << sprite_animation(:from => from, :to => to,
+ :duration => 0.3).start(@sprite)
+ animations << translation(:of => of, :duration => 0.3).start(@sprite)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.