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

45 lines
1.5 KiB
GDScript

extends Node2D
class_name Weapon
@export var ShootingProjectile : PackedScene
@export var Spread : float = 0
@export var AmmoType : String = "n/a"
@export var AmmoConsumption : float = 0
@export var ShootingTimer : Timer
@export var ShootingAction : String = ""
@export var SpawnerPoints : 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":
ShootingAction = "shootprimary"
"SecondaryWeapon":
ShootingAction = "shootsecondary"
elif Ship is NPCShip:
ShootingAction = "npc"
func _process(_delta):
var CanShoot = Ship.Hull.Ammunition[AmmoType] >= AmmoConsumption and ShootingTimer.is_stopped() and Ship.AllowShooting
if CanShoot and (Input.get_action_strength(ShootingAction) and ShootingAction != "npc" or ShootingAction == "npc" and Ship.Shooting):
shoot()
Ship.Hull.Ammunition[AmmoType] -= AmmoConsumption
ShootingTimer.start()
if AmmoType == "Laser Energy":
Ship.Shield.LaserTimer.start()
func shoot():
for Spawner in SpawnerPoints:
var ShootedProjectile = ShootingProjectile.instantiate()
ProjectileContainer.Instance.add_child(ShootedProjectile)
ShootedProjectile.global_position = Spawner.global_position
ShootedProjectile.global_rotation = Spawner.global_rotation + randf_range(-Deviation/2, Deviation/2)
ShootedProjectile.Fraction = Ship.Fraction
ShootedProjectile.modulate = Ship.modulate