Comets.gd/scripts/ship.gd

28 lines
817 B
GDScript3
Raw Normal View History

2024-05-09 22:42:55 -04:00
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
2024-05-09 22:42:55 -04:00
$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: