Initial commit (1/2)

This commit is contained in:
Алкесей Мирнеков 2023-11-05 16:23:18 +03:00 committed by GitHub
commit 3411c5796d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 2261 additions and 0 deletions

45
modules/weapon.gd Normal file
View file

@ -0,0 +1,45 @@
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