82 lines
2.0 KiB
GDScript
82 lines
2.0 KiB
GDScript
class_name PlayerShip
|
|
extends AbstractShip
|
|
|
|
|
|
const ENEMY_LAYER = 4
|
|
|
|
const BLINK_CHARGE_MAXIMUM = 3.0
|
|
|
|
|
|
@export_range(0, 200) var blink_range := 0
|
|
@export var player_data : PlayerData:
|
|
set = _set_player_data
|
|
|
|
|
|
var blink_charge: float:
|
|
set(value):
|
|
blink_charge = value
|
|
if blink_charge_indicator != null:
|
|
blink_charge_indicator.value = blink_charge
|
|
|
|
|
|
@onready var blink_shadow : GPUParticles2D = $BlinkShadow
|
|
@onready var blink_charge_indicator : BlinkChargeIndicator = $Ship/BlinkChargeIndicator
|
|
|
|
|
|
func _ready() -> void:
|
|
super._ready()
|
|
|
|
blink_charge_indicator.maximum = BLINK_CHARGE_MAXIMUM
|
|
blink_charge = BLINK_CHARGE_MAXIMUM
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
super._physics_process(delta)
|
|
|
|
shoot()
|
|
|
|
if blink_charge < BLINK_CHARGE_MAXIMUM:
|
|
blink_charge += delta
|
|
blink_charge_indicator.value = blink_charge
|
|
|
|
|
|
func _blink(direction: Vector2) -> void:
|
|
if blink_charge < BLINK_CHARGE_MAXIMUM: return
|
|
|
|
blink_charge = 0
|
|
|
|
var shadow : GPUParticles2D = blink_shadow.duplicate()
|
|
var process_material : ParticleProcessMaterial = shadow.process_material
|
|
process_material.direction = Vector3(direction.x, direction.y, 0)
|
|
|
|
shadow.emitting = true
|
|
shadow.global_position = global_position
|
|
get_tree().current_scene.add_child(shadow)
|
|
shadow.finished.connect(shadow.queue_free)
|
|
|
|
collision_mask &= ~ENEMY_LAYER
|
|
move_and_collide(direction * blink_range)
|
|
collision_mask |= ENEMY_LAYER
|
|
|
|
|
|
func _set_player_data(new_data: PlayerData) -> void:
|
|
if new_data == null: return
|
|
|
|
player_data = new_data
|
|
_weapons.clear()
|
|
for i in range(min(player_data.weapons.size(), weapon_positions.size())):
|
|
var weapon_scene := player_data.weapons[i].player_scene
|
|
var weapon : AbstractWeapon = weapon_scene.instantiate()
|
|
_add_weapon(weapon, weapon_positions[i])
|
|
|
|
if player_data.hull > 0:
|
|
health.hull = min(player_data.hull, health.max_hull)
|
|
|
|
|
|
func _on_hull_updated(value: int, max_value: int) -> void:
|
|
super._on_hull_updated(value, max_value)
|
|
|
|
if player_data == null: return
|
|
|
|
player_data.hull = value
|