Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
44
scripts/objects/Shield.gd
Normal file
44
scripts/objects/Shield.gd
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Shield
|
||||
|
||||
@export var max_capacity : int = 8
|
||||
@export var shield_charge_rate : float = 1
|
||||
@export var recharge_timer : Timer
|
||||
@export var laser_timer : Timer
|
||||
@export var laser_charge_rate : float = 20
|
||||
@onready var ship = get_parent()
|
||||
@onready var capacity : float = max_capacity
|
||||
var can_recharge : bool = false
|
||||
var laser_recharge : bool = true
|
||||
|
||||
func _ready():
|
||||
recharge_timer.timeout.connect(recharging_timer_out)
|
||||
laser_timer.timeout.connect(laser_timer_out)
|
||||
|
||||
func deal_damage(damage : float):
|
||||
capacity -= damage
|
||||
if capacity < 0:
|
||||
ship.hull.hp += capacity
|
||||
capacity = 0
|
||||
can_recharge = false
|
||||
recharge_timer.start()
|
||||
laser_timer.start()
|
||||
|
||||
func recharging_timer_out():
|
||||
can_recharge = true
|
||||
|
||||
func _physics_process(delta):
|
||||
if can_recharge:
|
||||
capacity += shield_charge_rate * delta
|
||||
if capacity > max_capacity:
|
||||
capacity = max_capacity
|
||||
can_recharge = false
|
||||
if laser_recharge:
|
||||
ship.hull.ammunition["Laser Energy"] += laser_charge_rate * delta
|
||||
if ship.hull.ammunition["Laser Energy"] > ship.hull.max_ammunition["Laser Energy"]:
|
||||
ship.hull.ammunition["Laser Energy"] = ship.hull.max_ammunition["Laser Energy"]
|
||||
laser_recharge = false
|
||||
|
||||
func laser_timer_out():
|
||||
laser_recharge = true
|
||||
Loading…
Add table
Add a link
Reference in a new issue