Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created February 3, 2012 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruprict/1726918 to your computer and use it in GitHub Desktop.
Save ruprict/1726918 to your computer and use it in GitHub Desktop.
ROFLBALT Player
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment