Class: Doom::Render::WeaponRenderer
- Inherits:
-
Object
- Object
- Doom::Render::WeaponRenderer
- Defined in:
- lib/doom/render/weapon_renderer.rb
Overview
Renders the first-person weapon view
Constant Summary collapse
- WEAPON_AREA_HEIGHT =
Weapon is rendered above the status bar
SCREEN_HEIGHT - StatusBar::STATUS_BAR_HEIGHT
- WEAPONTOP =
Chocolate Doom R_DrawPSprite weapon positioning: centery = viewheight/2 (view area excluding status bar) texturemid = centery - (WEAPONTOP - spritetopoffset) dc_yl = centery - texturemid (first visible row)
32- VIEW_CENTERY =
104
(SCREEN_HEIGHT - StatusBar::STATUS_BAR_HEIGHT) / 2
Instance Method Summary collapse
-
#initialize(hud_graphics, player_state) ⇒ WeaponRenderer
constructor
A new instance of WeaponRenderer.
- #render(framebuffer) ⇒ Object
Constructor Details
#initialize(hud_graphics, player_state) ⇒ WeaponRenderer
Returns a new instance of WeaponRenderer.
17 18 19 20 |
# File 'lib/doom/render/weapon_renderer.rb', line 17 def initialize(hud_graphics, player_state) @gfx = hud_graphics @player = player_state end |
Instance Method Details
#render(framebuffer) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/doom/render/weapon_renderer.rb', line 22 def render(framebuffer) weapon_name = @player.weapon_name weapon_data = @gfx.weapons[weapon_name] return unless weapon_data # Get the appropriate frame sprite = if @player.attacking && weapon_data[:fire]&.any? frame = @player.attack_frame.clamp(0, weapon_data[:fire].length - 1) weapon_data[:fire][frame] else weapon_data[:idle] end return unless sprite # Bob offset (frozen during attack to keep weapon steady) bob_x = @player.attacking ? 0 : @player.weapon_bob_x.to_i bob_y = @player.attacking ? 0 : @player.weapon_bob_y.to_i # Chocolate Doom on 200px: dc_yl = WEAPONTOP - topoffset # Our view area is 208px (240-32 status bar) vs DOOM's 168px (200-32) # Offset by half the extra height to keep weapon centered in view x = 1 - sprite.left_offset + bob_x y = WEAPONTOP - sprite.top_offset + 20 + bob_y draw_weapon_sprite(framebuffer, sprite, x, y) # Draw muzzle flash only on the first fire frame (the actual shot) if @player.attacking && @player.attack_frame == 0 draw_muzzle_flash(framebuffer, weapon_name) end end |