1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2025-02-04 12:28:35 +00:00

Improve menuing, and convert ships to RigidBody2D for accurate positioning.

This commit is contained in:
2021-10-21 01:24:27 -05:00
parent e9040293ae
commit 0fd0fa63f0
14 changed files with 153 additions and 58 deletions

View File

@@ -1,29 +1,30 @@
extends Sprite
extends RigidBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var held = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
var dragging = false;
var click_radius = 32
var orient = 0;
func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if(event.position - position).length() < click_radius:
if not dragging and event.pressed:
dragging = true;
if (event.position - position).length() < click_radius:
if not held and event.pressed:
held = true;
if dragging and not event.pressed:
dragging = false;
if held and not event.pressed:
held = false;
position = position.snapped(Vector2(32, 32)) + Vector2(2, 2)
if event is InputEventMouseMotion and dragging:
if event is InputEventMouseMotion and held:
position = event.position;
if event.is_action_pressed("ui_rotate"):
@@ -32,3 +33,15 @@ func _input(event):
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func pickup():
if held:
return
mode = RigidBody2D.MODE_STATIC
held = true
func drop(impulse=Vector2.ZERO):
if held:
mode = RigidBody2D.MODE_RIGID
apply_central_impulse(impulse)
held = false