Fixed placeholder texture. Added correct ship movement

This commit is contained in:
2025-10-20 22:21:01 +03:00
parent be3db76fe2
commit c5f53b845a
5 changed files with 65 additions and 21 deletions
+36 -1
View File
@@ -1,9 +1,44 @@
extends Node2D
@export var size : Vector2
@export var size : Vector2:
set(value):
size = value
if $Sprite2D.texture:
$Sprite2D.texture.size = value
get:
return size
@export var acceleration : int
@export var deceleration : int
@export var max_speed : int
var _velocity : Vector2
func _ready() -> void:
var texture := PlaceholderTexture2D.new()
texture.size = size
$Sprite2D.texture = texture
func _process(delta: float) -> void:
position += _velocity * delta
func accelerate(value: Vector2) -> void:
_velocity += value
_velocity = _velocity.clamp(Vector2(-max_speed, -max_speed), Vector2(max_speed, max_speed))
func decelerate(value: float) -> void:
var current_speed := _velocity.length()
if current_speed <= 0:
_velocity = Vector2.ZERO
return
var new_speed := current_speed - value
if new_speed < 0:
new_speed = 0
_velocity = _velocity.normalized() * new_speed