Initial commit (1/2)
This commit is contained in:
commit
3411c5796d
66 changed files with 2261 additions and 0 deletions
78
modules/npcship.gd
Normal file
78
modules/npcship.gd
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
class_name NPCShip
|
||||
|
||||
@export var DestinationTimer : Timer
|
||||
@export var Fraction = "Enemy"
|
||||
@export var BountyMin : int = 20
|
||||
@export var BountyMax : int = 30
|
||||
@export var Bounty : PackedScene
|
||||
|
||||
var State = "idle"
|
||||
var Shooting = false
|
||||
var AllowShooting = true
|
||||
|
||||
@onready var PlayerShip = get_tree().current_scene.get_node("MainShip")
|
||||
@onready var NPCEngine = $"Engine"
|
||||
@onready var Hull = $"Hull"
|
||||
@onready var DebugLabel = $DebugLabel
|
||||
@onready var TargetSnap = $TargetSnap
|
||||
@onready var Healthbar = $Zalupa/ZalupaTwo/Health
|
||||
@onready var Shield = $Shield
|
||||
|
||||
func _ready():
|
||||
DestinationTimer.timeout.connect(switchdestination)
|
||||
TargetSnap.mouse_entered.connect(get_tree().current_scene.addtargetlist.bind(self))
|
||||
TargetSnap.mouse_exited.connect(get_tree().current_scene.removetargetlist.bind(self))
|
||||
|
||||
func _physics_process(_delta):
|
||||
match State:
|
||||
"idle":
|
||||
idlestate()
|
||||
"chase":
|
||||
chasestate()
|
||||
"maintaindistance":
|
||||
maintaindistancestate()
|
||||
"runaway":
|
||||
runawaystate()
|
||||
Healthbar.text = "{HP} HS + {SC} SC".format({"HP" : "%0.2f" % Hull.HP, "SC" : "%0.2f" % Shield.Capacity})
|
||||
if Vector2.ZERO.distance_to(global_position) > 5800 or Hull.HP <= 0:
|
||||
destroy()
|
||||
|
||||
func switchdestination():
|
||||
NPCEngine.DestinationAngle = randi_range(0, 360)
|
||||
|
||||
func idlestate():
|
||||
Shooting = false
|
||||
if global_position.distance_to(PlayerShip.global_position) <= 512 and PlayerShip.AllowShooting: State = "chase"
|
||||
if Vector2.ZERO.distance_to(global_position) > 5800: NPCEngine.DestinationAngle = rad_to_deg(global_position.angle_to(Vector2.ZERO))
|
||||
|
||||
func chasestate():
|
||||
NPCEngine.DestinationAngle = rad_to_deg(global_position.angle_to_point(PlayerShip.global_position))
|
||||
Shooting = true if NPCEngine.DestinationDifference == clamp(NPCEngine.DestinationDifference, -5, 5) else false
|
||||
if global_position.distance_to(PlayerShip.global_position) > 512 or !PlayerShip.AllowShooting: State = "idle"
|
||||
if Hull.HP < Hull.MaxHP * 0.2: State = "runaway"
|
||||
if global_position.distance_to(PlayerShip.global_position) <= 128: State = "maintaindistance"
|
||||
|
||||
func maintaindistancestate():
|
||||
NPCEngine.DestinationAngle += 1
|
||||
Shooting = true if NPCEngine.DestinationDifference == clamp(NPCEngine.DestinationDifference, -5, 5) else false
|
||||
if global_position.distance_to(PlayerShip.global_position) > 128: State = "chase"
|
||||
if !PlayerShip.AllowShooting: State = "idle"
|
||||
|
||||
func runawaystate():
|
||||
Shooting = false
|
||||
NPCEngine.DestinationAngle = rad_to_deg(global_position.angle_to_point(PlayerShip.global_position)) - 180
|
||||
if global_position.distance_to(PlayerShip.global_position) > 1024 or !PlayerShip.AllowShooting: State = "idle"
|
||||
|
||||
func destroy():
|
||||
Hull.HP = Hull.MaxHP
|
||||
Hull.Fuel = Hull.MaxFuel
|
||||
Shield.Capacity = Shield.MaxShieldCapacity
|
||||
State = "idle"
|
||||
var BountyInst = Bounty.instantiate()
|
||||
get_tree().current_scene.add_child(BountyInst)
|
||||
BountyInst.global_position = global_position
|
||||
BountyInst.Amount = randi_range(BountyMin, BountyMax)
|
||||
BountyInst.Text.text = str(BountyInst.Amount) + " MU"
|
||||
global_position = Vector2(randi_range(-4096, 4096), randi_range(-4096, 4096))
|
||||
49
modules/projectile.gd
Normal file
49
modules/projectile.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Projectile
|
||||
|
||||
@export var Speed : float = 300
|
||||
@export var RotationSpeed : float = 0
|
||||
@export var Damage : float = 1
|
||||
@export var Collider : Area2D
|
||||
@export var Lifetime : float = 10
|
||||
|
||||
var Fraction = "none"
|
||||
var DestinationAngle : float
|
||||
var Target : Node2D = self
|
||||
|
||||
func _ready():
|
||||
get_tree().create_timer(Lifetime).timeout.connect(queue_free)
|
||||
Collider.body_entered.connect(_on_collision)
|
||||
areyouready()
|
||||
|
||||
func _physics_process(delta):
|
||||
if RotationSpeed == 0: DestinationAngle = global_rotation_degrees
|
||||
else: DestinationAngle = rad_to_deg(global_position.angle_to_point(Target.global_position))
|
||||
global_position += Speed * delta * global_transform.x
|
||||
var DestinationDifference : float
|
||||
if DestinationAngle - global_rotation_degrees == clamp(DestinationAngle - global_rotation_degrees, -180, 180):
|
||||
DestinationDifference = DestinationAngle - global_rotation_degrees
|
||||
else:
|
||||
DestinationDifference = global_rotation_degrees - DestinationAngle
|
||||
if DestinationDifference != clamp(DestinationDifference, -1, 1):
|
||||
global_rotation_degrees += sign(DestinationDifference) * RotationSpeed * delta
|
||||
else:
|
||||
global_rotation_degrees = DestinationAngle
|
||||
|
||||
func _on_collision(body):
|
||||
match body.collision_layer:
|
||||
1:
|
||||
if body.Fraction != Fraction:
|
||||
if Target != self:
|
||||
Target.queue_free()
|
||||
body.Shield.deal_damage(Damage)
|
||||
queue_free()
|
||||
2:
|
||||
if Target != self:
|
||||
Target.queue_free()
|
||||
queue_free()
|
||||
|
||||
|
||||
func areyouready():
|
||||
pass
|
||||
45
modules/weapon.gd
Normal file
45
modules/weapon.gd
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue