Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func _ready() -> void:

## Cover all [param cells] with [member terrain_name], hiding any nodes in those cells which are
## direct children of [member consumable_node_holders].
## Return true if any cells were consumed.
func consume_cells(cells: Array[Vector2i], immediate: bool = false) -> bool:
## Return true if any nodes were consumed.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started doing a data class for returning here:

class ConsumedInfo:
    var has_consumed_cells: bool
    var consumed_nodes: Array[Node2D]

And then I realized that the docstring I added for this function is wrong. It has been always returning if nodes were consumed, not cells.

func consume_cells(cells: Array[Vector2i], immediate: bool = false) -> Array[Node2D]:
for i in range(cells.size() - 1, -1, -1):
var c: Vector2i = cells[i]

Expand All @@ -128,35 +128,46 @@ func consume_cells(cells: Array[Vector2i], immediate: bool = false) -> bool:
if cells:
set_cells_terrain_connect(cells, terrain_set, _terrain_id)

var consumed_nodes := [] as Array[Node2D]
for cell in cells:
consume(cell, immediate)
return true
return false
var nodes := consume(cell, immediate)
consumed_nodes.append_array(nodes)
return consumed_nodes
return []
Comment on lines 128 to +136
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if cells:
set_cells_terrain_connect(cells, terrain_set, _terrain_id)
var consumed_nodes := [] as Array[Node2D]
for cell in cells:
consume(cell, immediate)
return true
return false
var nodes := consume(cell, immediate)
consumed_nodes.append_array(nodes)
return consumed_nodes
return []
var consumed_nodes: Array[Node2D]
if cells:
set_cells_terrain_connect(cells, terrain_set, _terrain_id)
for cell in cells:
var nodes := consume(cell, immediate)
consumed_nodes.append_array(nodes)
return consumed_nodes



## Hide all nodes in cell [param coord] which are direct children of
## [member consumable_node_holders].
func consume(coord: Vector2i, immediate: bool = false) -> void:
func consume(coord: Vector2i, immediate: bool = false) -> Array[Node2D]:
if coord not in _unconsumed_nodes:
return
return []

var consumed_nodes := [] as Array[Node2D]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above I think you can spell this as:

Suggested change
var consumed_nodes := [] as Array[Node2D]
var consumed_nodes: Array[Node2D]

and I believe it gets initialised to empty array (not null)


var nodes: Array = _unconsumed_nodes[coord]
_unconsumed_nodes.erase(coord)
# TODO: store previous modulate.a to restore in uncover_all()
if immediate:
for node: Node2D in nodes:
node.modulate.a = 0.0
consumed_nodes.append(node)
else:
var tween := create_tween().set_parallel(true)
for node: Node2D in nodes:
tween.tween_property(node, "modulate:a", 0.0, _DURATION).set_ease(Tween.EASE_OUT)
await tween.finished
tween.finished.connect(
_on_consumed_node_tween_finished.bind(node), CONNECT_REFERENCE_COUNTED
)
Comment on lines +158 to +160
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could connect to the tween's finish function just once with:

tween.finished.connect(_on_consumed_nodes_finished.bind(nodes))

and change its implementation to have a for loop?

consumed_nodes.append(node)

for node: Node2D in nodes:
# TODO: also store original visibility and process mode
node.visible = false
node.process_mode = Node.PROCESS_MODE_DISABLED
_consumed_nodes[coord] = nodes
return consumed_nodes
Comment on lines 163 to +164
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's confusing to have a local variable with the same name (minus an underscore) as a class field.



func _on_consumed_node_tween_finished(node: Node2D) -> void:
## TODO: also store original visibility and process mode
node.visible = false
node.process_mode = Node.PROCESS_MODE_DISABLED


## Clear this layer, and reveal all previously-"consumed" nodes, with an animation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum State {
IDLE,
## The void is chasing the player
CHASING,
## The void is busy ingesting something else, not the player for now
INGESTING,
## The void has engulfed the player
CAUGHT,
## The void has been defeated
Expand All @@ -28,6 +30,7 @@ const NEIGHBORS := [
]

const IDLE_EMIT_DISTANCE := sqrt(2 * (64.0 ** 2))
const IDLE_EMIT_TIME := 0.4

@export var void_layer: TileMapCover

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

var _last_position: Vector2
var _distance_since_emit: float = 0.0
var _time_since_emit: float = 0.0
var _live_particles: int = 0

@onready var path_walk_behavior: PathWalkBehavior = %PathWalkBehavior
Expand Down Expand Up @@ -73,6 +77,9 @@ func _set_state(new_state: State) -> void:
State.CHASING:
path_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
follow_walk_behavior.process_mode = Node.PROCESS_MODE_INHERIT
State.INGESTING:
path_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
follow_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
State.DEFEATED:
path_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
follow_walk_behavior.process_mode = Node.PROCESS_MODE_DISABLED
Expand All @@ -99,6 +106,7 @@ func defeat() -> void:
func _process(_delta: float) -> void:
if state == State.DEFEATED:
return
_time_since_emit += _delta
_distance_since_emit += (position - _last_position).length()
_last_position = position

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

var consumed := void_layer.consume_cells(coords)
if consumed or _distance_since_emit >= IDLE_EMIT_DISTANCE:
var consumed_nodes := void_layer.consume_cells(coords)
if (
consumed_nodes
or _distance_since_emit >= IDLE_EMIT_DISTANCE
or _time_since_emit >= IDLE_EMIT_TIME
):
_emit_particles()

if state == State.INGESTING:
return
for node in consumed_nodes:
if node.has_meta(&"ingest_time"):
var previous_state := state
state = State.INGESTING
await get_tree().create_timer(node.get_meta(&"ingest_time")).timeout
state = previous_state
Comment on lines +132 to +137
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for node in consumed_nodes:
if node.has_meta(&"ingest_time"):
var previous_state := state
state = State.INGESTING
await get_tree().create_timer(node.get_meta(&"ingest_time")).timeout
state = previous_state
var ingest_time := 0.0
for node in consumed_nodes:
ingest_time += node.get_meta(&"ingest_time", 0.0)
if ingest_time > 0:
var previous_state := state
state = State.INGESTING
await get_tree().create_timer(ingest_time).timeout
state = previous_state



func _emit_particles() -> void:
_time_since_emit = 0
_distance_since_emit = 0

var particles: GPUParticles2D = VOID_PARTICLES.instantiate()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[gd_scene load_steps=6 format=3 uid="uid://ktjtnp64e63v"]

[ext_resource type="Texture2D" uid="uid://cyvi71ryavsld" path="res://scenes/game_elements/props/decoration/books/components/Books_2.png" id="1_lljyg"]
[ext_resource type="Texture2D" uid="uid://b65dg7i548oip" path="res://scenes/game_elements/props/decoration/books/components/Books_1.png" id="2_ej8sk"]
[ext_resource type="Script" uid="uid://dabvr3pqmyya4" path="res://scenes/game_elements/props/hookable_area/components/hookable_area.gd" id="3_ej8sk"]

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_grfk2"]
radius = 12.0
height = 62.0

[sub_resource type="RectangleShape2D" id="RectangleShape2D_5vg6g"]
size = Vector2(72, 124)

[node name="BooksPile" type="CharacterBody2D"]
metadata/ingest_time = 2.0

[node name="Books2" type="Sprite2D" parent="."]
position = Vector2(2, -15)
texture = ExtResource("1_lljyg")

[node name="Books1" type="Sprite2D" parent="."]
position = Vector2(-2, -47)
texture = ExtResource("2_ej8sk")

[node name="Books3" type="Sprite2D" parent="."]
position = Vector2(-7, -73)
texture = ExtResource("2_ej8sk")

[node name="Books4" type="Sprite2D" parent="."]
position = Vector2(-1, -94)
texture = ExtResource("2_ej8sk")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = -1.5707964
shape = SubResource("CapsuleShape2D_grfk2")

[node name="HookableArea" type="Area2D" parent="." node_paths=PackedStringArray("controlled_entity")]
collision_layer = 4096
collision_mask = 0
script = ExtResource("3_ej8sk")
controlled_entity = NodePath("..")
weight = 0.0
metadata/_custom_type_script = "uid://dabvr3pqmyya4"

[node name="CollisionShape2D" type="CollisionShape2D" parent="HookableArea"]
position = Vector2(0, -51)
shape = SubResource("RectangleShape2D_5vg6g")
debug_color = Color(0.689707, 0.288376, 1, 0.42)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=4 uid="uid://ce7nk8qmi64d2"]
[gd_scene load_steps=27 format=4 uid="uid://ce7nk8qmi64d2"]

[ext_resource type="PackedScene" uid="uid://cfcgrfvtn04yp" path="res://scenes/ui_elements/hud/hud.tscn" id="1_5a8rg"]
[ext_resource type="TileSet" uid="uid://07fq3rspk8ia" path="res://scenes/tileset.tres" id="1_d6l2m"]
Expand All @@ -13,6 +13,7 @@
[ext_resource type="PackedScene" uid="uid://evb46lm6ssu2" path="res://scenes/game_elements/props/hookable_pin/hookable_pin.tscn" id="6_kmyoj"]
[ext_resource type="PackedScene" uid="uid://cokul8w425pja" path="res://scenes/quests/lore_quests/quest_002/1_void_runner/components/void_spreading_enemy.tscn" id="6_m0g5h"]
[ext_resource type="Script" uid="uid://csev4hv57utxv" path="res://scenes/game_logic/walk_behaviors/character_speeds.gd" id="8_c2723"]
[ext_resource type="PackedScene" uid="uid://ktjtnp64e63v" path="res://scenes/quests/lore_quests/quest_002/3_void_grappling/components/books_pile.tscn" id="10_g4kbc"]
[ext_resource type="PackedScene" uid="uid://7873qa54birk" path="res://scenes/game_elements/props/tree/tree.tscn" id="12_wgn4u"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_wgn4u"]
Expand Down Expand Up @@ -291,11 +292,11 @@ position = Vector2(1062, -262.00003)
scale = Vector2(1.22224, 1.15899)

[node name="Tree7" parent="OnTheGround/Props" instance=ExtResource("12_wgn4u")]
position = Vector2(1189, -997)
position = Vector2(980.00006, -1018)
scale = Vector2(1.22224, 1.15899)

[node name="Tree8" parent="OnTheGround/Props" instance=ExtResource("12_wgn4u")]
position = Vector2(421.00003, -1445)
position = Vector2(401, -1457.0001)
scale = Vector2(1.22224, 1.15899)

[node name="Tree5" parent="OnTheGround/Props" instance=ExtResource("12_wgn4u")]
Expand All @@ -306,6 +307,15 @@ scale = Vector2(1.22224, 1.15899)
position = Vector2(1256, -363)
scale = Vector2(1.22224, 1.15899)

[node name="BooksPile" parent="OnTheGround/Props" instance=ExtResource("10_g4kbc")]
position = Vector2(1158, -860)

[node name="BooksPile2" parent="OnTheGround/Props" instance=ExtResource("10_g4kbc")]
position = Vector2(891, -1496)

[node name="BooksPile3" parent="OnTheGround/Props" instance=ExtResource("10_g4kbc")]
position = Vector2(1954, -606)

[node name="CollectibleItem" parent="OnTheGround" instance=ExtResource("4_jrfsf")]
position = Vector2(2693, -483)
next_scene = "uid://cufkthb25mpxy"
Expand Down