Class: Doom::Render::StatusBar
- Inherits:
-
Object
- Object
- Doom::Render::StatusBar
- Defined in:
- lib/doom/render/status_bar.rb
Overview
Renders the classic DOOM status bar at the bottom of the screen
Constant Summary collapse
- STATUS_BAR_HEIGHT =
32- STATUS_BAR_Y =
SCREEN_HEIGHT - STATUS_BAR_HEIGHT
- AMMO_RIGHT_X =
DOOM status bar layout (from st_stuff.c) Positions from Chocolate Doom st_stuff.c (relative to status bar top)
44- HEALTH_RIGHT_X =
ST_AMMOX - right edge of 3-digit ammo
90- ARMOR_RIGHT_X =
ST_HEALTHX
221- ARMS_BG_X =
ST_ARMORX
104- ARMS_BG_Y =
ST_ARMSBGX
0- ARMS_X =
ST_ARMSBGY (relative to status bar)
111- ARMS_Y =
ST_ARMSX
4- ARMS_XSPACE =
ST_ARMSY (relative to status bar)
12- ARMS_YSPACE =
10- FACE_X =
Centered in face background area
149- FACE_Y =
Vertically centered in status bar
2- KEYS_X =
ST_KEY0X
239- SMALL_AMMO_X =
Small ammo counts (right side of status bar)
288- SMALL_MAX_X =
Current ammo X
314- SMALL_AMMO_Y =
Max ammo X
[5, 11, 23, 17]
- NUM_WIDTH =
Width of large digit
14- SMALL_NUM_WIDTH =
Width of small digit
4
Instance Attribute Summary collapse
-
#gfx ⇒ Object
readonly
Returns the value of attribute gfx.
-
#player ⇒ Object
writeonly
Re-pointed on world rebind (map change, netgame resync).
Instance Method Summary collapse
-
#initialize(hud_graphics, player_state) ⇒ StatusBar
constructor
A new instance of StatusBar.
- #render(framebuffer) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(hud_graphics, player_state) ⇒ StatusBar
Returns a new instance of StatusBar.
39 40 41 42 43 44 |
# File 'lib/doom/render/status_bar.rb', line 39 def initialize(hud_graphics, player_state) @gfx = hud_graphics @player = player_state @face_timer = 0 @face_index = 0 end |
Instance Attribute Details
#gfx ⇒ Object (readonly)
Returns the value of attribute gfx.
36 37 38 |
# File 'lib/doom/render/status_bar.rb', line 36 def gfx @gfx end |
#player=(value) ⇒ Object (writeonly)
Re-pointed on world rebind (map change, netgame resync)
37 38 39 |
# File 'lib/doom/render/status_bar.rb', line 37 def player=(value) @player = value end |
Instance Method Details
#render(framebuffer) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/doom/render/status_bar.rb', line 46 def render(framebuffer) # Draw status bar background draw_sprite(framebuffer, @gfx., 0, STATUS_BAR_Y) if @gfx. # Draw arms background (single-player only, replaces FRAG area) draw_sprite(framebuffer, @gfx.arms_background, ARMS_BG_X, STATUS_BAR_Y + ARMS_BG_Y) if @gfx.arms_background # Y position for numbers (3 pixels from top of status bar) num_y = STATUS_BAR_Y + 3 # Draw ammo count (right-aligned ending at AMMO_RIGHT_X) draw_number_right(framebuffer, @player.current_ammo, AMMO_RIGHT_X, num_y) if @player.current_ammo # Draw health with percent draw_number_right(framebuffer, @player.health, HEALTH_RIGHT_X, num_y) draw_percent(framebuffer, HEALTH_RIGHT_X, num_y) # Draw weapon selector (2-7) draw_arms(framebuffer) # Draw face draw_face(framebuffer) # Draw armor with percent draw_number_right(framebuffer, @player.armor, ARMOR_RIGHT_X, num_y) draw_percent(framebuffer, ARMOR_RIGHT_X, num_y) # Draw keys draw_keys(framebuffer) # Draw small ammo counts (right side) draw_ammo_counts(framebuffer) end |
#update ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/doom/render/status_bar.rb', line 80 def update # Cycle face animation @face_timer += 1 return unless @face_timer > 15 # Change face every ~0.5 seconds @face_timer = 0 @face_index = (@face_index + 1) % 3 end |