Class: Pacman::BoardScale

Inherits:
Object
  • Object
show all
Defined in:
lib/pacman/board_scale.rb

Overview

How much the board is zoomed for a given terminal, and how that zoom slows the game's movement pace so on-screen speed stays roughly constant.

Constant Summary collapse

HUD_ROWS =
2
SLOWDOWN_ZOOM =
3

Instance Method Summary collapse

Constructor Details

#initialize(screen:, maze:) ⇒ BoardScale

Returns a new instance of BoardScale.



9
10
11
12
# File 'lib/pacman/board_scale.rb', line 9

def initialize(screen:, maze:)
  @screen = screen
  @maze = maze
end

Instance Method Details

#cramped?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/pacman/board_scale.rb', line 18

def cramped?
  factor < 1
end

#factorObject



14
15
16
# File 'lib/pacman/board_scale.rb', line 14

def factor
  [width_factor, height_factor].min
end

#paceObject

Timer pulses per movement tick: full speed at modest zooms, one gentle halving once cells get big enough that motion would blur across the board.



26
27
28
# File 'lib/pacman/board_scale.rb', line 26

def pace
  (factor >= SLOWDOWN_ZOOM) ? 2 : 1
end