mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2025-02-04 12:28:35 +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:
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
|
||||
|
||||
Reference in New Issue
Block a user