Class: Doom::Game::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/doom/game/menu.rb

Overview

DOOM main menu system with title screen, new game, and difficulty selection.

Constant Summary collapse

SKULL_ANIM_TICS =

Skull cursor blink rate

8
SKILL_BABY =

Difficulty levels matching DOOM’s skill levels

0
SKILL_EASY =

I’m too young to die

1
SKILL_MEDIUM =

Hey, not too rough

2
SKILL_HARD =

Hurt me plenty

3
SKILL_NIGHTMARE =

Ultra-Violence

4
STATE_TITLE =

Menu states

:title
STATE_MAIN =
:main
STATE_SKILL =
:skill
STATE_OPTIONS =
:options
STATE_NONE =

In-game, no menu

:none
MAIN_ITEMS =

Main menu items

%i[new_game options quit].freeze
OPTIONS_ITEMS =

Options menu items

%i[god_mode infinite_ammo all_weapons fullscreen rubykaigi_mode].freeze
OPTIONS_LABELS =
{
  god_mode: "GOD MODE",
  infinite_ammo: "INFINITE AMMO",
  all_weapons: "ALL WEAPONS",
  fullscreen: "FULLSCREEN",
  rubykaigi_mode: "RUBYKAIGI MODE",
}.freeze
OPTIONS_X =
48
OPTIONS_Y =
50
OPTIONS_SPACING =
18
SKILL_ITEMS =

Skill menu items

[SKILL_BABY, SKILL_EASY, SKILL_MEDIUM, SKILL_HARD, SKILL_NIGHTMARE].freeze
MAIN_X =

Menu item Y positions (from Chocolate Doom m_menu.c)

97
MAIN_Y =
64
MAIN_SPACING =
16
SKILL_X =
48
SKILL_Y =
63
SKILL_SPACING =
16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wad, hud_graphics, font = nil) ⇒ Menu

Returns a new instance of Menu.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/doom/game/menu.rb', line 54

def initialize(wad, hud_graphics, font = nil)
  @wad = wad
  @gfx = hud_graphics
  @font = font
  @state = STATE_TITLE
  @cursor = 0
  @skull_frame = 0
  @skull_tic = 0
  @selected_skill = SKILL_MEDIUM  # Default difficulty
  @game_started = false

  # Options toggles
  @options = {
    god_mode: false,
    infinite_ammo: false,
    all_weapons: false,
    fullscreen: false,
    rubykaigi_mode: false,
  }

  load_graphics
end

Instance Attribute Details

#fontObject (readonly)

Returns the value of attribute font.



52
53
54
# File 'lib/doom/game/menu.rb', line 52

def font
  @font
end

#optionsObject (readonly)

Returns the value of attribute options.



52
53
54
# File 'lib/doom/game/menu.rb', line 52

def options
  @options
end

#selected_skillObject (readonly)

Returns the value of attribute selected_skill.



52
53
54
# File 'lib/doom/game/menu.rb', line 52

def selected_skill
  @selected_skill
end

#stateObject (readonly)

Returns the value of attribute state.



52
53
54
# File 'lib/doom/game/menu.rb', line 52

def state
  @state
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/doom/game/menu.rb', line 77

def active?
  @state != STATE_NONE
end

#dismissObject



121
122
123
124
# File 'lib/doom/game/menu.rb', line 121

def dismiss
  @state = STATE_NONE
  @game_started = true
end

#handle_key(key) ⇒ Object

Returns :start_game, :resume, :quit, or option action symbols



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/doom/game/menu.rb', line 107

def handle_key(key)
  case @state
  when STATE_TITLE
    @state = STATE_MAIN
    @cursor = 0
  when STATE_MAIN
    handle_main_key(key)
  when STATE_SKILL
    handle_skill_key(key)
  when STATE_OPTIONS
    handle_options_key(key)
  end
end

#needs_background?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/doom/game/menu.rb', line 81

def needs_background?
  @state != STATE_TITLE
end

#render(framebuffer, palette_colors) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/doom/game/menu.rb', line 93

def render(framebuffer, palette_colors)
  case @state
  when STATE_TITLE
    render_title(framebuffer)
  when STATE_MAIN
    render_main_menu(framebuffer)
  when STATE_SKILL
    render_skill_menu(framebuffer)
  when STATE_OPTIONS
    render_options_menu(framebuffer)
  end
end

#showObject



126
127
128
129
# File 'lib/doom/game/menu.rb', line 126

def show
  @state = STATE_MAIN
  @cursor = 0
end

#updateObject



85
86
87
88
89
90
91
# File 'lib/doom/game/menu.rb', line 85

def update
  @skull_tic += 1
  if @skull_tic >= SKULL_ANIM_TICS
    @skull_tic = 0
    @skull_frame = 1 - @skull_frame
  end
end