1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 05:25:57 +00:00

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.
This commit is contained in:
Chance Atkinson 2021-11-11 20:36:58 -06:00
parent 3ef450a80a
commit 9ecf401efa
8 changed files with 81 additions and 4 deletions

View File

@ -99,3 +99,8 @@ contact_monitor = true
[connection signal="pressed" from="VBoxContainer/Forfeit" to="." method="_on_Forfeit_pressed"] [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="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"]

View File

@ -8,6 +8,7 @@ extents = Vector2( 16, 32 )
[node name="2Ship" type="RigidBody2D"] [node name="2Ship" type="RigidBody2D"]
input_pickable = true input_pickable = true
gravity_scale = 0.0
custom_integrator = true custom_integrator = true
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -16,5 +17,11 @@ position = Vector2( 0, 16 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [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 ) shape = SubResource( 1 )

View File

@ -8,6 +8,7 @@ extents = Vector2( 16, 48 )
[node name="3ShipB" type="RigidBody2D"] [node name="3ShipB" type="RigidBody2D"]
input_pickable = true input_pickable = true
gravity_scale = 0.0
custom_integrator = true custom_integrator = true
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -16,3 +17,8 @@ texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 1 )

View File

@ -8,6 +8,7 @@ extents = Vector2( 16, 48 )
[node name="3ShipA" type="RigidBody2D"] [node name="3ShipA" type="RigidBody2D"]
input_pickable = true input_pickable = true
gravity_scale = 0.0
custom_integrator = true custom_integrator = true
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -16,3 +17,8 @@ texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 1 )

View File

@ -8,6 +8,7 @@ extents = Vector2( 16, 64 )
[node name="4Ship" type="RigidBody2D"] [node name="4Ship" type="RigidBody2D"]
input_pickable = true input_pickable = true
gravity_scale = 0.0
custom_integrator = true custom_integrator = true
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -18,3 +19,9 @@ texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 1, 15 ) position = Vector2( 1, 15 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 1, 15 )
shape = SubResource( 1 )

View File

@ -15,4 +15,10 @@ script = ExtResource( 1 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [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 ) shape = SubResource( 1 )

View File

@ -1,5 +1,10 @@
extends Control 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: # Declare member variables here. Examples:
# var a = 2 # var a = 2
@ -19,3 +24,25 @@ func _on_Forfeit_pressed():
AudioBus.emit_signal("button_clicked") AudioBus.emit_signal("button_clicked")
queue_free(); queue_free();
MessageBus.emit_signal("change_scene", "Title") 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")

View File

@ -12,7 +12,12 @@ var startingPos
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
startingPos = position 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 click_radius = 16
var orient = 0; var orient = 0;
@ -113,10 +118,10 @@ func _input(event):
return return
elif(event.position - position).length() < click_radius: elif(event.position - position).length() < click_radius:
if vertical == true: if vertical == true:
rotate(-PI/2) rotation = (-PI/2)
vertical = false vertical = false
else: else:
rotate(PI/2) rotation = 0
vertical = true vertical = true
if(position.x > 17.4 and position.x < 335.5) and (position.y > 20.2 and position.y < 335.5): 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 return true
else: else:
return false return false
func if_ship_stacked(ship):
if !held && ship == name:
position = startingPos
rotation = 0
print("we colliding over here")
return