public
Created

ROFLBALT Player

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
class Player
include Renderable
def initialize y, background
@y = y
@background = background
@velocity = 1
@walking = false
end
def x; 0; end
def width; 3 end
def height; 3 end
def pixel x, y, rx, ry, ticks
Pixel.new char(rx, ry, ticks), 255, @background.color(x, y)
end
 
def char rx, ry, ticks
if dead?
[
' @ ',
'\+/',
' \\\\',
][ry][rx]
elsif !@walking
[
' O/',
'/| ',
'/ >',
][ry][rx]
else
[
[
' O ',
'/|v',
'/ >',
],
[
' 0 ',
',|\\',
' >\\',
],
][ticks / 4 % 2][ry][rx]
end
end
def acceleration
if @dead
0.05
else
0.35
end
end
def tick
@y += @velocity
@velocity += acceleration
@walking = false
end
def y; @y.round end
def bottom_y; y + height end
def walk_on_building b
@y = b.y - height
@velocity = 0
@walking = true
end
def jump
jump! if @walking
end
def jump!
@velocity = -2.5
end
def die!
@dead = true
@velocity = 0
end
def dead?
@dead
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.