Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
|
|
@ -1,6 +0,0 @@
|
|||
extends Label
|
||||
|
||||
@onready var Hull = $"../../../Hull"
|
||||
|
||||
func _process(_delta):
|
||||
text = str(Hull.Ammunition)
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
extends NinePatchRect
|
||||
|
||||
class_name BuyMenuButton
|
||||
|
||||
@export var Price : float
|
||||
@export var Clickable : BaseButton
|
||||
|
||||
@onready var BuyMenuObj = $".."
|
||||
@onready var PlayerShip = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
Clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
if PlayerShip.Money >= Price:
|
||||
PlayerShip.Money -= Price
|
||||
bought_action()
|
||||
|
||||
func bought_action():
|
||||
pass
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
extends Camera2D
|
||||
|
||||
@onready var MSEngine = $"../Engine"
|
||||
|
||||
var Scale : float = 1
|
||||
var MinScale = Scale / 1.5
|
||||
var MaxScale = Scale * 2
|
||||
|
||||
func _process(_delta):
|
||||
var SpeedPercentage = MSEngine.MaxSpeed / MSEngine.Speed
|
||||
SpeedPercentage = (clamp(SpeedPercentage, MinScale, MaxScale) if MSEngine.Speed >= 0 else MaxScale) if get_parent().AllowShooting else 1
|
||||
zoom = Vector2(SpeedPercentage, SpeedPercentage)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
func changeitemscolor():
|
||||
var Items = get_children()
|
||||
var Player = get_tree().current_scene.get_node("MainShip")
|
||||
for Item in Items:
|
||||
Item.modulate = modulate
|
||||
Player.Minimap.add_marker(Item, "hostile")
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
extends Label
|
||||
|
||||
@onready var Hull = $"../../../Hull"
|
||||
|
||||
func _process(_delta):
|
||||
text = "Fuel: {fuel} / {max} units".format({"fuel":Hull.Fuel, "max":Hull.MaxFuel})
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
extends Label
|
||||
|
||||
@onready var Hull = $"../../../Hull"
|
||||
|
||||
func _process(_delta):
|
||||
text = "Hull Strength: {hp} / {max} units".format({"hp":"%0.2f" % Hull.HP, "max":Hull.MaxHP})
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name ShipEngine
|
||||
|
||||
@export var MaxSpeed : float = 200 #максимальная скорость без турбо режима
|
||||
@export var MaxTurboSpeed : float = 300 #максимальная скорость в турбо режиме
|
||||
@export var SpeedAcceleration : float = 50 #ускорение
|
||||
@export var TurboFuelConsumption : float = 100 #потребление топлива в турбо режиме за секунду
|
||||
@export var RotationSpeed : int = 90 #максимальная скорость поворота
|
||||
|
||||
@onready var Ship = get_parent()
|
||||
|
||||
var Speed = 0 #текущая скорость
|
||||
var MinSpeed = MaxSpeed / -4 #минимальная скорость
|
||||
var TurboEnabled = false
|
||||
var AlternativeMovement = false
|
||||
var DestinationAngle : float
|
||||
var DestinationDifference : float
|
||||
|
||||
@onready var Hull = $"../Hull"
|
||||
|
||||
func _physics_process(delta):
|
||||
|
||||
|
||||
if DestinationAngle - Ship.rotation_degrees == clamp(DestinationAngle - Ship.rotation_degrees, -180, 180):
|
||||
DestinationDifference = DestinationAngle - Ship.rotation_degrees
|
||||
else:
|
||||
DestinationDifference = Ship.rotation_degrees - DestinationAngle
|
||||
if DestinationDifference != clamp(DestinationDifference, -1, 1):
|
||||
Ship.rotation_degrees += sign(DestinationDifference) * RotationSpeed * delta
|
||||
else:
|
||||
Ship.rotation_degrees = DestinationAngle
|
||||
if !AlternativeMovement:
|
||||
if Ship is MainShip: DestinationAngle = rad_to_deg(Ship.global_position.angle_to_point(get_global_mouse_position()))
|
||||
else:
|
||||
var RotationInput = Input.get_axis("rotateleft","rotateright")
|
||||
DestinationAngle += RotationInput * RotationSpeed * delta
|
||||
if DestinationAngle > 180: DestinationAngle = -180
|
||||
if DestinationAngle < -180: DestinationAngle = 180
|
||||
if Vector2.ZERO.distance_to(global_position) >= 5800: DestinationAngle = rad_to_deg(global_position.angle_to_point(Vector2.ZERO))
|
||||
|
||||
TurboEnabled = clamp(Input.get_action_raw_strength("turbo") * Hull.Fuel, 0, 1) if Ship is MainShip else (Ship.State == "runaway" and Hull.Fuel > 0)
|
||||
var AccelerationInput = Input.get_axis("deccelerate", "accelerate") if Ship is MainShip else 1.0
|
||||
if !TurboEnabled:
|
||||
Speed = clamp(Speed + AccelerationInput * SpeedAcceleration * delta, MinSpeed, max(MaxSpeed, Speed))
|
||||
if Speed > MaxSpeed:
|
||||
Speed -= SpeedAcceleration * delta if AccelerationInput != -1 else 0
|
||||
else:
|
||||
if Hull.Fuel > 0:
|
||||
Speed = clamp(Speed + SpeedAcceleration * delta, MinSpeed, MaxTurboSpeed)
|
||||
if Speed > MaxSpeed:
|
||||
Hull.Fuel -= TurboFuelConsumption * delta
|
||||
if Hull.Fuel < 0:
|
||||
Hull.Fuel = 0
|
||||
|
||||
Ship.velocity = Vector2.from_angle(Ship.rotation) * Speed
|
||||
Ship.move_and_slide()
|
||||
|
||||
if Input.is_action_just_released("alternatemovement") and Ship is MainShip:
|
||||
AlternativeMovement = !AlternativeMovement
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
extends GPUParticles2D
|
||||
|
||||
@onready var MSEngine = $".."
|
||||
|
||||
func _process(_delta):
|
||||
var SpeedPercentage = clamp(MSEngine.Speed / MSEngine.MaxSpeed, 0.75, 1.5)
|
||||
speed_scale = SpeedPercentage if MSEngine.Speed > 0 else 1
|
||||
emitting = MSEngine.Speed > 0
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Hull
|
||||
|
||||
@export var MaxHP : int = 30 #максимальное здоровье корпуса
|
||||
@export var MaxFuel : int = 1000 #максимальный запас топлива
|
||||
|
||||
@onready var HP = MaxHP #текущее количество здоровья
|
||||
@onready var Fuel : float = MaxFuel #текущее количество топлива
|
||||
|
||||
var Ammunition = {
|
||||
"n/a" : 0,
|
||||
"Laser Energy" : 100,
|
||||
"Rockets" : 10
|
||||
}
|
||||
|
||||
var MaxAmmunition = {
|
||||
"n/a" : 0,
|
||||
"Laser Energy" : 100,
|
||||
"Rockets" : 20
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Shield
|
||||
|
||||
@export var MaxShieldCapacity : int = 8 #максимальный заряд щита
|
||||
@export var ShieldChargeRate : float = 1 #скорость зарядки щита
|
||||
@export var RechargeTimer : Timer
|
||||
@export var LaserTimer : Timer
|
||||
@export var LaserChargeRate : float = 20
|
||||
|
||||
@onready var Capacity : float = MaxShieldCapacity #текущий заряд щита
|
||||
var CanRecharge : bool = false
|
||||
var LaserRecharge : bool = true
|
||||
|
||||
func _ready():
|
||||
RechargeTimer.timeout.connect(recharging_timer)
|
||||
LaserTimer.timeout.connect(laser_timer)
|
||||
|
||||
func deal_damage(damage : float):
|
||||
Capacity -= damage
|
||||
if Capacity < 0:
|
||||
get_parent().Hull.HP += Capacity
|
||||
Capacity = 0
|
||||
CanRecharge = false
|
||||
RechargeTimer.start()
|
||||
LaserTimer.start()
|
||||
|
||||
func recharging_timer():
|
||||
CanRecharge = true
|
||||
|
||||
func _physics_process(delta):
|
||||
if CanRecharge:
|
||||
Capacity += ShieldChargeRate * delta
|
||||
if Capacity > MaxShieldCapacity:
|
||||
Capacity = MaxShieldCapacity
|
||||
CanRecharge = false
|
||||
if LaserRecharge:
|
||||
get_parent().Hull.Ammunition["Laser Energy"] += LaserChargeRate * delta
|
||||
if get_parent().Hull.Ammunition["Laser Energy"] > get_parent().Hull.MaxAmmunition["Laser Energy"]:
|
||||
get_parent().Hull.Ammunition["Laser Energy"] = get_parent().Hull.MaxAmmunition["Laser Energy"]
|
||||
LaserRecharge = false
|
||||
|
||||
func laser_timer():
|
||||
LaserRecharge = true
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
class_name MainShip
|
||||
|
||||
@onready var MSEngine = $Engine
|
||||
@onready var Hull = $Hull
|
||||
@onready var Shield = $Shield
|
||||
@onready var PauseController = $GUI/Interface/PauseController
|
||||
@onready var Minimap = $CanvasLayer/Control/Minimap
|
||||
@onready var Camera = $Camera
|
||||
|
||||
var AllowShooting = true
|
||||
var Fraction = "player"
|
||||
var Money : float = 1000
|
||||
|
||||
func _physics_process(_delta):
|
||||
if Hull.HP < 0: destroy()
|
||||
|
||||
func changeinterfacecolor():
|
||||
$GUI/Interface.modulate = modulate
|
||||
|
||||
func destroy():
|
||||
Hull.HP = Hull.MaxHP
|
||||
#Hull.Fuel = Hull.MaxFuel
|
||||
Shield.Capacity = Shield.MaxShieldCapacity
|
||||
global_position = Vector2.ZERO
|
||||
MSEngine.Speed = 0
|
||||
MSEngine.TurboEnabled = false
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
extends NinePatchRect
|
||||
|
||||
class_name MenuDefaultButton
|
||||
|
||||
@export var Clickable : BaseButton
|
||||
|
||||
@onready var PlayerShip = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
Clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
action()
|
||||
|
||||
func action():
|
||||
pass
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
extends Control
|
||||
|
||||
@export var MarkerPack : PackedScene
|
||||
|
||||
@onready var Player = $"../../.."
|
||||
|
||||
var Markers = []
|
||||
|
||||
func _process(_delta):
|
||||
$Sprite.self_modulate = Player.modulate
|
||||
|
||||
func add_marker(Target : Node, Type : String):
|
||||
var MarkerInst = MarkerPack.instantiate()
|
||||
Markers.append(MarkerInst)
|
||||
MarkerInst.Target = Target
|
||||
MarkerInst.Type = Type
|
||||
MarkerInst.position = Vector2(96, 96)
|
||||
add_child(MarkerInst)
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var Marker = $MarkerSprite
|
||||
@onready var Ship = $"../../../.."
|
||||
|
||||
var Target : Node2D
|
||||
var Type = "hostile"
|
||||
var TMI = {
|
||||
"hostile": 0,
|
||||
"base": 1,
|
||||
"loot": 2
|
||||
}
|
||||
|
||||
func _ready():
|
||||
Marker.frame = TMI[Type]
|
||||
|
||||
func _process(_delta):
|
||||
rotation = Ship.global_position.angle_to_point(Target.global_position)
|
||||
var Scale = 1024 / clamp(Ship.global_position.distance_to(Target.global_position), 512, 2048)
|
||||
Marker.scale = Vector2(Scale, Scale)
|
||||
modulate = Target.modulate
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
extends Label
|
||||
|
||||
@onready var MS = $"../../.."
|
||||
|
||||
func _process(_delta):
|
||||
text = "Available Money: {money} units".format({"money":MS.Money})
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
extends Label
|
||||
|
||||
@onready var Shield = $"../../../Shield"
|
||||
|
||||
func _process(_delta):
|
||||
text = "Shield Capacity: {shield} / {max} units".format({"shield":"%0.2f" % Shield.Capacity, "max":Shield.MaxShieldCapacity})
|
||||
|
|
@ -1,42 +1,39 @@
|
|||
extends Node2D
|
||||
|
||||
var CanTarget = []
|
||||
|
||||
var WeaponDict = {
|
||||
var can_target = []
|
||||
var weapon_dict = {
|
||||
"SingleRocketMk1" : "res://scenes/weapons/presets/SingleRocketMk1.tscn",
|
||||
"DoubleLaserMk1" : "res://scenes/weapons/presets/DoubleLaserMk1.tscn",
|
||||
"SingleLaserMk1" : "res://scenes/weapons/presets/SingleLaserMk1.tscn"
|
||||
}
|
||||
var BoughtWeapon : Dictionary = WeaponDict.duplicate()
|
||||
var ColorPlayer
|
||||
var ColorBaseMenu
|
||||
var ColorEnemyFaction
|
||||
|
||||
@export var MapWidth = 8192
|
||||
@export var MapHeight = 8192
|
||||
|
||||
@onready var Player = $MainShip
|
||||
@onready var Base = $StarterBase
|
||||
@onready var EnemyFaction = $EnemyFaction
|
||||
var bought_weapon : Dictionary = weapon_dict.duplicate()
|
||||
var color_player
|
||||
var color_base
|
||||
var color_enemy
|
||||
@export var map_width = 8192
|
||||
@export var map_height = 8192
|
||||
@onready var ship = $MainShip
|
||||
@onready var base = $StarterBase
|
||||
@onready var enemy_faction = $EnemyFaction
|
||||
|
||||
func _ready():
|
||||
randomize()
|
||||
recolor()
|
||||
for key in BoughtWeapon:
|
||||
BoughtWeapon[key] = false
|
||||
BoughtWeapon["SingleLaserMk1"] = true
|
||||
Player.Camera.limit_left = -MapWidth/2.0
|
||||
Player.Camera.limit_right = MapWidth/2.0
|
||||
Player.Camera.limit_top = -MapHeight/2.0
|
||||
Player.Camera.limit_bottom = MapHeight/2.0
|
||||
for key in bought_weapon:
|
||||
bought_weapon[key] = false
|
||||
bought_weapon["SingleLaserMk1"] = true
|
||||
ship.camera.limit_left = -map_width/2.0
|
||||
ship.camera.limit_right = map_width/2.0
|
||||
ship.camera.limit_top = -map_height/2.0
|
||||
ship.camera.limit_bottom = map_height/2.0
|
||||
|
||||
func addtargetlist(body : Node2D):
|
||||
if !CanTarget.has(body):
|
||||
CanTarget.append(body)
|
||||
if !can_target.has(body):
|
||||
can_target.append(body)
|
||||
|
||||
func removetargetlist(body : Node2D):
|
||||
if CanTarget.has(body):
|
||||
CanTarget.erase(body)
|
||||
if can_target.has(body):
|
||||
can_target.erase(body)
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_released("pause"):
|
||||
|
|
@ -47,21 +44,21 @@ func _process(_delta):
|
|||
|
||||
func pause():
|
||||
get_tree().paused = true
|
||||
Player.PauseController.visible = true
|
||||
ship.pause_controller.visible = true
|
||||
|
||||
func unpause():
|
||||
get_tree().paused = false
|
||||
Player.PauseController.visible = false
|
||||
ship.pause_controller.visible = false
|
||||
|
||||
func recolor():
|
||||
ColorPlayer = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
|
||||
ColorBaseMenu = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
|
||||
ColorEnemyFaction = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
|
||||
Player.modulate = ColorPlayer
|
||||
Base.modulate = ColorBaseMenu
|
||||
EnemyFaction.modulate = ColorEnemyFaction
|
||||
EnemyFaction.changeitemscolor()
|
||||
Player.changeinterfacecolor()
|
||||
var Menu = get_node_or_null("MainShip/GUI/StarterBaseMenu")
|
||||
if Menu != null:
|
||||
Menu.modulate = Base.modulate
|
||||
color_player = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
|
||||
color_base = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
|
||||
color_enemy = Color.from_hsv(randf(), randf_range(0.8, 1), randf_range(0.8, 1))
|
||||
ship.modulate = color_player
|
||||
base.modulate = color_base
|
||||
enemy_faction.modulate = color_enemy
|
||||
enemy_faction.changeitemscolor()
|
||||
ship.changeinterfacecolor()
|
||||
var menu = get_node_or_null("MainShip/GUI/StarterBaseMenu")
|
||||
if menu != null:
|
||||
menu.modulate = base.modulate
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
extends Line2D
|
||||
|
||||
@onready var MSEngine = $"../../../Engine"
|
||||
|
||||
func _process(_delta):
|
||||
var SpeedPercentage : float = MSEngine.Speed / MSEngine.MaxSpeed * 100
|
||||
var NewPoints = [Vector2.ZERO, Vector2(SpeedPercentage, 0)]
|
||||
points = PackedVector2Array(NewPoints)
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
@export var Star : PackedScene
|
||||
@export var StarsAmount = 1000
|
||||
|
||||
func _ready():
|
||||
var MapWidthH = get_tree().current_scene.MapWidth / 2
|
||||
var MapHeightH = get_tree().current_scene.MapHeight / 2
|
||||
for i in range(StarsAmount):
|
||||
var StarInstance = Star.instantiate()
|
||||
add_child(StarInstance)
|
||||
StarInstance.position = Vector2(randi_range(-MapWidthH, MapWidthH), randi_range(-MapHeightH, MapHeightH))
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var Menu = $MenuCollider
|
||||
|
||||
func _ready():
|
||||
var Player = get_tree().current_scene.get_node("MainShip")
|
||||
Player.Minimap.add_marker(self, "base")
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
extends Area2D
|
||||
|
||||
@export var Menu : PackedScene
|
||||
@onready var BaseCollider = $"../BaseCollider/BaseColliderDetector"
|
||||
var MenuInst
|
||||
|
||||
func onbcbodyentered(body):
|
||||
if body is MainShip:
|
||||
body.MSEngine.Speed = 0
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is MainShip:
|
||||
body.AllowShooting = false
|
||||
MenuInst = Menu.instantiate()
|
||||
#get_tree().current_scene.add_child(MenuInst)
|
||||
body.find_child("GUI").add_child(MenuInst)
|
||||
#MenuInst.global_position = body.global_position# - Vector2(640, 360)
|
||||
MenuInst.modulate = get_parent().modulate
|
||||
|
||||
func _on_body_exited(body):
|
||||
if body is MainShip:
|
||||
body.AllowShooting = true
|
||||
MenuInst.queue_free()
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
extends GPUParticles2D
|
||||
|
||||
@onready var MSEngine = $".."
|
||||
|
||||
func _process(_delta):
|
||||
var SpeedPercentage = MSEngine.Speed / MSEngine.MaxSpeed if MSEngine.Ship is MainShip else 0
|
||||
emitting = SpeedPercentage > 1
|
||||
67
scripts/menu/BuyMenuButton.gd
Normal file
67
scripts/menu/BuyMenuButton.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends NinePatchRect
|
||||
|
||||
@export var data : Dictionary = {"id" : ""} ## Contains all buy options. Must have "id" key.
|
||||
@export var price : float
|
||||
@export var clickable : BaseButton
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
if ship.money >= price:
|
||||
ship.money -= price
|
||||
bought_action()
|
||||
|
||||
func bought_action():
|
||||
match data["id"]:
|
||||
"hp":
|
||||
if ship.hull.hp >= ship.hull.max_hp:
|
||||
ship.hull.hp = ship.hull.max_hp
|
||||
ship.money += price
|
||||
return
|
||||
ship.hull.hp += 1
|
||||
while(ship.hull.hp < ship.hull.max_hp and ship.money >= price):
|
||||
ship.hull.hp += 1
|
||||
ship.money -= price
|
||||
if ship.hull.hp > ship.hull.max_hp: ship.hull.hp = ship.hull.max_hp
|
||||
"rockets":
|
||||
if ship.hull.ammunition["Rockets"] == ship.hull.max_ammunition["Rockets"]:
|
||||
ship.money += price
|
||||
return
|
||||
var rocket_price : float = price / data["amount"]
|
||||
if ship.hull.ammunition["Rockets"] + data["amount"] > ship.hull.max_ammunition["Rockets"]:
|
||||
var rockets_left = ship.hull.max_ammunition["Rockets"] - ship.hull.ammunition["Rockets"]
|
||||
for i in range(rockets_left + 1):
|
||||
ship.money += rocket_price
|
||||
ship.hull.ammunition["Rockets"] = ship.hull.max_ammunition["Rockets"]
|
||||
else:
|
||||
ship.hull.ammunition["Rockets"] += data["amount"]
|
||||
"fuel":
|
||||
if ship.hull.fuel == ship.hull.max_fuel:
|
||||
ship.money += price
|
||||
return
|
||||
if ship.hull.fuel + data["amount"] > ship.hull.max_fuel:
|
||||
ship.hull.fuel = ship.hull.max_fuel
|
||||
else:
|
||||
ship.hull.fuel += data["amount"]
|
||||
"weapon":
|
||||
var primary_slot = ship.get_node("PrimaryWeapon")
|
||||
var secondary_slot = ship.get_node("SecondaryWeapon")
|
||||
var bought_weapon = get_tree().current_scene.bought_weapon
|
||||
var weapon_dict = get_tree().current_scene.weapon_dict
|
||||
var slot = primary_slot if data["slot"] == "primary" else secondary_slot
|
||||
if !bought_weapon[data["weapon"]]:
|
||||
bought_weapon[data["weapon"]] = true
|
||||
else:
|
||||
ship.money += price
|
||||
if slot.get_child_count() == 0:
|
||||
var weapon_inst = load(weapon_dict[data["weapon"]]).instantiate()
|
||||
slot.add_child(weapon_inst)
|
||||
slot.position = data["position"]
|
||||
else:
|
||||
for node in slot.get_children():
|
||||
node.queue_free()
|
||||
var weapon_inst = load(weapon_dict[data["weapon"]]).instantiate()
|
||||
slot.add_child(weapon_inst)
|
||||
slot.position = data["position"]
|
||||
38
scripts/menu/MainMenu.gd
Normal file
38
scripts/menu/MainMenu.gd
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
extends Node2D
|
||||
|
||||
var map_width = 1280
|
||||
var map_height = 720
|
||||
@onready var b1 = $Control/MenuButton1
|
||||
@onready var b2 = $Control/MenuButton2
|
||||
@onready var b3 = $Control/MenuButton3
|
||||
@onready var b4 = $Control/MenuButton4
|
||||
@onready var b5 = $Control/MenuButton5
|
||||
|
||||
func _ready():
|
||||
change_menu(0)
|
||||
|
||||
func change_menu(id):
|
||||
match id:
|
||||
0:
|
||||
b1.id = "NewGame"
|
||||
b2.id = "Profiles"
|
||||
b3.id = "Settings"
|
||||
b4.id = "Credits"
|
||||
b5.id = "ExitGame"
|
||||
1:
|
||||
b1.id = "CreateProfile"
|
||||
b2.id = "LoadProfile"
|
||||
b3.id = "DeleteProfile"
|
||||
b4.id = "Back"
|
||||
b5.id = "Null"
|
||||
2:
|
||||
b1.id = ""
|
||||
b2.id = ""
|
||||
b3.id = ""
|
||||
b4.id = ""
|
||||
b5.id = ""
|
||||
b1.change_name()
|
||||
b2.change_name()
|
||||
b3.change_name()
|
||||
b4.change_name()
|
||||
b5.change_name()
|
||||
47
scripts/menu/MainMenuButton.gd
Normal file
47
scripts/menu/MainMenuButton.gd
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
extends Button
|
||||
|
||||
@export var id = "Null"
|
||||
|
||||
@onready var сontroller = $"../.."
|
||||
|
||||
func _ready():
|
||||
button_up.connect(_on_button_up)
|
||||
change_name()
|
||||
|
||||
func _on_button_up():
|
||||
match id:
|
||||
"NewGame":
|
||||
get_tree().change_scene_to_file("res://scenes/Space.tscn")
|
||||
"CreateProfile":
|
||||
Game.profile_create("1")
|
||||
"LoadProfile":
|
||||
Game.profile_load("1")
|
||||
"ExitGame":
|
||||
get_tree().quit()
|
||||
|
||||
func change_name():
|
||||
visible = true
|
||||
match id:
|
||||
"NewGame":
|
||||
text = "New Game"
|
||||
"CreateProfile":
|
||||
text = "Create Profile"
|
||||
"LoadProfile":
|
||||
text = "Load Profile"
|
||||
"DeleteProfile":
|
||||
text = "Delete Profile"
|
||||
"ExitGame":
|
||||
text = "Exit Game"
|
||||
"Settings":
|
||||
text = "Settings (WIP)"
|
||||
"AudioSettings":
|
||||
text = "Audio (WIP)"
|
||||
"VideoSettings":
|
||||
text = "Video (WIP)"
|
||||
"Profiles":
|
||||
text = "Profiles (WIP)"
|
||||
"Back":
|
||||
text = "Back"
|
||||
"Null":
|
||||
text = Game.gameversion
|
||||
visible = false
|
||||
16
scripts/menu/MenuButton.gd
Normal file
16
scripts/menu/MenuButton.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
extends NinePatchRect
|
||||
|
||||
class_name MenuDefaultButton
|
||||
|
||||
@export var clickable : BaseButton
|
||||
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
action()
|
||||
|
||||
func action():
|
||||
pass
|
||||
4
scripts/menu/OptionsColors.gd
Normal file
4
scripts/menu/OptionsColors.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends MenuDefaultButton
|
||||
|
||||
func action():
|
||||
get_tree().current_scene.recolor()
|
||||
4
scripts/menu/ResetMainShip.gd
Normal file
4
scripts/menu/ResetMainShip.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends MenuDefaultButton
|
||||
|
||||
func action():
|
||||
ship.destroy()
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
extends StaticBody2D
|
||||
|
||||
var Fraction = "none"
|
||||
var faction = "none"
|
||||
17
scripts/misc/CameraTweaks.gd
Normal file
17
scripts/misc/CameraTweaks.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
extends Camera2D
|
||||
|
||||
@onready var engine = $"../Engine"
|
||||
@onready var cur_scale = zoom.x
|
||||
@onready var min_scale = cur_scale / 1.5
|
||||
@onready var max_scale = cur_scale * 2
|
||||
|
||||
func _process(_delta):
|
||||
var speed_percentage = engine.max_speed / engine.speed
|
||||
var factor : float
|
||||
if get_parent().allow_shooting:
|
||||
factor = clamp(speed_percentage, min_scale, max_scale)
|
||||
if engine.speed < 0:
|
||||
factor = max_scale
|
||||
else:
|
||||
factor = 1.0
|
||||
zoom = Vector2(factor, factor)
|
||||
19
scripts/misc/Counter.gd
Normal file
19
scripts/misc/Counter.gd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extends Label
|
||||
|
||||
@export var counter_id : String
|
||||
@onready var ship = $"../../.."
|
||||
@onready var hull = $"../../../Hull"
|
||||
@onready var shield = $"../../../Shield"
|
||||
|
||||
func _process(_delta) -> void:
|
||||
match counter_id:
|
||||
"ammo":
|
||||
text = str(hull.ammunition)
|
||||
"fuel":
|
||||
text = "Fuel: {fuel} / {max} units".format({"fuel":hull.fuel, "max":hull.max_fuel})
|
||||
"hp":
|
||||
text = "Hull Strength: {hp} / {max} units".format({"hp":"%0.2f" % hull.hp, "max":hull.max_hp})
|
||||
"money":
|
||||
text = "Available Money: {money} units".format({"money":ship.money})
|
||||
"shield":
|
||||
text = "Shield Capacity: {shield} / {max} units".format({"shield":"%0.2f" % shield.capacity, "max":shield.max_capacity})
|
||||
8
scripts/misc/EngineParticles.gd
Normal file
8
scripts/misc/EngineParticles.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends GPUParticles2D
|
||||
|
||||
@onready var engine = $".."
|
||||
|
||||
func _process(_delta):
|
||||
var speed_percentage = clamp(engine.speed / engine.max_speed, 0.75, 1.5)
|
||||
speed_scale = speed_percentage if engine.speed > 0 else 1
|
||||
emitting = engine.speed > 0
|
||||
8
scripts/misc/FactionRecoloring.gd
Normal file
8
scripts/misc/FactionRecoloring.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends Node2D
|
||||
|
||||
func changeitemscolor():
|
||||
var items = get_children()
|
||||
var ship = get_tree().current_scene.get_node("MainShip")
|
||||
for item in items:
|
||||
item.modulate = modulate
|
||||
ship.minimap.add_marker(item, "hostile")
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
extends Control
|
||||
|
||||
@onready var MainShip = $"../../.."
|
||||
@onready var ship = $"../../.."
|
||||
|
||||
func _on_unpause_button_button_up():
|
||||
get_tree().current_scene.unpause()
|
||||
|
|
@ -2,7 +2,7 @@ extends Node2D
|
|||
|
||||
class_name ProjectileContainer
|
||||
|
||||
static var Instance : ProjectileContainer
|
||||
static var instance : ProjectileContainer
|
||||
|
||||
func _ready():
|
||||
Instance = self
|
||||
instance = self
|
||||
8
scripts/misc/SpeedLine.gd
Normal file
8
scripts/misc/SpeedLine.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends Line2D
|
||||
|
||||
@onready var engine = $"../../../Engine"
|
||||
|
||||
func _process(_delta):
|
||||
var speed_percentage : float = engine.speed / engine.max_speed * 100
|
||||
var new_points = [Vector2.ZERO, Vector2(speed_percentage, 0)]
|
||||
points = PackedVector2Array(new_points)
|
||||
14
scripts/misc/StarsGeneration.gd
Normal file
14
scripts/misc/StarsGeneration.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
extends Node2D
|
||||
|
||||
@export var star : PackedScene
|
||||
@export var stars_amount = 1000
|
||||
|
||||
func _ready():
|
||||
var map_width_halved = get_tree().current_scene.map_width / 2
|
||||
var map_height_halved = get_tree().current_scene.map_height / 2
|
||||
for i in range(stars_amount):
|
||||
var star_inst = star.instantiate()
|
||||
var x = randi_range(-map_width_halved, map_width_halved)
|
||||
var y = randi_range(-map_height_halved, map_height_halved)
|
||||
add_child(star_inst)
|
||||
star_inst.position = Vector2(x, y)
|
||||
7
scripts/misc/StarterBase.gd
Normal file
7
scripts/misc/StarterBase.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var menu = $MenuCollider
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
ship.minimap.add_marker(self, "base")
|
||||
22
scripts/misc/StarterBaseMenu.gd
Normal file
22
scripts/misc/StarterBaseMenu.gd
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
extends Area2D
|
||||
|
||||
@export var menu : PackedScene
|
||||
@onready var base_collider = $"../BaseCollider/BaseColliderDetector"
|
||||
var menu_inst
|
||||
|
||||
func onbcbodyentered(body):
|
||||
if body is MainShip:
|
||||
body.engine.speed = 0
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is MainShip:
|
||||
body.allow_shooting = false
|
||||
menu_inst = menu.instantiate()
|
||||
body.find_child("GUI").add_child(menu_inst)
|
||||
menu_inst.modulate = get_parent().modulate
|
||||
|
||||
func _on_body_exited(body):
|
||||
if body is MainShip:
|
||||
body.allow_shooting = true
|
||||
menu_inst.queue_free()
|
||||
7
scripts/misc/TurboParticles.gd
Normal file
7
scripts/misc/TurboParticles.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends GPUParticles2D
|
||||
|
||||
@onready var engine = $".."
|
||||
|
||||
func _process(_delta):
|
||||
var speed_percentage = engine.speed / engine.max_speed if engine.ship is MainShip else 0
|
||||
emitting = speed_percentage > 1
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
extends Area2D
|
||||
|
||||
@export var Amount: float = 20
|
||||
@export var amount: float = 20
|
||||
|
||||
@onready var Text = $Label
|
||||
@onready var text = $Label
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is MainShip:
|
||||
body.Money += Amount
|
||||
body.money += amount
|
||||
queue_free()
|
||||
21
scripts/objects/Hull.gd
Normal file
21
scripts/objects/Hull.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Hull
|
||||
|
||||
@export var max_hp : int = 30
|
||||
@export var max_fuel : int = 1000
|
||||
|
||||
@onready var hp = max_hp
|
||||
@onready var fuel : float = max_fuel
|
||||
|
||||
var ammunition = {
|
||||
"n/a" : 0,
|
||||
"Laser Energy" : 100,
|
||||
"Rockets" : 10
|
||||
}
|
||||
|
||||
var max_ammunition = {
|
||||
"n/a" : 0,
|
||||
"Laser Energy" : 100,
|
||||
"Rockets" : 20
|
||||
}
|
||||
27
scripts/objects/MainShip.gd
Normal file
27
scripts/objects/MainShip.gd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
class_name MainShip
|
||||
|
||||
@onready var engine = $Engine
|
||||
@onready var hull = $Hull
|
||||
@onready var shield = $Shield
|
||||
@onready var pause_controller = $GUI/Interface/PauseController
|
||||
@onready var minimap = $CanvasLayer/Control/Minimap
|
||||
@onready var camera = $Camera
|
||||
|
||||
var allow_shooting = true
|
||||
var faction = "player"
|
||||
var money : float = 1000
|
||||
|
||||
func _process(_delta):
|
||||
if hull.hp < 0: destroy()
|
||||
|
||||
func changeinterfacecolor():
|
||||
$GUI/Interface.modulate = modulate
|
||||
|
||||
func destroy():
|
||||
hull.hp = hull.max_hp
|
||||
shield.capacity = shield.max_capacity
|
||||
global_position = Vector2.ZERO
|
||||
engine.speed = 0
|
||||
engine.turbo_enabled = false
|
||||
18
scripts/objects/Minimap.gd
Normal file
18
scripts/objects/Minimap.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
extends Control
|
||||
|
||||
@export var marker : PackedScene
|
||||
|
||||
@onready var ship = $"../../.."
|
||||
|
||||
var markers = []
|
||||
|
||||
func _process(_delta):
|
||||
$Sprite.self_modulate = ship.modulate
|
||||
|
||||
func add_marker(target : Node, type : String):
|
||||
var marker_inst = marker.instantiate()
|
||||
markers.append(marker_inst)
|
||||
marker_inst.target = target
|
||||
marker_inst.type = type
|
||||
marker_inst.position = Vector2(96, 96)
|
||||
add_child(marker_inst)
|
||||
21
scripts/objects/MinimapMarker.gd
Normal file
21
scripts/objects/MinimapMarker.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var marker = $MarkerSprite
|
||||
@onready var ship = $"../../../.."
|
||||
|
||||
var target : Node2D
|
||||
var type = "hostile"
|
||||
var tmi = {
|
||||
"hostile": 0,
|
||||
"base": 1,
|
||||
"loot": 2
|
||||
}
|
||||
|
||||
func _ready():
|
||||
marker.frame = tmi[type]
|
||||
|
||||
func _process(_delta):
|
||||
rotation = ship.global_position.angle_to_point(target.global_position)
|
||||
var sp_scale = 1024 / clamp(ship.global_position.distance_to(target.global_position), 512, 2048)
|
||||
marker.scale = Vector2(sp_scale, sp_scale)
|
||||
modulate = target.modulate
|
||||
10
scripts/objects/Rocket.gd
Normal file
10
scripts/objects/Rocket.gd
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
extends Projectile
|
||||
|
||||
func areyouready():
|
||||
target = Node2D.new()
|
||||
if len(get_tree().current_scene.can_target) > 0:
|
||||
get_tree().current_scene.can_target[0].add_child(target)
|
||||
else:
|
||||
get_parent().add_child(target)
|
||||
target.global_position = get_global_mouse_position()
|
||||
|
||||
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
|
||||
57
scripts/objects/ShipEngine.gd
Normal file
57
scripts/objects/ShipEngine.gd
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
extends Node2D
|
||||
|
||||
class_name ShipEngine
|
||||
|
||||
@export var max_speed : float = 200
|
||||
@export var max_turbo_speed : float = 300
|
||||
@export var acceleration : float = 50
|
||||
@export var fuel_consumption : float = 100
|
||||
@export var rotation_speed : int = 90
|
||||
@onready var ship = get_parent()
|
||||
@onready var hull = $"../Hull"
|
||||
var speed = 0
|
||||
var min_speed = max_speed / -4
|
||||
var turbo_enabled = false
|
||||
var alternative_movement = false
|
||||
var destination_angle : float
|
||||
var destination_difference : float
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var turbo_input = Input.get_action_raw_strength("turbo")
|
||||
var acceleration_input = Input.get_axis("deccelerate", "accelerate") if ship is MainShip else 1.0
|
||||
var rotation_input = Input.get_axis("rotateleft","rotateright")
|
||||
if destination_angle - ship.rotation_degrees == clamp(destination_angle - ship.rotation_degrees, -180, 180):
|
||||
destination_difference = destination_angle - ship.rotation_degrees
|
||||
else:
|
||||
destination_difference = ship.rotation_degrees - destination_angle
|
||||
if destination_difference != clamp(destination_difference, -1, 1):
|
||||
ship.rotation_degrees += sign(destination_difference) * rotation_speed * delta
|
||||
else:
|
||||
ship.rotation_degrees = destination_angle
|
||||
if alternative_movement:
|
||||
destination_angle += rotation_input * rotation_speed * delta
|
||||
if destination_angle > 180: destination_angle = -180
|
||||
if destination_angle < -180: destination_angle = 180
|
||||
if Vector2.ZERO.distance_to(global_position) >= 5800:
|
||||
destination_angle = rad_to_deg(global_position.angle_to_point(Vector2.ZERO))
|
||||
elif ship is MainShip:
|
||||
destination_angle = rad_to_deg(ship.global_position.angle_to_point(get_global_mouse_position()))
|
||||
turbo_enabled = clamp(turbo_input * hull.fuel, 0, 1) if ship is MainShip else (ship.state == "runaway" and hull.fuel > 0)
|
||||
if !turbo_enabled:
|
||||
speed = clamp(speed + acceleration_input * acceleration * delta, min_speed, max(max_speed, speed))
|
||||
if speed > max_speed:
|
||||
speed -= acceleration * delta if acceleration_input != -1 else 0
|
||||
else:
|
||||
if hull.fuel > 0:
|
||||
speed = clamp(speed + acceleration * delta, min_speed, max_turbo_speed)
|
||||
if speed > max_speed:
|
||||
hull.fuel -= fuel_consumption * delta
|
||||
if hull.fuel < 0:
|
||||
hull.fuel = 0
|
||||
|
||||
ship.velocity = Vector2.from_angle(ship.rotation) * speed
|
||||
ship.move_and_slide()
|
||||
|
||||
if Input.is_action_just_released("alternatemovement") and ship is MainShip:
|
||||
alternative_movement = !alternative_movement
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
extends AnimatedSprite2D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
randomize()
|
||||
var Size : float = randf_range(0.5, 2)
|
||||
82
scripts/objects/npcship.gd
Normal file
82
scripts/objects/npcship.gd
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
class_name NPCShip
|
||||
|
||||
@export var destination_timer : Timer
|
||||
@export var faction = "Enemy"
|
||||
@export var bounty_min : int = 20
|
||||
@export var bounty_max : int = 30
|
||||
@export var bounty : PackedScene
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
@onready var engine = $"Engine"
|
||||
@onready var hull = $"Hull"
|
||||
@onready var debug_label = $DebugLabel
|
||||
@onready var target_snap = $TargetSnap
|
||||
@onready var healthbar = $Zalupa/ZalupaTwo/Health
|
||||
@onready var shield = $Shield
|
||||
var state = "idle"
|
||||
var shooting = false
|
||||
var allow_shooting = true
|
||||
|
||||
func _ready():
|
||||
destination_timer.timeout.connect(switchdestination)
|
||||
target_snap.mouse_entered.connect(get_tree().current_scene.addtargetlist.bind(self))
|
||||
target_snap.mouse_exited.connect(get_tree().current_scene.removetargetlist.bind(self))
|
||||
|
||||
func _physics_process(_delta):
|
||||
match state:
|
||||
"idle":
|
||||
idlestate()
|
||||
"chase":
|
||||
chasestate()
|
||||
"maintaindistance":
|
||||
maintaindistancestate()
|
||||
"runaway":
|
||||
runawaystate()
|
||||
var format = {"HP" : "%0.2f" % hull.hp, "SC" : "%0.2f" % shield.capacity}
|
||||
healthbar.text = "{HP} HS + {SC} SC".format(format)
|
||||
if Vector2.ZERO.distance_to(global_position) > 5800 or hull.hp <= 0:
|
||||
destroy()
|
||||
|
||||
func switchdestination():
|
||||
engine.destination_angle = randi_range(0, 360)
|
||||
|
||||
func idlestate():
|
||||
shooting = false
|
||||
if global_position.distance_to(ship.global_position) <= 512 and ship.allow_shooting:
|
||||
state = "chase"
|
||||
|
||||
func chasestate():
|
||||
engine.destination_angle = rad_to_deg(global_position.angle_to_point(ship.global_position))
|
||||
shooting = true if abs(engine.destination_difference) <= 5 else false
|
||||
if global_position.distance_to(ship.global_position) > 512 or !ship.allow_shooting:
|
||||
state = "idle"
|
||||
if hull.hp < hull.max_hp * 0.2: state = "runaway"
|
||||
if global_position.distance_to(ship.global_position) <= 128:
|
||||
state = "maintaindistance"
|
||||
|
||||
func maintaindistancestate():
|
||||
engine.destination_angle += 1
|
||||
shooting = true if abs(engine.destination_difference) <= 5 else false
|
||||
if global_position.distance_to(ship.global_position) > 128:
|
||||
state = "chase"
|
||||
if !ship.allow_shooting:
|
||||
state = "idle"
|
||||
|
||||
func runawaystate():
|
||||
shooting = false
|
||||
engine.destination_angle = rad_to_deg(global_position.angle_to_point(ship.global_position)) - 180
|
||||
if global_position.distance_to(ship.global_position) > 1024 or !ship.allow_shooting:
|
||||
state = "idle"
|
||||
|
||||
func destroy():
|
||||
hull.hp = hull.max_hp
|
||||
hull.fuel = hull.max_fuel
|
||||
shield.capacity = shield.max_capacity
|
||||
state = "idle"
|
||||
var bounty_inst = bounty.instantiate()
|
||||
get_tree().current_scene.add_child(bounty_inst)
|
||||
bounty_inst.global_position = global_position
|
||||
bounty_inst.amount = randi_range(bounty_min, bounty_max)
|
||||
bounty_inst.text.text = str(bounty_inst.amount) + " MU"
|
||||
global_position = Vector2(randi_range(-4096, 4096), randi_range(-4096, 4096))
|
||||
48
scripts/objects/projectile.gd
Normal file
48
scripts/objects/projectile.gd
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
extends Node2D
|
||||
|
||||
class_name Projectile
|
||||
|
||||
@export var speed : float = 300
|
||||
@export var rotation_speed : float = 0
|
||||
@export var damage : float = 1
|
||||
@export var collider : Area2D
|
||||
@export var lifetime : float = 10
|
||||
|
||||
var faction = "none"
|
||||
var destination_angle : 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 rotation_speed == 0: destination_angle = global_rotation_degrees
|
||||
else: destination_angle = rad_to_deg(global_position.angle_to_point(target.global_position))
|
||||
global_position += speed * delta * global_transform.x
|
||||
var destination_difference : float
|
||||
if abs(destination_angle - global_rotation_degrees) <= 180:
|
||||
destination_difference = destination_angle - global_rotation_degrees
|
||||
else:
|
||||
destination_difference = global_rotation_degrees - destination_angle
|
||||
if destination_difference != clamp(destination_difference, -1, 1):
|
||||
global_rotation_degrees += sign(destination_difference) * rotation_speed * delta
|
||||
else:
|
||||
global_rotation_degrees = destination_angle
|
||||
|
||||
func _on_collision(body):
|
||||
match body.collision_layer:
|
||||
1:
|
||||
if body.faction != faction:
|
||||
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
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
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
extends Projectile
|
||||
|
||||
|
||||
|
||||
func areyouready():
|
||||
Target = Node2D.new()
|
||||
if len(get_tree().current_scene.CanTarget) > 0:
|
||||
get_tree().current_scene.CanTarget[0].add_child(Target)
|
||||
else:
|
||||
get_parent().add_child(Target)
|
||||
Target.global_position = get_global_mouse_position()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue