-
Notifications
You must be signed in to change notification settings - Fork 202
Make Void slow down while consuming piles of books #1393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ## 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] | ||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above I think you can spell this as:
Suggested change
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could connect to the tween's finish function just once with: and change its implementation to have a |
||||||||||||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| func _emit_particles() -> void: | ||||||||||||||||||||||||||||||
| _time_since_emit = 0 | ||||||||||||||||||||||||||||||
| _distance_since_emit = 0 | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| var particles: GPUParticles2D = VOID_PARTICLES.instantiate() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| 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) |
There was a problem hiding this comment.
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:
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.