Skip to content

Commit e1fdfc6

Browse files
committed
Void spreading enemy: Add ingesting state
In TileMapCover: Report the nodes as they are being consumed. And fix the function documentation comment, previously it was also returning true or false if nodes (not tiles) were consumed. In the enemy new ingesting state, it does nothing more than waiting. Transition to this state if the metadata of a consumed node says to be ingested, and set the waiting to that amount of time. Also emit particles when not the enemy is not moving. The previous solution for emitting particles when not consuming stuff was distance-based. Now if the enemy is standing in the new INGESTING state, nothing would be displayed.
1 parent 519f35b commit e1fdfc6

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

scenes/quests/lore_quests/quest_002/1_void_runner/components/tile_map_cover.gd

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func _ready() -> void:
116116

117117
## Cover all [param cells] with [member terrain_name], hiding any nodes in those cells which are
118118
## direct children of [member consumable_node_holders].
119-
## Return true if any cells were consumed.
120-
func consume_cells(cells: Array[Vector2i], immediate: bool = false) -> bool:
119+
## Return true if any nodes were consumed.
120+
func consume_cells(cells: Array[Vector2i], immediate: bool = false) -> Array[Node2D]:
121121
for i in range(cells.size() - 1, -1, -1):
122122
var c: Vector2i = cells[i]
123123

@@ -128,35 +128,44 @@ func consume_cells(cells: Array[Vector2i], immediate: bool = false) -> bool:
128128
if cells:
129129
set_cells_terrain_connect(cells, terrain_set, _terrain_id)
130130

131+
var consumed_nodes := [] as Array[Node2D]
131132
for cell in cells:
132-
consume(cell, immediate)
133-
return true
134-
return false
133+
var nodes := consume(cell, immediate)
134+
consumed_nodes.append_array(nodes)
135+
return consumed_nodes
136+
return []
135137

136138

137139
## Hide all nodes in cell [param coord] which are direct children of
138140
## [member consumable_node_holders].
139-
func consume(coord: Vector2i, immediate: bool = false) -> void:
141+
func consume(coord: Vector2i, immediate: bool = false) -> Array[Node2D]:
140142
if coord not in _unconsumed_nodes:
141-
return
143+
return []
144+
145+
var consumed_nodes := [] as Array[Node2D]
142146

143147
var nodes: Array = _unconsumed_nodes[coord]
144148
_unconsumed_nodes.erase(coord)
145149
# TODO: store previous modulate.a to restore in uncover_all()
146150
if immediate:
147151
for node: Node2D in nodes:
148152
node.modulate.a = 0.0
153+
consumed_nodes.append(node)
149154
else:
150155
var tween := create_tween().set_parallel(true)
151156
for node: Node2D in nodes:
152157
tween.tween_property(node, "modulate:a", 0.0, _DURATION).set_ease(Tween.EASE_OUT)
153-
await tween.finished
158+
tween.finished.connect(_on_consumed_node_tween_finished.bind(node))
159+
consumed_nodes.append(node)
154160

155-
for node: Node2D in nodes:
156-
# TODO: also store original visibility and process mode
157-
node.visible = false
158-
node.process_mode = Node.PROCESS_MODE_DISABLED
159161
_consumed_nodes[coord] = nodes
162+
return consumed_nodes
163+
164+
165+
func _on_consumed_node_tween_finished(node: Node2D) -> void:
166+
## TODO: also store original visibility and process mode
167+
node.visible = false
168+
node.process_mode = Node.PROCESS_MODE_DISABLED
160169

161170

162171
## Clear this layer, and reveal all previously-"consumed" nodes, with an animation.

scenes/quests/lore_quests/quest_002/1_void_runner/components/void_spreading_enemy.gd

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ enum State {
99
IDLE,
1010
## The void is chasing the player
1111
CHASING,
12+
## The void is busy ingesting something else, not the player for now
13+
INGESTING,
1214
## The void has engulfed the player
1315
CAUGHT,
1416
## The void has been defeated
@@ -28,6 +30,7 @@ const NEIGHBORS := [
2830
]
2931

3032
const IDLE_EMIT_DISTANCE := sqrt(2 * (64.0 ** 2))
33+
const IDLE_EMIT_TIME := 0.4
3134

3235
@export var void_layer: TileMapCover
3336

@@ -42,6 +45,7 @@ var state := State.IDLE:
4245

4346
var _last_position: Vector2
4447
var _distance_since_emit: float = 0.0
48+
var _time_since_emit: float = 0.0
4549
var _live_particles: int = 0
4650

4751
@onready var path_walk_behavior: PathWalkBehavior = %PathWalkBehavior
@@ -73,6 +77,9 @@ func _set_state(new_state: State) -> void:
7377
State.CHASING:
7478
path_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
7579
follow_walk_behavior.process_mode = Node.PROCESS_MODE_INHERIT
80+
State.INGESTING:
81+
path_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
82+
follow_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
7683
State.DEFEATED:
7784
path_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
7885
follow_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
@@ -99,6 +106,7 @@ func defeat() -> void:
99106
func _process(_delta: float) -> void:
100107
if state == State.DEFEATED:
101108
return
109+
_time_since_emit += _delta
102110
_distance_since_emit += (position - _last_position).length()
103111
_last_position = position
104112

@@ -111,12 +119,26 @@ func _process(_delta: float) -> void:
111119
for neighbor: int in NEIGHBORS:
112120
coords.append(void_layer.get_neighbor_cell(coord, neighbor))
113121

114-
var consumed := void_layer.consume_cells(coords)
115-
if consumed or _distance_since_emit >= IDLE_EMIT_DISTANCE:
122+
var consumed_nodes := void_layer.consume_cells(coords)
123+
if (
124+
consumed_nodes
125+
or _distance_since_emit >= IDLE_EMIT_DISTANCE
126+
or _time_since_emit >= IDLE_EMIT_TIME
127+
):
116128
_emit_particles()
117129

130+
if state == State.INGESTING:
131+
return
132+
for node in consumed_nodes:
133+
if node.has_meta(&"ingest_time"):
134+
var previous_state := state
135+
state = State.INGESTING
136+
await get_tree().create_timer(node.get_meta(&"ingest_time")).timeout
137+
state = previous_state
138+
118139

119140
func _emit_particles() -> void:
141+
_time_since_emit = 0
120142
_distance_since_emit = 0
121143

122144
var particles: GPUParticles2D = VOID_PARTICLES.instantiate()

0 commit comments

Comments
 (0)