Class: Player
Instance Method Summary collapse
- #acceleration ⇒ Object
- #bottom_y ⇒ Object
- #char(rx, ry, ticks) ⇒ Object
- #dead? ⇒ Boolean
- #die! ⇒ Object
- #height ⇒ Object
-
#initialize(y, background) ⇒ Player
constructor
A new instance of Player.
- #jump ⇒ Object
- #jump! ⇒ Object
- #pixel(x, y, rx, ry, ticks) ⇒ Object
- #tick ⇒ Object
- #walk_on_building(b) ⇒ Object
- #width ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
Methods included from Renderable
Constructor Details
#initialize(y, background) ⇒ Player
Returns a new instance of Player.
311 312 313 314 315 316 |
# File 'lib/roflbalt.rb', line 311 def initialize y, background @y = y @background = background @velocity = 1 @walking = false end |
Instance Method Details
#acceleration ⇒ Object
352 353 354 355 356 357 358 |
# File 'lib/roflbalt.rb', line 352 def acceleration if @dead 0.05 else 0.35 end end |
#bottom_y ⇒ Object
365 |
# File 'lib/roflbalt.rb', line 365 def bottom_y; y + height end |
#char(rx, ry, ticks) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/roflbalt.rb', line 324 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 |
#dead? ⇒ Boolean
381 382 383 |
# File 'lib/roflbalt.rb', line 381 def dead? @dead end |
#die! ⇒ Object
377 378 379 380 |
# File 'lib/roflbalt.rb', line 377 def die! @dead = true @velocity = 0 end |
#height ⇒ Object
319 |
# File 'lib/roflbalt.rb', line 319 def height; 3 end |
#jump ⇒ Object
371 372 373 |
# File 'lib/roflbalt.rb', line 371 def jump jump! if @walking end |
#jump! ⇒ Object
374 375 376 |
# File 'lib/roflbalt.rb', line 374 def jump! @velocity = -2.5 end |
#pixel(x, y, rx, ry, ticks) ⇒ Object
320 321 322 |
# File 'lib/roflbalt.rb', line 320 def pixel x, y, rx, ry, ticks Pixel.new char(rx, ry, ticks), 255, @background.color(x, y) end |
#tick ⇒ Object
359 360 361 362 363 |
# File 'lib/roflbalt.rb', line 359 def tick @y += @velocity @velocity += acceleration @walking = false end |
#walk_on_building(b) ⇒ Object
366 367 368 369 370 |
# File 'lib/roflbalt.rb', line 366 def walk_on_building b @y = b.y - height @velocity = 0 @walking = true end |
#width ⇒ Object
318 |
# File 'lib/roflbalt.rb', line 318 def width; 3 end |
#x ⇒ Object
317 |
# File 'lib/roflbalt.rb', line 317 def x; 0; end |
#y ⇒ Object
364 |
# File 'lib/roflbalt.rb', line 364 def y; @y.round end |