42 lines
1.3 KiB
GDScript
42 lines
1.3 KiB
GDScript
class_name Player extends "res://scenes/spaceShip/spaceShip.gd"
|
|
|
|
@onready var dashCooldown = $dashCooldown
|
|
@onready var spawnPointPool = $spawnPointPool
|
|
|
|
@export var spawnDistance: int = 1000
|
|
|
|
func _ready() -> void:
|
|
randomize()
|
|
|
|
|
|
func _init() -> void:
|
|
pass
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if Input.is_action_pressed("attack"):
|
|
attack()
|
|
|
|
look_at(get_global_mouse_position())
|
|
rotation += PI / 2
|
|
var direction = Input.get_vector("moveLeft", "moveRight", "moveForward", "moveBackward").normalized().rotated(rotation)
|
|
if Input.is_action_just_pressed("dash") and dashCooldown.is_stopped():
|
|
dash()
|
|
velocity = velocity.lerp(direction * speed, acceleration * delta)
|
|
move_and_slide()
|
|
if timeGhost != null:
|
|
moveTimeGhost(global_position, rotation)
|
|
|
|
|
|
func _on_hurt_area_hurt(amount: int) -> void:
|
|
damage(amount)
|
|
|
|
func dash():
|
|
dashCooldown.start()
|
|
global_position += Vector2.UP.rotated(rotation) * 1000
|
|
|
|
func getRandomSpawnPointPosition() -> Vector2:
|
|
var rng = RandomNumberGenerator.new()
|
|
print(deg_to_rad(rng.randi_range(0, 360)))
|
|
print(Vector2.UP.rotated(deg_to_rad(rng.randi_range(0, 360))) * spawnDistance)
|
|
return global_position + Vector2.UP.rotated(deg_to_rad(rng.randi_range(0, 360))) * spawnDistance
|
|
#return spawnPointPool.get_children()[rng.randi_range(0, spawnPointPool.get_children().size()-1)].global_position
|