cosmic/scripts/MSShield.gd
Алкесей Мирнеков 3411c5796d
Initial commit (1/2)
2023-11-05 16:23:18 +03:00

44 lines
1.3 KiB
GDScript

extends Node2D
class_name Shield
@export var MaxShieldCapacity : int = 8 #максимальный заряд щита
@export var ShieldChargeRate : float = 1 #скорость зарядки щита
@export var RechargeTimer : Timer
@export var LaserTimer : Timer
@export var LaserChargeRate : float = 20
@onready var Capacity : float = MaxShieldCapacity #текущий заряд щита
var CanRecharge : bool = false
var LaserRecharge : bool = true
func _ready():
RechargeTimer.timeout.connect(recharging_timer)
LaserTimer.timeout.connect(laser_timer)
func deal_damage(damage : float):
Capacity -= damage
if Capacity < 0:
get_parent().Hull.HP += Capacity
Capacity = 0
CanRecharge = false
RechargeTimer.start()
LaserTimer.start()
func recharging_timer():
CanRecharge = true
func _physics_process(delta):
if CanRecharge:
Capacity += ShieldChargeRate * delta
if Capacity > MaxShieldCapacity:
Capacity = MaxShieldCapacity
CanRecharge = false
if LaserRecharge:
get_parent().Hull.Ammunition["Laser Energy"] += LaserChargeRate * delta
if get_parent().Hull.Ammunition["Laser Energy"] > get_parent().Hull.MaxAmmunition["Laser Energy"]:
get_parent().Hull.Ammunition["Laser Energy"] = get_parent().Hull.MaxAmmunition["Laser Energy"]
LaserRecharge = false
func laser_timer():
LaserRecharge = true