mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2024-11-15 05:25:57 +00:00
Snap only when on board
- snaps only when placed on board - Returns to original position if it isn't
This commit is contained in:
parent
448f3a0262
commit
df1c43bb0d
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=10 format=2]
|
||||
[gd_scene load_steps=9 format=2]
|
||||
|
||||
[ext_resource path="res://assets/game/board_blue.png" type="Texture" id=1]
|
||||
[ext_resource path="res://script/title screen/Title-Screen-Background.png" type="Texture" id=2]
|
||||
@ -9,9 +9,6 @@
|
||||
[ext_resource path="res://scenes/ships/3shipA.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://scenes/ships/4Ship.tscn" type="PackedScene" id=8]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 7.27765, 175.36 )
|
||||
|
||||
[node name="Game" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.889
|
||||
@ -72,41 +69,33 @@ __meta__ = {
|
||||
|
||||
[node name="2Ship" parent="." instance=ExtResource( 4 )]
|
||||
position = Vector2( 529.802, 70.7151 )
|
||||
collision_layer = 3
|
||||
contacts_reported = 1
|
||||
contact_monitor = true
|
||||
|
||||
[node name="3ShipA" parent="." instance=ExtResource( 7 )]
|
||||
position = Vector2( 434.236, 114.21 )
|
||||
collision_layer = 3
|
||||
contacts_reported = 1
|
||||
contact_monitor = true
|
||||
|
||||
[node name="3ShipB" parent="." instance=ExtResource( 6 )]
|
||||
position = Vector2( 443.216, 266.865 )
|
||||
collision_layer = 3
|
||||
contacts_reported = 1
|
||||
contact_monitor = true
|
||||
|
||||
[node name="4Ship" parent="." instance=ExtResource( 8 )]
|
||||
position = Vector2( 522.911, 218.599 )
|
||||
collision_layer = 3
|
||||
contacts_reported = 1
|
||||
contact_monitor = true
|
||||
|
||||
[node name="5Ship" parent="." instance=ExtResource( 5 )]
|
||||
position = Vector2( 607.096, 211.864 )
|
||||
|
||||
[node name="Borders" type="Area2D" parent="."]
|
||||
position = Vector2( 8.87946, 176.974 )
|
||||
gravity_vec = Vector2( 0, 0 )
|
||||
gravity = 0.0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Borders"]
|
||||
shape = SubResource( 1 )
|
||||
one_way_collision_margin = 0.0
|
||||
|
||||
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Borders"]
|
||||
position = Vector2( 343, 0 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D3" type="CollisionShape2D" parent="Borders"]
|
||||
position = Vector2( 171.26, -168.324 )
|
||||
rotation = 1.5708
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D4" type="CollisionShape2D" parent="Borders"]
|
||||
position = Vector2( 171.26, 173.677 )
|
||||
rotation = 1.5708
|
||||
shape = SubResource( 1 )
|
||||
collision_layer = 3
|
||||
contacts_reported = 1
|
||||
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"]
|
||||
|
18
godot_ship/script/game/Border.gd
Normal file
18
godot_ship/script/game/Border.gd
Normal file
@ -0,0 +1,18 @@
|
||||
extends Area2D
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func _on_Border_body_entered(body):
|
||||
print(body)
|
@ -5,11 +5,12 @@ extends RigidBody2D
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
var held = false
|
||||
|
||||
var originalPos
|
||||
var snapOriginalPos = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
pass
|
||||
|
||||
var click_radius = 16
|
||||
var orient = 0;
|
||||
@ -22,9 +23,16 @@ func _input(event):
|
||||
|
||||
if held and not event.pressed:
|
||||
held = false;
|
||||
position = position.snapped(Vector2(32, 32)) + Vector2(2, 2)
|
||||
if (position.x > 17.4 and position.x < 337.5) and (position.y > 20.2 and position.y < 335.5):
|
||||
position = position.snapped(Vector2(32, 32)) + Vector2(2, 2)
|
||||
else:
|
||||
position = originalPos
|
||||
|
||||
|
||||
if event is InputEventMouseMotion and held:
|
||||
if snapOriginalPos == false:
|
||||
originalPos = position
|
||||
snapOriginalPos = true
|
||||
position = event.position;
|
||||
|
||||
if event.is_action_pressed("ui_rotate"):
|
||||
@ -45,3 +53,4 @@ func drop(impulse=Vector2.ZERO):
|
||||
mode = RigidBody2D.MODE_RIGID
|
||||
apply_central_impulse(impulse)
|
||||
held = false
|
||||
snapOriginalPos = false
|
||||
|
Loading…
Reference in New Issue
Block a user