Class: Player

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/roflbalt.rb

Instance Method Summary collapse

Methods included from Renderable

#each_pixel, #right_x

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

#accelerationObject



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_yObject



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

Returns:

  • (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

#heightObject



319
# File 'lib/roflbalt.rb', line 319

def height; 3 end

#jumpObject



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

#tickObject



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

#widthObject



318
# File 'lib/roflbalt.rb', line 318

def width; 3 end

#xObject



317
# File 'lib/roflbalt.rb', line 317

def x; 0; end

#yObject



364
# File 'lib/roflbalt.rb', line 364

def y; @y.round end