From d710219cfdf9358d7e3f7a34871e482885ee547f Mon Sep 17 00:00:00 2001 From: Jakob Feldmann Date: Tue, 3 Jan 2023 19:23:45 +0100 Subject: [PATCH] New BoundFrog scene manages rope + frog --- src/Actors/Enemies/Beings/BoundFrog.gd | 17 +++++++---- src/Actors/Enemies/Beings/BoundFrog.tscn | 4 ++- src/Actors/Enemies/Beings/WhatAreFrog.gd | 15 ++++------ src/Actors/Enemies/Beings/WhatAreFrog.tscn | 14 +++++++--- .../Enemies/Beings/WhatAreFrogStateMachine.gd | 7 +++-- src/Contraptions/Rope/Rope.gd | 28 ++++++++----------- src/Contraptions/Rope/RopeAnchor.tscn | 4 +-- src/Contraptions/Rope/RopePiece.tscn | 2 +- src/Levels/The Line Level.gd | 12 +++++--- src/Levels/The Line Level.tscn | 16 ++++------- 10 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/Actors/Enemies/Beings/BoundFrog.gd b/src/Actors/Enemies/Beings/BoundFrog.gd index db8af3b..ab9ef38 100644 --- a/src/Actors/Enemies/Beings/BoundFrog.gd +++ b/src/Actors/Enemies/Beings/BoundFrog.gd @@ -1,13 +1,18 @@ extends Node2D -var Rope = preload("res://src/Contraptions/Rope/Rope.tscn") +var Rope = preload("res://src/Contraptions/Rope/Rope.tscn") var start_pos := Vector2.ZERO var end_pos := Vector2.ZERO -onready var rope: Node2D = null func _ready() -> void: - rope = Rope.instance() - add_child(rope) - rope.spawn_rope($AnchorPos.global_position, Vector2($AnchorPos.global_position.x + 200, $AnchorPos.global_position.y)) - rope.end_attached_node = $WhatAreFrog1 + pass + +func _on_LevelTemplate_ready() -> void: + var rope = Rope.instance() + get_parent().add_child(rope) + rope.rope_end = get_node("RopeAnchor") + rope.rope_start = get_node("WhatAreFrog") + rope.rope_end_joint = get_node("RopeAnchor/cshape/pjoint") + rope.rope_start_joint = get_node("WhatAreFrog/cshape/pjoint") + rope.spawn_rope($RopeAnchor.global_position, $RopeAnchor.global_position, false) diff --git a/src/Actors/Enemies/Beings/BoundFrog.tscn b/src/Actors/Enemies/Beings/BoundFrog.tscn index c0dd02e..bae7898 100644 --- a/src/Actors/Enemies/Beings/BoundFrog.tscn +++ b/src/Actors/Enemies/Beings/BoundFrog.tscn @@ -10,4 +10,6 @@ script = ExtResource( 3 ) [node name="WhatAreFrog" parent="." instance=ExtResource( 1 )] [node name="RopeAnchor" parent="." instance=ExtResource( 2 )] -position = Vector2( -53, 10 ) +position = Vector2( -136, 11 ) + +[editable path="RopeAnchor"] diff --git a/src/Actors/Enemies/Beings/WhatAreFrog.gd b/src/Actors/Enemies/Beings/WhatAreFrog.gd index acbd6f1..88e7241 100644 --- a/src/Actors/Enemies/Beings/WhatAreFrog.gd +++ b/src/Actors/Enemies/Beings/WhatAreFrog.gd @@ -7,19 +7,15 @@ onready var orientation: RayCast2D = $Orientation onready var jump_timer: Timer export var score := 100 -export var chain_length := 100 -export var chained := true var start_x = 0 var in_air = false +var died = false func _ready(): jump_timer = Timer.new() jump_timer.connect("timeout", self, "jump") add_child(jump_timer) - if chained: - pass - # TODO adapt to groups # TODO Engine error here(what does it WANT???) @@ -33,7 +29,7 @@ func execute_movement(delta: float) -> void: velocity.y += _gravity * delta if sign(velocity.x) != orientation.cast_to.x: velocity.x *= -1 - velocity = move_and_slide(velocity, FLOOR_NORMAL) + velocity = move_and_slide(velocity, FLOOR_NORMAL, false, 4, 0.785398,false) if(is_on_floor()): velocity = Vector2(0,0) if ($Left_Wallcast.is_colliding() || $Right_Wallcast.is_colliding()) && is_on_floor(): @@ -41,8 +37,10 @@ func execute_movement(delta: float) -> void: func die() -> void: - queue_free() - GlobalState.score += score + if(!died): + GlobalState.score += score + died = true + #queue_free() func _on_EnemySkin_area_entered(area:Area2D) -> void: @@ -50,7 +48,6 @@ func _on_EnemySkin_area_entered(area:Area2D) -> void: get_node("EnemyBody").disabled = true die() - func searching() -> Vector2: if(is_on_floor()): if(jump_timer.is_stopped()): diff --git a/src/Actors/Enemies/Beings/WhatAreFrog.tscn b/src/Actors/Enemies/Beings/WhatAreFrog.tscn index 58ff7f8..5183bbd 100644 --- a/src/Actors/Enemies/Beings/WhatAreFrog.tscn +++ b/src/Actors/Enemies/Beings/WhatAreFrog.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://assets/enemy/enemy.png" type="Texture" id=1] [ext_resource path="res://src/Actors/Enemies/Beings/WhatAreFrog.gd" type="Script" id=2] [ext_resource path="res://src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd" type="Script" id=3] -[ext_resource path="res://src/Contraptions/Rope/RopeAnchor.tscn" type="PackedScene" id=4] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 2.72463, 1.17848 ) @@ -62,6 +61,15 @@ position = Vector2( 0, 6.48802 ) scale = Vector2( 5.68128, 5.29182 ) shape = SubResource( 1 ) +[node name="cshape" type="Node2D" parent="."] +position = Vector2( 0, -3.8147e-06 ) +scale = Vector2( 0.1, 0.1 ) + +[node name="pjoint" type="PinJoint2D" parent="cshape"] +scale = Vector2( 0.3, 0.3 ) +bias = 0.9 +softness = 0.1 + [node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]] modulate = Color( 0, 0.0392157, 1, 1 ) position = Vector2( 0, -6.44095 ) @@ -80,7 +88,5 @@ position = Vector2( 5.96046e-07, 2.5 ) scale = Vector2( 1.03, 1.04 ) shape = SubResource( 3 ) -[node name="RopeAnchor" parent="." instance=ExtResource( 4 )] - [connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"] [connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"] diff --git a/src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd b/src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd index 541bfa3..7110db4 100644 --- a/src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd +++ b/src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd @@ -19,9 +19,10 @@ func _ready() -> void: # Game logic consequences of state func _state_logic(delta): - var state_action_ref = funcref(parent, self.state) - parent.velocity = state_action_ref.call_func() - parent.execute_movement(delta) + if(!(parent.died && parent.is_on_floor())): + var state_action_ref = funcref(parent, self.state) + parent.velocity = state_action_ref.call_func() + parent.execute_movement(delta) func _get_transition(_delta): diff --git a/src/Contraptions/Rope/Rope.gd b/src/Contraptions/Rope/Rope.gd index d06b8fa..1a7a754 100644 --- a/src/Contraptions/Rope/Rope.gd +++ b/src/Contraptions/Rope/Rope.gd @@ -7,8 +7,6 @@ var rope_close_tolerance := 2.0 var rope_pieces := [] var rope_piece_positions : PoolVector2Array= [] -var end_attached_node: Node2D = null - export var mouse_follow := false onready var rope_start @@ -18,11 +16,6 @@ onready var rope_end_joint func _physics_process(_delta: float) -> void: #Resize or reinitialize? - if(end_attached_node != null): - if (!is_instance_valid(end_attached_node)): - rope_end.mode = RigidBody2D.MODE_RIGID - else: - rope_end.global_position = end_attached_node.global_position if(mouse_follow): rope_end.global_position = get_global_mouse_position() rope_piece_positions.resize(0) @@ -30,15 +23,16 @@ func _physics_process(_delta: float) -> void: if !rope_piece_positions.empty(): update() -func spawn_rope(start_pos: Vector2, end_pos: Vector2): - rope_start = RopeAnchor.instance() - rope_end = RopeAnchor.instance() - rope_start_joint = rope_start.get_node("cshape/pjoint") - rope_end_joint = rope_end.get_node("cshape/pjoint") - add_child(rope_start, true) - add_child(rope_end, true) - rope_start.global_position = start_pos - rope_end.global_position = end_pos +func spawn_rope(start_pos: Vector2, end_pos: Vector2, new_anchors: bool = true): + if(new_anchors): + rope_start = RopeAnchor.instance() + rope_end = RopeAnchor.instance() + rope_start_joint = rope_start.get_node("cshape/pjoint") + rope_end_joint = rope_end.get_node("cshape/pjoint") + add_child(rope_start, true) + add_child(rope_end, true) + rope_start.global_position = start_pos + rope_end.global_position = end_pos start_pos = rope_start_joint.global_position end_pos = rope_end_joint.global_position var dist = start_pos.distance_to(end_pos) @@ -84,4 +78,4 @@ func get_piece_positions() -> Array: return rope_points func _draw() -> void: - draw_polyline(rope_piece_positions, Color.blue, 2.0) + draw_polyline(rope_piece_positions, Color.blue, 1.2) diff --git a/src/Contraptions/Rope/RopeAnchor.tscn b/src/Contraptions/Rope/RopeAnchor.tscn index 53cd6ee..cc279ce 100644 --- a/src/Contraptions/Rope/RopeAnchor.tscn +++ b/src/Contraptions/Rope/RopeAnchor.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://assets/environment/blocks/approx build block.png" type="Texture" id=1] +[ext_resource path="res://assets/environment/blocks/random-innentile.png" type="Texture" id=1] [sub_resource type="CircleShape2D" id=5] radius = 2.0 @@ -23,5 +23,5 @@ bias = 0.1 softness = 0.1 [node name="Sprite" type="Sprite" parent="."] -scale = Vector2( 0.1875, 0.1875 ) +scale = Vector2( 0.25, 0.245353 ) texture = ExtResource( 1 ) diff --git a/src/Contraptions/Rope/RopePiece.tscn b/src/Contraptions/Rope/RopePiece.tscn index b33fbad..ad3ca4b 100644 --- a/src/Contraptions/Rope/RopePiece.tscn +++ b/src/Contraptions/Rope/RopePiece.tscn @@ -9,7 +9,7 @@ height = 1.0 [node name="RigidBody2D" type="RigidBody2D"] collision_layer = 256 collision_mask = 8 -gravity_scale = 3.0 +gravity_scale = 0.2 linear_damp = 1.0 angular_damp = 1.0 script = ExtResource( 1 ) diff --git a/src/Levels/The Line Level.gd b/src/Levels/The Line Level.gd index 79ecd76..36baf3b 100644 --- a/src/Levels/The Line Level.gd +++ b/src/Levels/The Line Level.gd @@ -6,10 +6,14 @@ var end_pos := Vector2.ZERO onready var rope: Node2D = null func _ready() -> void: - rope = Rope.instance() - add_child(rope) - rope.spawn_rope($AnchorPos.global_position, Vector2($AnchorPos.global_position.x + 200, $AnchorPos.global_position.y)) - rope.end_attached_node = $WhatAreFrog1 + pass + # rope = Rope.instance() + # add_child(rope) + # rope.rope_start = get_node("BoundFrog/RopeAnchor") + # rope.rope_end = get_node("BoundFrog/WhatAreFrog") + # rope.rope_start_joint = get_node("BoundFrog/RopeAnchor/cshape/pjoint") + # rope.rope_end_joint = get_node("BoundFrog/WhatAreFrog/cshape/pjoint") + # rope.spawn_rope($BoundFrog/RopeAnchor.global_position, $BoundFrog.global_position, false) func _input(event): if event is InputEventMouseButton && !event.is_pressed(): diff --git a/src/Levels/The Line Level.tscn b/src/Levels/The Line Level.tscn index fa28c4a..4a29907 100644 --- a/src/Levels/The Line Level.tscn +++ b/src/Levels/The Line Level.tscn @@ -11,7 +11,7 @@ [ext_resource path="res://src/UserInterface/UserInterface.tscn" type="PackedScene" id=9] [ext_resource path="res://src/Contraptions/Portal/Portal.tscn" type="PackedScene" id=10] [ext_resource path="res://src/Actors/BlobbyCam.tscn" type="PackedScene" id=11] -[ext_resource path="res://src/Actors/Enemies/Beings/WhatAreFrog.tscn" type="PackedScene" id=12] +[ext_resource path="res://src/Actors/Enemies/Beings/BoundFrog.tscn" type="PackedScene" id=12] [sub_resource type="AnimationNodeStateMachinePlayback" id=4] @@ -37,14 +37,6 @@ collision_mask = 8 format = 1 tile_data = PoolIntArray( 0, -1610612732, 0, 260, -1073741820, 0, 131070, -1610612733, 0, 131071, 1610612738, 0, 65536, 1610612738, 0, 65537, 1610612738, 0, 65538, 1610612738, 0, 65539, 1610612738, 0, 65540, 1610612738, 0, 65541, 1610612738, 0, 65542, 1610612738, 0, 65543, 1610612738, 0, 65544, 1610612738, 0, 65545, 1610612738, 0, 65546, 1610612738, 0, 65547, 1610612738, 0, 65548, 1610612738, 0, 65549, 1610612738, 0, 65550, 1610612738, 0, 65551, 1610612738, 0, 65552, 1610612738, 0, 65553, 1610612738, 0, 65554, 1610612738, 0, 65555, 1610612738, 0, 65556, 1610612738, 0, 65557, 1610612738, 0, 65558, 1610612738, 0, 65559, 1610612738, 0, 65560, 1610612738, 0, 65561, 1610612738, 0, 65562, 1610612738, 0, 65563, 1610612738, 0, 65564, 1610612738, 0, 65565, 1610612738, 0, 65566, -1610612733, 0, 65796, -1073741820, 0, 196606, -1610612734, 0, 131072, -1610612732, 0, 131102, -1073741822, 0, 131332, -1073741820, 0, 262142, -1610612734, 0, 196608, -1610612732, 0, 196638, -1073741822, 0, 196868, -1073741820, 0, 327678, -1610612734, 0, 262144, -1610612732, 0, 262174, -1073741822, 0, 262404, -1073741820, 0, 393214, -1610612734, 0, 327680, -1610612732, 0, 327710, -1073741822, 0, 327940, -1073741820, 0, 458750, -1610612734, 0, 393216, -1610612732, 0, 393246, -1073741822, 0, 393476, -1073741820, 0, 524286, -1610612734, 0, 458752, -1610612732, 0, 458782, -1073741822, 0, 459012, -1073741820, 0, 589822, -1610612734, 0, 524288, -1610612732, 0, 524318, -1073741822, 0, 524548, -1073741820, 0, 655358, -1610612734, 0, 589824, -1610612732, 0, 589854, -1073741822, 0, 590084, -1073741820, 0, 720894, -1610612734, 0, 655360, -1610612732, 0, 655390, -1073741822, 0, 655620, -1073741820, 0, 786430, -1610612734, 0, 720896, -1610612732, 0, 720926, -1073741822, 0, 721156, -1073741820, 0, 851966, -1610612734, 0, 786432, -1610612732, 0, 786462, -1073741822, 0, 786692, -1073741820, 0, 917502, -1610612734, 0, 851968, -1610612732, 0, 851998, -1073741822, 0, 852228, -1073741820, 0, 983038, -1610612733, 0, 983039, 2, 0, 917504, 2, 0, 917505, 2, 0, 917506, 2, 0, 917507, 2, 0, 917508, 2, 0, 917509, 2, 0, 917510, 2, 0, 917511, 2, 0, 917512, 2, 0, 917513, 2, 0, 917514, 2, 0, 917515, 2, 0, 917516, 2, 0, 917517, 2, 0, 917518, 2, 0, 917519, 2, 0, 917520, 2, 0, 917521, 2, 0, 917522, 2, 0, 917523, 2, 0, 917524, 2, 0, 917525, 2, 0, 917526, 2, 0, 917527, 2, 0, 917528, 2, 0, 917529, 2, 0, 917530, 2, 0, 917531, 2, 0, 917532, 2, 0, 917533, 2, 0, 917534, -1073741821, 0, 917535, 4, 0, 917536, 4, 0, 917538, 4, 0, 917539, 4, 0, 917540, 4, 0, 917541, 4, 0, 917542, 4, 0, 917543, 4, 0, 917544, 4, 0, 917545, 4, 0, 917546, 4, 0, 917547, 4, 0, 917548, 4, 0, 917549, 4, 0, 917550, 4, 0, 917551, 4, 0, 917552, 4, 0, 917553, 4, 0, 917554, 4, 0, 917555, 4, 0, 917556, 4, 0, 917557, 4, 0, 917558, 4, 0, 917559, 4, 0, 917560, 4, 0, 917561, 4, 0, 917562, 4, 0, 917563, 4, 0, 917564, 4, 0, 917565, 4, 0, 917566, 4, 0, 917567, 4, 0, 917568, 4, 0, 917569, 4, 0, 917570, 4, 0, 917571, 4, 0, 917572, 4, 0, 917573, 4, 0, 917574, 4, 0, 917575, 4, 0, 917576, 4, 0, 917577, 4, 0, 917578, 4, 0, 917579, 4, 0, 917580, 4, 0, 917581, 4, 0, 917582, 4, 0, 917583, 4, 0, 917584, 4, 0, 917585, 4, 0, 917586, 4, 0, 917587, 4, 0, 917588, 4, 0, 917589, 4, 0, 917590, 4, 0, 917591, 4, 0, 917592, 4, 0, 917593, 4, 0, 917594, 4, 0, 917595, 4, 0, 917596, 4, 0, 917597, 4, 0, 917598, 4, 0, 917599, 4, 0, 917600, 4, 0, 917601, 4, 0, 917602, 4, 0, 917603, 4, 0, 917604, 4, 0, 917605, 4, 0, 917606, 4, 0, 917607, 4, 0, 917608, 4, 0, 917609, 4, 0, 917610, 4, 0, 917611, 4, 0, 917612, 4, 0, 917613, 4, 0, 917614, 4, 0, 917615, 4, 0, 917616, 4, 0, 917617, 4, 0, 917618, 4, 0, 917619, 4, 0, 917620, 4, 0, 917621, 4, 0, 917622, 4, 0, 917623, 4, 0, 917624, 4, 0, 917625, 4, 0, 917626, 4, 0, 917627, 4, 0, 917628, 4, 0, 917629, 4, 0, 917630, 4, 0, 917631, 4, 0, 917632, 4, 0, 917633, 4, 0, 917634, 4, 0, 917635, 4, 0, 917636, 4, 0, 917637, 4, 0, 917638, 4, 0, 917639, 4, 0, 917640, 4, 0, 917641, 4, 0, 917642, 4, 0, 917643, 4, 0, 917644, 4, 0, 917645, 4, 0, 917646, 4, 0, 917647, 4, 0, 917648, 4, 0, 917649, 4, 0, 917650, 4, 0, 917651, 4, 0, 917652, 4, 0, 917653, 4, 0, 917654, 4, 0, 917655, 4, 0, 917656, 4, 0, 917657, 4, 0, 917658, 4, 0, 917659, 4, 0, 917660, 4, 0, 917661, 4, 0, 917662, 4, 0, 917663, 4, 0, 917664, 4, 0, 917665, 4, 0, 917666, 4, 0, 917667, 4, 0, 917668, 4, 0, 917669, 4, 0, 917670, 4, 0, 917671, 4, 0, 917672, 4, 0, 917673, 4, 0, 917674, 4, 0, 917675, 4, 0, 917676, 4, 0, 917677, 4, 0, 917678, 4, 0, 917679, 4, 0, 917680, 4, 0, 917681, 4, 0, 917682, 4, 0, 917683, 4, 0, 917684, 4, 0, 917685, 4, 0, 917686, 4, 0, 917687, 4, 0, 917688, 4, 0, 917689, 4, 0, 917690, 4, 0, 917691, 4, 0, 917692, 4, 0, 917693, 4, 0, 917694, 4, 0, 917695, 4, 0, 917696, 4, 0, 917697, 4, 0, 917698, 4, 0, 917699, 4, 0, 917700, 4, 0, 917701, 4, 0, 917702, 4, 0, 917703, 4, 0, 917704, 4, 0, 917705, 4, 0, 917706, 4, 0, 917707, 4, 0, 917708, 4, 0, 917709, 4, 0, 917710, 4, 0, 917711, 4, 0, 917712, 4, 0, 917713, 4, 0, 917714, 4, 0, 917715, 4, 0, 917716, 4, 0, 917717, 4, 0, 917718, 4, 0, 917719, 4, 0, 917720, 4, 0, 917721, 4, 0, 917722, 4, 0, 917723, 4, 0, 917724, 4, 0, 917725, 4, 0, 917726, 4, 0, 917727, 4, 0, 917728, 4, 0, 917729, 4, 0, 917730, 4, 0, 917731, 4, 0, 917732, 4, 0, 917733, 4, 0, 917734, 4, 0, 917735, 4, 0, 917736, 4, 0, 917737, 4, 0, 917738, 4, 0, 917739, 4, 0, 917740, 4, 0, 917741, 4, 0, 917742, 4, 0, 917743, 4, 0, 917744, 4, 0, 917745, 4, 0, 917746, 4, 0, 917747, 4, 0, 917748, 4, 0, 917749, 4, 0, 917750, 4, 0, 917751, 4, 0, 917752, 4, 0, 917753, 4, 0, 917754, 4, 0, 917755, 4, 0, 917756, 4, 0, 917757, 4, 0, 917758, 4, 0, 917759, 4, 0, 917760, 4, 0, 917761, 4, 0, 917762, 4, 0, 917763, 4, 0, 917764, 4, 0 ) -[node name="AnchorPos" type="Node2D" parent="."] -unique_name_in_owner = true -position = Vector2( 315, 331 ) - -[node name="CollarPos" type="Node2D" parent="."] -unique_name_in_owner = true -position = Vector2( 196, 323 ) - [node name="BlobbyCam" parent="." instance=ExtResource( 11 )] [node name="Blobby" parent="." instance=ExtResource( 4 )] @@ -55,8 +47,9 @@ scale = Vector2( 0.878906, 0.936025 ) [node name="AnimationTree" parent="Blobby/BlobbySprite" index="0"] parameters/playback = SubResource( 4 ) -[node name="WhatAreFrog1" parent="." instance=ExtResource( 12 )] -position = Vector2( 195, 322 ) +[node name="BoundFrog" parent="." instance=ExtResource( 12 )] +position = Vector2( 263, 323 ) +scale = Vector2( 0.878906, 0.936025 ) [node name="Collectibles" type="Node2D" parent="."] visible = false @@ -120,6 +113,7 @@ next_scene = ExtResource( 6 ) [node name="GameplaySignalManager" type="Node2D" parent="."] script = ExtResource( 1 ) +[connection signal="ready" from="." to="BoundFrog" method="_on_LevelTemplate_ready"] [connection signal="timeout" from="UserInterface/HUD/HUDOverlay/GetBackTimer/Timer" to="GameplaySignalManager" method="_on_Timer_timeout"] [connection signal="getback_timer_up" from="GameplaySignalManager" to="Blobby" method="_on_GameplaySignalManager_getback_timer_up"] [connection signal="terminal_activated" from="GameplaySignalManager" to="UserInterface/HUD" method="_on_SignalManager_terminal_activated"]