From 9ecf401efa633c47599b3f8e892be5161c959632 Mon Sep 17 00:00:00 2001 From: Chance Atkinson Date: Thu, 11 Nov 2021 20:36:58 -0600 Subject: [PATCH] Collision is bad Tried working on the collision when placing ships, they are cramming when held on top of each other and are not returning to starting position when they are supposed to. --- godot_ship/scenes/Gameplay.tscn | 5 +++++ godot_ship/scenes/ships/2Ship.tscn | 9 ++++++++- godot_ship/scenes/ships/3ShipB.tscn | 6 ++++++ godot_ship/scenes/ships/3shipA.tscn | 6 ++++++ godot_ship/scenes/ships/4Ship.tscn | 7 +++++++ godot_ship/scenes/ships/5Ship.tscn | 6 ++++++ godot_ship/script/game/Gameplay.gd | 27 +++++++++++++++++++++++++++ godot_ship/script/game/moveShip.gd | 19 ++++++++++++++++--- 8 files changed, 81 insertions(+), 4 deletions(-) diff --git a/godot_ship/scenes/Gameplay.tscn b/godot_ship/scenes/Gameplay.tscn index b820cb7..c9f727e 100644 --- a/godot_ship/scenes/Gameplay.tscn +++ b/godot_ship/scenes/Gameplay.tscn @@ -99,3 +99,8 @@ contact_monitor = true [connection signal="pressed" from="VBoxContainer/Forfeit" to="." method="_on_Forfeit_pressed"] [connection signal="about_to_show" from="ConfirmationDialog" to="." method="_on_ConfirmationDialog_about_to_show"] +[connection signal="body_entered" from="2Ship" to="." method="_on_2Ship_body_entered"] +[connection signal="body_entered" from="3ShipA" to="." method="_on_3ShipA_body_entered"] +[connection signal="body_entered" from="3ShipB" to="." method="_on_3ShipB_body_entered"] +[connection signal="body_entered" from="4Ship" to="." method="_on_4Ship_body_entered"] +[connection signal="body_entered" from="5Ship" to="." method="_on_5Ship_body_entered"] diff --git a/godot_ship/scenes/ships/2Ship.tscn b/godot_ship/scenes/ships/2Ship.tscn index 8647965..9b64cc0 100644 --- a/godot_ship/scenes/ships/2Ship.tscn +++ b/godot_ship/scenes/ships/2Ship.tscn @@ -8,6 +8,7 @@ extents = Vector2( 16, 32 ) [node name="2Ship" type="RigidBody2D"] input_pickable = true +gravity_scale = 0.0 custom_integrator = true script = ExtResource( 1 ) @@ -16,5 +17,11 @@ position = Vector2( 0, 16 ) texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] -position = Vector2( 0, 16.25 ) +position = Vector2( 0.125, 16 ) +shape = SubResource( 1 ) + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2( 0.125, 16 ) shape = SubResource( 1 ) diff --git a/godot_ship/scenes/ships/3ShipB.tscn b/godot_ship/scenes/ships/3ShipB.tscn index 6317e99..bcbc759 100644 --- a/godot_ship/scenes/ships/3ShipB.tscn +++ b/godot_ship/scenes/ships/3ShipB.tscn @@ -8,6 +8,7 @@ extents = Vector2( 16, 48 ) [node name="3ShipB" type="RigidBody2D"] input_pickable = true +gravity_scale = 0.0 custom_integrator = true script = ExtResource( 1 ) @@ -16,3 +17,8 @@ texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource( 1 ) diff --git a/godot_ship/scenes/ships/3shipA.tscn b/godot_ship/scenes/ships/3shipA.tscn index c0d40b5..6e5da1b 100644 --- a/godot_ship/scenes/ships/3shipA.tscn +++ b/godot_ship/scenes/ships/3shipA.tscn @@ -8,6 +8,7 @@ extents = Vector2( 16, 48 ) [node name="3ShipA" type="RigidBody2D"] input_pickable = true +gravity_scale = 0.0 custom_integrator = true script = ExtResource( 1 ) @@ -16,3 +17,8 @@ texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 1 ) + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource( 1 ) diff --git a/godot_ship/scenes/ships/4Ship.tscn b/godot_ship/scenes/ships/4Ship.tscn index b4e7b7f..18f3a4d 100644 --- a/godot_ship/scenes/ships/4Ship.tscn +++ b/godot_ship/scenes/ships/4Ship.tscn @@ -8,6 +8,7 @@ extents = Vector2( 16, 64 ) [node name="4Ship" type="RigidBody2D"] input_pickable = true +gravity_scale = 0.0 custom_integrator = true script = ExtResource( 1 ) @@ -18,3 +19,9 @@ texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2( 1, 15 ) shape = SubResource( 1 ) + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2( 1, 15 ) +shape = SubResource( 1 ) diff --git a/godot_ship/scenes/ships/5Ship.tscn b/godot_ship/scenes/ships/5Ship.tscn index 137db4a..a599393 100644 --- a/godot_ship/scenes/ships/5Ship.tscn +++ b/godot_ship/scenes/ships/5Ship.tscn @@ -15,4 +15,10 @@ script = ExtResource( 1 ) texture = ExtResource( 2 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] +visible = false +shape = SubResource( 1 ) + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource( 1 ) diff --git a/godot_ship/script/game/Gameplay.gd b/godot_ship/script/game/Gameplay.gd index 2ff36b6..573a793 100644 --- a/godot_ship/script/game/Gameplay.gd +++ b/godot_ship/script/game/Gameplay.gd @@ -1,5 +1,10 @@ extends Control +signal two_ship_collide +signal three_shipA_collide +signal three_shipB_collide +signal four_ship_collide +signal five_ship_collide # Declare member variables here. Examples: # var a = 2 @@ -19,3 +24,25 @@ func _on_Forfeit_pressed(): AudioBus.emit_signal("button_clicked") queue_free(); MessageBus.emit_signal("change_scene", "Title") + + +func _on_2Ship_body_entered(body): + var _errno = emit_signal("two_ship_collide", "2Ship") + print("Emitting two_ship_collide") + +func _on_3ShipA_body_entered(body): + emit_signal("three_shipA_collide", "3ShipA") + print("Emitting three_shipA_collide") + +func _on_3ShipB_body_entered(body): + emit_signal("three_shipB_collide", "3ShipA") + print("Emitting three_shipB_collide") + +func _on_4Ship_body_entered(body): + emit_signal("four_ship_collide", "4Ship") + print("Emitting four_ship_collide") + +func _on_5Ship_body_entered(body): + emit_signal("five_ship_collide", "5Ship") + print("Emitting five_ship_collide") + diff --git a/godot_ship/script/game/moveShip.gd b/godot_ship/script/game/moveShip.gd index a64aba7..1e03052 100644 --- a/godot_ship/script/game/moveShip.gd +++ b/godot_ship/script/game/moveShip.gd @@ -12,7 +12,12 @@ var startingPos # Called when the node enters the scene tree for the first time. func _ready(): startingPos = position - pass + var _errno = 0 + _errno = find_parent("Game").connect("two_ship_collide", self, "if_ship_stacked") + _errno = find_parent("Game").connect("three_shipA_collide", self, "if_ship_stacked") + _errno = find_parent("Game").connect("three_shipB_collide", self, "if_ship_stacked") + _errno = find_parent("Game").connect("four_ship_collide", self, "if_ship_stacked") + _errno = find_parent("Game").connect("five_ship_collide", self, "if_ship_stacked") var click_radius = 16 var orient = 0; @@ -113,10 +118,10 @@ func _input(event): return elif(event.position - position).length() < click_radius: if vertical == true: - rotate(-PI/2) + rotation = (-PI/2) vertical = false else: - rotate(PI/2) + rotation = 0 vertical = true if(position.x > 17.4 and position.x < 335.5) and (position.y > 20.2 and position.y < 335.5): @@ -213,3 +218,11 @@ func checkOriginalPos(): return true else: return false + +func if_ship_stacked(ship): + if !held && ship == name: + position = startingPos + rotation = 0 + print("we colliding over here") + return +