Class: Doom::Game::SectorActions

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

Overview

Manages animated sector actions (doors, lifts, etc.)

Constant Summary collapse

DOOR_CLOSED =

Door states

0
DOOR_OPENING =
1
DOOR_OPEN =
2
DOOR_CLOSING =
3
DOOR_SPEED =

Door speeds (units per tic, 35 tics/sec)

2
DOOR_WAIT =

Tics to wait when open (~4 seconds)

150
PLAYER_HEIGHT =
56
LIFT_SPEED =

Lift constants

4
LIFT_WAIT =

~3 seconds

105

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map, sound_engine = nil) ⇒ SectorActions

Returns a new instance of SectorActions.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/doom/game/sector_actions.rb', line 32

def initialize(map, sound_engine = nil)
  @map = map
  @sound = sound_engine
  @active_doors = {}   # sector_index => door_state
  @active_lifts = {}   # sector_index => lift_state
  @player_x = 0
  @player_y = 0
  @exit_triggered = nil
  @secrets_found = {}  # sector_index => true
  @crossed_linedefs = {}
end

Instance Attribute Details

#exit_triggeredObject (readonly)

Returns the value of attribute exit_triggered.



24
25
26
# File 'lib/doom/game/sector_actions.rb', line 24

def exit_triggered
  @exit_triggered
end

#secrets_foundObject (readonly)

Returns the value of attribute secrets_found.



24
25
26
# File 'lib/doom/game/sector_actions.rb', line 24

def secrets_found
  @secrets_found
end

Instance Method Details

#pop_teleportObject



26
27
28
29
30
# File 'lib/doom/game/sector_actions.rb', line 26

def pop_teleport
  dest = @teleport_dest
  @teleport_dest = nil
  dest
end

#updateObject



49
50
51
52
53
54
# File 'lib/doom/game/sector_actions.rb', line 49

def update
  update_doors
  update_lifts
  check_walk_triggers
  check_secrets
end

#update_player_position(x, y) ⇒ Object



44
45
46
47
# File 'lib/doom/game/sector_actions.rb', line 44

def update_player_position(x, y)
  @player_x = x
  @player_y = y
end

#use_linedef(linedef, linedef_idx) ⇒ Object

Try to use a linedef (called when player presses use key)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/doom/game/sector_actions.rb', line 57

def use_linedef(linedef, linedef_idx)
  return false if linedef.special == 0

  case linedef.special
  # --- Doors ---
  when 1    # DR Door Open Wait Close
    activate_door(linedef)
  when 26   # DR Blue Door
    activate_door(linedef, key: :blue_card)
  when 27   # DR Yellow Door
    activate_door(linedef, key: :yellow_card)
  when 28   # DR Red Door
    activate_door(linedef, key: :red_card)
  when 31   # D1 Door Open Stay
    activate_door(linedef, stay_open: true)
  when 32   # D1 Blue Door Open Stay
    activate_door(linedef, key: :blue_card, stay_open: true)
  when 33   # D1 Red Door Open Stay
    activate_door(linedef, key: :red_card, stay_open: true)
  when 34   # D1 Yellow Door Open Stay
    activate_door(linedef, key: :yellow_card, stay_open: true)
  when 103  # S1 Door Open Wait Close (tagged)
    activate_tagged_door(linedef)

  # --- Lifts ---
  when 62   # SR Lift Lower Wait Raise (repeatable)
    activate_lift(linedef)

  # --- Floor changes ---
  when 18   # S1 Raise Floor to Next Higher
    raise_floor_to_next(linedef)
  when 20   # S1 Raise Floor to Next Higher (platform)
    raise_floor_to_next(linedef)
  when 22   # W1 Raise Floor to Next Higher
    raise_floor_to_next(linedef)
  when 23   # S1 Lower Floor to Lowest
    lower_floor_to_lowest(linedef)
  when 36   # S1 Lower Floor to Highest Adjacent - 8
    lower_floor_to_highest(linedef)
  when 70   # SR Lower Floor to Highest Adjacent - 8
    lower_floor_to_highest(linedef)

  # --- Exits ---
  when 11   # S1 Exit
    @exit_triggered = :normal
  when 51   # S1 Secret Exit
    @exit_triggered = :secret

  else
    return false
  end
  true
end