Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
45
scripts/objects/weapon.gd
Normal file
45
scripts/objects/weapon.gd
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Weapon
|
||||
|
||||
@export var projectile : PackedScene
|
||||
@export var spread : float = 0
|
||||
@export var ammo_type : String = "n/a"
|
||||
@export var ammo_consumption : float = 0
|
||||
@export var shoot_timer : Timer
|
||||
@export var shoot_action : String = ""
|
||||
@export var spawner_points : Array[Node2D]
|
||||
|
||||
@onready var ship = $"../.."
|
||||
@onready var slot = $".."
|
||||
|
||||
var deviation : float = deg_to_rad(spread)
|
||||
|
||||
func _ready():
|
||||
randomize()
|
||||
if ship is MainShip:
|
||||
match slot.name:
|
||||
"PrimaryWeapon":
|
||||
shoot_action = "shootprimary"
|
||||
"SecondaryWeapon":
|
||||
shoot_action = "shootsecondary"
|
||||
elif ship is NPCShip:
|
||||
shoot_action = "npc"
|
||||
|
||||
func _process(_delta):
|
||||
var can_shoot = ship.hull.ammunition[ammo_type] >= ammo_consumption and shoot_timer.is_stopped() and ship.allow_shooting
|
||||
if can_shoot and (Input.get_action_strength(shoot_action) and shoot_action != "npc" or shoot_action == "npc" and ship.shooting):
|
||||
shoot()
|
||||
ship.hull.ammunition[ammo_type] -= ammo_consumption
|
||||
shoot_timer.start()
|
||||
if ammo_type == "Laser Energy":
|
||||
ship.shield.laser_timer.start()
|
||||
|
||||
func shoot():
|
||||
for spawner in spawner_points:
|
||||
var proj_inst = projectile.instantiate()
|
||||
ProjectileContainer.instance.add_child(proj_inst)
|
||||
proj_inst.global_position = spawner.global_position
|
||||
proj_inst.global_rotation = spawner.global_rotation + randf_range(-deviation/2, deviation/2)
|
||||
proj_inst.faction = ship.faction
|
||||
proj_inst.modulate = ship.modulate
|
||||
Loading…
Add table
Add a link
Reference in a new issue