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.
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,44 @@ 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 []


## 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]

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))
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


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


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
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: The Threadbare Authors
# SPDX-License-Identifier: MPL-2.0
extends Node2D


func _ready() -> void:
visible = false
process_mode = Node.PROCESS_MODE_DISABLED


func appear() -> void:
visible = true
process_mode = Node.PROCESS_MODE_INHERIT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://be84u27t0yhj2
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=29 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,9 @@
[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="Script" uid="uid://be84u27t0yhj2" path="res://scenes/quests/lore_quests/quest_002/3_void_grappling/components/return_needles.gd" id="11_ayr6d"]
[ext_resource type="PackedScene" uid="uid://dohb701lxbe5s" path="res://scenes/game_elements/props/hookable_needle/hookable_needle.tscn" id="11_grfk2"]
[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 @@ -62,9 +65,9 @@ _data = {
point_count = 5

[sub_resource type="NavigationPolygon" id="NavigationPolygon_c2723"]
vertices = PackedVector2Array(953, 1726.7969, -135, 1726.9922, -135, 147, 2149, 147, 2149, 1727, 1061, 1727, 953, 1869.1406, 1061, 1868.5078, 1322.1875, 2195, 5733, 2195, 5733, 2303, 1318.7969, 2303, 1254.7969, 2623, 886.8125, 2623, 825, 2375.7734, 825, 1997.1406)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(0, 3, 4, 5), PackedInt32Array(6, 0, 5, 7), PackedInt32Array(8, 9, 10, 11), PackedInt32Array(7, 8, 11, 12, 13, 14, 15, 6)])
outlines = Array[PackedVector2Array]([PackedVector2Array(815, 1993, 943, 1865, 943.00006, 1736.8054, -145, 1737, -145, 137, 2159, 137, 2159, 1737, 1071, 1737, 1071, 1865, 1327, 2185, 5743, 2185, 5743, 2313, 1327, 2313, 1263, 2633, 879, 2633, 815, 2377)])
vertices = PackedVector2Array(953, 1726.7969, -135, 1726.9922, -135, 147, 2149, 147, 2149, 1727, 1061, 1727, 953, 1869.1406, 1061, 1866.6172, 825, 2371.6406, 825, 1997.1406, 1126.6016, 2063.4219, 1010.03125, 2495, 1193.6484, 2495, 1317, 2190.3516, 1317, 2309.9688)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(0, 3, 4, 5), PackedInt32Array(6, 0, 5, 7), PackedInt32Array(8, 9, 6, 7, 10, 11), PackedInt32Array(12, 11, 10, 13, 14)])
outlines = Array[PackedVector2Array]([PackedVector2Array(815, 1993, 943, 1865, 943.00006, 1736.8054, -145, 1737, -145, 137, 2159, 137, 2159, 1737, 1071, 1737, 1071, 1865, 1135, 2057, 1327, 2185, 1327, 2313, 1199, 2505, 1007, 2505, 815, 2377)])

[node name="VoidGrappling" type="Node2D"]
metadata/_edit_lock_ = true
Expand Down Expand Up @@ -291,11 +294,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 +309,62 @@ 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="ReturnNeedles" type="Node2D" parent="OnTheGround"]
unique_name_in_owner = true
y_sort_enabled = true
script = ExtResource("11_ayr6d")

[node name="HookableNeedle" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(2288, -560)

[node name="HookableNeedle2" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(2128, -560)

[node name="HookableNeedle3" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1984, -704)

[node name="HookableNeedle4" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1808, -720)

[node name="HookableNeedle5" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1656, -616)

[node name="HookableNeedle6" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1496, -488)

[node name="HookableNeedle7" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1312, -496)

[node name="HookableNeedle8" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1167, -398)

[node name="HookableNeedle9" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1280, -208)

[node name="HookableNeedle10" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1408, -112)

[node name="HookableNeedle11" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1172, -287)

[node name="HookableNeedle12" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1504, 0)

[node name="HookableNeedle13" parent="OnTheGround/ReturnNeedles" instance=ExtResource("11_grfk2")]
position = Vector2(1496, 104)

[node name="HookablePin9" parent="OnTheGround/ReturnNeedles" instance=ExtResource("6_kmyoj")]
position = Vector2(1504, 208)

[node name="CollectibleItem" parent="OnTheGround" instance=ExtResource("4_jrfsf")]
position = Vector2(2693, -483)
next_scene = "uid://cufkthb25mpxy"
Expand Down Expand Up @@ -358,6 +417,7 @@ metadata/_edit_lock_ = true
metadata/_edit_group_ = true

[connection signal="body_entered" from="EnemyChaseTrigger" to="OnTheGround/VoidChasing" method="start"]
[connection signal="body_entered" from="EnemyDefeatTrigger" to="OnTheGround/ReturnNeedles" method="appear" unbinds=1]
[connection signal="body_entered" from="EnemyDefeatTrigger" to="OnTheGround/VoidChasing" method="defeat" unbinds=1]
[connection signal="body_entered" from="SwitchModeArea" to="SwitchModeArea" method="_on_body_entered"]
[connection signal="body_exited" from="SwitchModeArea" to="SwitchModeArea" method="_on_body_exited"]
Expand Down