Class: Doom::Game::Menu

Inherits:
Object
  • Object
show all
Includes:
FramebufferBlitter
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
NETGAME_UNSAFE_OPTIONS =

Menu entries that change the simulation on this machine alone. In a netgame every peer must run the same world from the same commands, so a local cheat or a local new game is a genuine desync, not a nuisance. They are hidden rather than ignored: an option that silently does nothing is worse than one that is not offered.

i[god_mode infinite_ammo all_weapons].freeze
NETGAME_UNSAFE_MAIN =
i[new_game].freeze
OPTIONS_ITEMS =

Options menu items

i[god_mode infinite_ammo all_weapons uncapped_fps fullscreen fog flashlight rt_bounces
rubykaigi_mode].freeze
OPTIONS_LABELS =
{
  god_mode: 'GOD MODE',
  infinite_ammo: 'INFINITE AMMO',
  all_weapons: 'ALL WEAPONS',
  uncapped_fps: 'UNCAPPED FPS',
  fullscreen: 'FULLSCREEN',
  fog: 'RAY FOG',
  flashlight: 'FLASHLIGHT',
  rt_bounces: 'RT BOUNCES',
  rubykaigi_mode: 'RUBYKAIGI MODE'
}.freeze
OPTIONS_X =
48
OPTIONS_Y =
50
OPTIONS_SPACING =
16
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

Methods included from FramebufferBlitter

#blit_sprite

Constructor Details

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/doom/game/menu.rb', line 72

def initialize(_wad, hud_graphics, font = nil)
  @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
  @netgame = false

  # Options toggles
  @options = {
    god_mode: false,
    infinite_ammo: false,
    all_weapons: false,
    uncapped_fps: true,
    fullscreen: false,
    fog: true,
    flashlight: true,
    rt_bounces: true,
    rubykaigi_mode: false
  }

  load_graphics
end

Instance Attribute Details

#fontObject (readonly)

Returns the value of attribute font.



69
70
71
# File 'lib/doom/game/menu.rb', line 69

def font
  @font
end

#netgameObject

Returns the value of attribute netgame.



70
71
72
# File 'lib/doom/game/menu.rb', line 70

def netgame
  @netgame
end

#optionsObject (readonly)

Returns the value of attribute options.



69
70
71
# File 'lib/doom/game/menu.rb', line 69

def options
  @options
end

#selected_skillObject (readonly)

Returns the value of attribute selected_skill.



69
70
71
# File 'lib/doom/game/menu.rb', line 69

def selected_skill
  @selected_skill
end

#stateObject (readonly)

Returns the value of attribute state.



69
70
71
# File 'lib/doom/game/menu.rb', line 69

def state
  @state
end

Instance Method Details

#active?Boolean



99
100
101
# File 'lib/doom/game/menu.rb', line 99

def active?
  @state != STATE_NONE
end

#dismissObject



153
154
155
156
# File 'lib/doom/game/menu.rb', line 153

def dismiss
  @state = STATE_NONE
  @game_started = true
end

#handle_key(key) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/doom/game/menu.rb', line 139

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

#main_itemsObject

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



131
132
133
# File 'lib/doom/game/menu.rb', line 131

def main_items
  @netgame ? MAIN_ITEMS - NETGAME_UNSAFE_MAIN : MAIN_ITEMS
end

#needs_background?Boolean



103
104
105
# File 'lib/doom/game/menu.rb', line 103

def needs_background?
  @state != STATE_TITLE
end

#options_itemsObject



135
136
137
# File 'lib/doom/game/menu.rb', line 135

def options_items
  @netgame ? OPTIONS_ITEMS - NETGAME_UNSAFE_OPTIONS : OPTIONS_ITEMS
end

#render(framebuffer, _palette_colors) ⇒ Object

NOTE: palette_colors is unused here (callers in gosu_window.rb pass nil). Kept only to preserve the call signature; drop it once the callers do.



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/doom/game/menu.rb', line 117

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



158
159
160
161
# File 'lib/doom/game/menu.rb', line 158

def show
  @state = STATE_MAIN
  @cursor = 0
end

#updateObject



107
108
109
110
111
112
113
# File 'lib/doom/game/menu.rb', line 107

def update
  @skull_tic += 1
  return unless @skull_tic >= SKULL_ANIM_TICS

  @skull_tic = 0
  @skull_frame = 1 - @skull_frame
end