Created
February 3, 2012 01:20
-
-
Save ruprict/1726918 to your computer and use it in GitHub Desktop.
ROFLBALT Player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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