Class: Doom::Render::WeaponRenderer

Inherits:
Object
  • Object
show all
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 top: dc_yl = WEAPONTOP - spritetopoffset

32

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hud_graphics, player_state) ⇒ WeaponRenderer

Returns a new instance of WeaponRenderer.



16
17
18
19
# File 'lib/doom/render/weapon_renderer.rb', line 16

def initialize(hud_graphics, player_state)
  @gfx = hud_graphics
  @player = player_state
end

Instance Attribute Details

#gfxObject (readonly)

Returns the value of attribute gfx.



13
14
15
# File 'lib/doom/render/weapon_renderer.rb', line 13

def gfx
  @gfx
end

#player=(value) ⇒ Object (writeonly)

Re-pointed on world rebind (map change, netgame resync)



14
15
16
# File 'lib/doom/render/weapon_renderer.rb', line 14

def player=(value)
  @player = value
end

Instance Method Details

#render(framebuffer) ⇒ Object



21
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
# File 'lib/doom/render/weapon_renderer.rb', line 21

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)
  return unless @player.attacking && @player.attack_frame == 0

  draw_muzzle_flash(framebuffer, weapon_name)
end