Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Legs
- attr_reader :x
- attr_reader :y
- attr_reader :next_x
- attr_reader :next_y
- def initialize(sprite)
- @frame = 1
- @tick_count = 0
- @sprite = sprite
- @x = 128
- @y = 128
- @next_x = 128
- @next_y = 128
- @depth = 1
- end
- def move(x,y)
- @next_x += x
- @next_y += y
- end
- def jump(x,y)
- @x = x
- @y = y
- @next_x = @x
- @next_y = @y
- end
- def update(world)
- if @next_x == @x && @next_y == @y
- if @frame%2 == 1
- @tick_count += 8
- @tick_count = @tick_count%32
- @frame = @tick_count/8
- end
- if @tick_count%8 != 7
- @tick_count = 8*@frame + 7
- end
- else
- @tick_count += 1
- @tick_count = @tick_count%32
- end
- @frame = @tick_count/8
- if world.valid_move(self, @next_x, @y)
- @x = @next_x
- end
- if world.valid_move(self, @x, @next_y-24)
- @y = @next_y
- end
- @next_x = x
- @next_y = y
- end
- def width
- 24
- end
- def height
- 48
- end
- def draw
- @sprite[@frame].draw(@x,@y,1+@y)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement