extends CharacterBody2D @export var acceleration: float = 400.0 @export var max_speed: float = 1500.0 @export var rotation_speed: float = 3.0 @export var friction: float = 0.99 signal fire # Signal to start firing signal stop_fire # Signal to stop firing var weapons_system func _ready(): weapons_system = $WeaponsSystem func get_spaceship_orientation_vector() -> Vector2: return -global_transform.y func handle_movement(delta: float) -> void: var thrust = Vector2.ZERO if Input.is_action_pressed("ui_up"): thrust = Vector2(0, -1).rotated(rotation) * acceleration * delta velocity += thrust if Input.is_action_pressed("ui_down"): thrust = Vector2(0, 1).rotated(rotation) * acceleration * delta velocity += thrust if Input.is_action_pressed("ui_left"): rotation -= rotation_speed * delta if Input.is_action_pressed("ui_right"): rotation += rotation_speed * delta # Clamp velocity and apply friction velocity = velocity.clamp(Vector2(-max_speed, -max_speed), Vector2(max_speed, max_speed)) velocity *= friction var collision = move_and_collide(velocity * delta) if collision: print("Collided with: ", collision.get_collider().name) var collision_normal = collision.get_normal() velocity = velocity.slide(collision_normal) func handle_weapons_input() -> void: if Input.is_action_pressed("ui_fire"): weapons_system.fire_all() if Input.is_action_just_released("ui_fire"): weapons_system.cease_fire_all() func _process(delta: float) -> void: handle_movement(delta) handle_weapons_input()