mirror of
https://codeberg.org/Melon-Bread/Comets.gd.git
synced 2024-11-24 21:18:21 -05:00
28 lines
817 B
GDScript
28 lines
817 B
GDScript
extends Area2D
|
|
|
|
@export var max_speed := 1200.0
|
|
@export var steering_factor := 3.0
|
|
|
|
var velocity := Vector2.ZERO
|
|
|
|
func _process(delta: float) -> void:
|
|
# TODO: Maybe look into tank controls like classic Astroids
|
|
var direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
|
if direction.length() > 1.0:
|
|
direction.normalized()
|
|
|
|
var desired_velocity := max_speed * direction
|
|
var steering := desired_velocity - velocity
|
|
velocity += steering * steering_factor * delta
|
|
position += velocity * delta
|
|
|
|
if velocity.length() > 0.0:
|
|
# TODO: Have the CollisionShape toate with the sprite
|
|
$Sprite2D.rotation = velocity.angle()
|
|
|
|
var viewport_size := get_viewport_rect().size
|
|
position.x = wrap(position.x, 0, viewport_size.x)
|
|
position.y = wrap(position.y, 0,viewport_size.y)
|
|
|
|
func fire_gun() -> void:
|