Advertisement
heroofhyla

Legs

Nov 12th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.09 KB | None | 0 0
  1. class Legs
  2.   attr_reader :x
  3.   attr_reader :y
  4.   attr_reader :next_x
  5.   attr_reader :next_y  
  6.  
  7.   def initialize(sprite)
  8.     @frame = 1
  9.     @tick_count = 0
  10.     @sprite = sprite
  11.     @x = 128
  12.     @y = 128
  13.     @next_x = 128
  14.     @next_y = 128
  15.     @depth = 1
  16.   end
  17.  
  18.   def move(x,y)
  19.     @next_x += x
  20.     @next_y += y
  21.   end
  22.  
  23.   def jump(x,y)
  24.     @x = x
  25.     @y = y
  26.     @next_x = @x
  27.     @next_y = @y
  28.   end
  29.   def update(world)
  30.     if @next_x == @x && @next_y == @y
  31.       if @frame%2 == 1
  32.         @tick_count += 8
  33.         @tick_count = @tick_count%32
  34.         @frame = @tick_count/8
  35.       end
  36.       if @tick_count%8 != 7
  37.         @tick_count = 8*@frame + 7
  38.       end
  39.     else
  40.       @tick_count += 1
  41.       @tick_count = @tick_count%32
  42.     end
  43.     @frame = @tick_count/8
  44.     if world.valid_move(self, @next_x, @y)
  45.       @x = @next_x
  46.     end
  47.     if world.valid_move(self, @x, @next_y-24)
  48.       @y = @next_y
  49.     end
  50.    
  51.     @next_x = x
  52.     @next_y = y
  53.   end
  54.   def width
  55.     24
  56.   end
  57.   def height
  58.     48
  59.   end
  60.   def draw
  61.     @sprite[@frame].draw(@x,@y,1+@y)
  62.   end
  63. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement