Initial commit (1/2)
This commit is contained in:
commit
3411c5796d
66 changed files with 2261 additions and 0 deletions
6
scripts/AmmoCounter.gd
Normal file
6
scripts/AmmoCounter.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Label
|
||||
|
||||
@onready var Hull = $"../../../Hull"
|
||||
|
||||
func _process(_delta):
|
||||
text = str(Hull.Ammunition)
|
||||
3
scripts/BaseCollider.gd
Normal file
3
scripts/BaseCollider.gd
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
extends StaticBody2D
|
||||
|
||||
var Fraction = "none"
|
||||
5
scripts/BaseNPCRotator.gd
Normal file
5
scripts/BaseNPCRotator.gd
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
extends Area2D
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is NPCShip:
|
||||
body.switchdestination()
|
||||
10
scripts/Bounty.gd
Normal file
10
scripts/Bounty.gd
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
extends Area2D
|
||||
|
||||
@export var Amount: float = 20
|
||||
|
||||
@onready var Text = $Label
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is MainShip:
|
||||
body.Money += Amount
|
||||
queue_free()
|
||||
20
scripts/BuyMenuButton.gd
Normal file
20
scripts/BuyMenuButton.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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
|
||||
12
scripts/CameraTweaks.gd
Normal file
12
scripts/CameraTweaks.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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)
|
||||
8
scripts/FactionRecoloring.gd
Normal file
8
scripts/FactionRecoloring.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
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")
|
||||
6
scripts/FuelCounter.gd
Normal file
6
scripts/FuelCounter.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Label
|
||||
|
||||
@onready var Hull = $"../../../Hull"
|
||||
|
||||
func _process(_delta):
|
||||
text = "Fuel: {fuel} / {max} units".format({"fuel":Hull.Fuel, "max":Hull.MaxFuel})
|
||||
6
scripts/HPCounter.gd
Normal file
6
scripts/HPCounter.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Label
|
||||
|
||||
@onready var Hull = $"../../../Hull"
|
||||
|
||||
func _process(_delta):
|
||||
text = "Hull Strength: {hp} / {max} units".format({"hp":"%0.2f" % Hull.HP, "max":Hull.MaxHP})
|
||||
60
scripts/MSEngine.gd
Normal file
60
scripts/MSEngine.gd
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
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
|
||||
8
scripts/MSEngineParticles.gd
Normal file
8
scripts/MSEngineParticles.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
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
|
||||
21
scripts/MSHull.gd
Normal file
21
scripts/MSHull.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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
|
||||
}
|
||||
44
scripts/MSShield.gd
Normal file
44
scripts/MSShield.gd
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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
|
||||
28
scripts/MainShipScript.gd
Normal file
28
scripts/MainShipScript.gd
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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
|
||||
16
scripts/MenuButton.gd
Normal file
16
scripts/MenuButton.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
18
scripts/Minimap.gd
Normal file
18
scripts/Minimap.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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)
|
||||
21
scripts/MinimapMarker.gd
Normal file
21
scripts/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 Scale = 1024 / clamp(Ship.global_position.distance_to(Target.global_position), 512, 2048)
|
||||
Marker.scale = Vector2(Scale, Scale)
|
||||
modulate = Target.modulate
|
||||
6
scripts/MoneyCounter.gd
Normal file
6
scripts/MoneyCounter.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Label
|
||||
|
||||
@onready var MS = $"../../.."
|
||||
|
||||
func _process(_delta):
|
||||
text = "Available Money: {money} units".format({"money":MS.Money})
|
||||
11
scripts/PlayerPauseController.gd
Normal file
11
scripts/PlayerPauseController.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends Control
|
||||
|
||||
@onready var MainShip = $"../../.."
|
||||
|
||||
func _on_unpause_button_button_up():
|
||||
get_tree().current_scene.unpause()
|
||||
|
||||
|
||||
func _on_exit_button_button_up():
|
||||
get_tree().current_scene.unpause()
|
||||
get_tree().change_scene_to_file("res://scenes/MainMenu.tscn")
|
||||
8
scripts/ProjectilesContainer.gd
Normal file
8
scripts/ProjectilesContainer.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
extends Node2D
|
||||
|
||||
class_name ProjectileContainer
|
||||
|
||||
static var Instance : ProjectileContainer
|
||||
|
||||
func _ready():
|
||||
Instance = self
|
||||
6
scripts/ShieldCounter.gd
Normal file
6
scripts/ShieldCounter.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
extends Label
|
||||
|
||||
@onready var Shield = $"../../../Shield"
|
||||
|
||||
func _process(_delta):
|
||||
text = "Shield Capacity: {shield} / {max} units".format({"shield":"%0.2f" % Shield.Capacity, "max":Shield.MaxShieldCapacity})
|
||||
67
scripts/Space.gd
Normal file
67
scripts/Space.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends Node2D
|
||||
|
||||
var CanTarget = []
|
||||
|
||||
var WeaponDict = {
|
||||
"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
|
||||
|
||||
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
|
||||
|
||||
func addtargetlist(body : Node2D):
|
||||
if !CanTarget.has(body):
|
||||
CanTarget.append(body)
|
||||
|
||||
func removetargetlist(body : Node2D):
|
||||
if CanTarget.has(body):
|
||||
CanTarget.erase(body)
|
||||
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_released("pause"):
|
||||
if get_tree().paused:
|
||||
unpause()
|
||||
else:
|
||||
pause()
|
||||
|
||||
func pause():
|
||||
get_tree().paused = true
|
||||
Player.PauseController.visible = true
|
||||
|
||||
func unpause():
|
||||
get_tree().paused = false
|
||||
Player.PauseController.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
|
||||
8
scripts/SpeedLine.gd
Normal file
8
scripts/SpeedLine.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
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)
|
||||
12
scripts/Star.gd
Normal file
12
scripts/Star.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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)
|
||||
frame = randi_range(0, 7)
|
||||
scale = Vector2(Size, Size)
|
||||
speed_scale = randf_range(0, 2)
|
||||
var Colors = [Color.LIGHT_BLUE, Color.WHITE, Color.LIGHT_GOLDENROD, Color.YELLOW, Color.ORANGE, Color.ORANGE_RED, Color.RED]
|
||||
modulate = Colors[randi_range(0, 6)]
|
||||
12
scripts/StarsGeneration.gd
Normal file
12
scripts/StarsGeneration.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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))
|
||||
7
scripts/StarterBase.gd
Normal file
7
scripts/StarterBase.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var Menu = $MenuCollider
|
||||
|
||||
func _ready():
|
||||
var Player = get_tree().current_scene.get_node("MainShip")
|
||||
Player.Minimap.add_marker(self, "base")
|
||||
24
scripts/StarterBaseMenu.gd
Normal file
24
scripts/StarterBaseMenu.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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()
|
||||
7
scripts/TurboParticles.gd
Normal file
7
scripts/TurboParticles.gd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
extends GPUParticles2D
|
||||
|
||||
@onready var MSEngine = $".."
|
||||
|
||||
func _process(_delta):
|
||||
var SpeedPercentage = MSEngine.Speed / MSEngine.MaxSpeed if MSEngine.Ship is MainShip else 0
|
||||
emitting = SpeedPercentage > 1
|
||||
12
scripts/projectiles/Rocket.gd
Normal file
12
scripts/projectiles/Rocket.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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()
|
||||
|
||||
62
scripts/saveload.gd
Normal file
62
scripts/saveload.gd
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
extends Node
|
||||
|
||||
class_name Game
|
||||
|
||||
static var gameversion = "Ictar 1.1"
|
||||
|
||||
static func profile_create(profile_name):
|
||||
var path = "user://"+profile_name+".cosmic"
|
||||
if not FileAccess.file_exists(path):
|
||||
var profile_meta = {
|
||||
'hash' : {},
|
||||
'meta' : {
|
||||
'created_in_version' : gameversion,
|
||||
'creation_date' : Time.get_datetime_string_from_system(),
|
||||
'last_version' : gameversion,
|
||||
'last_updated' : Time.get_datetime_string_from_system(),
|
||||
'profile_name' : profile_name,
|
||||
'legit' : true
|
||||
}
|
||||
}
|
||||
var profile_meta_keys = profile_meta['meta'].keys()
|
||||
for i in range(len(profile_meta_keys)):
|
||||
if profile_meta_keys[i][0] == "_":
|
||||
profile_meta_keys.remove_at(i)
|
||||
for i in range(len(profile_meta_keys)):
|
||||
profile_meta['hash'][i] = str(profile_meta['meta'][profile_meta_keys[i]]).sha256_buffer().hex_encode()
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
var json_string = JSON.stringify(profile_meta, "\t")
|
||||
file.store_string(json_string)
|
||||
else:
|
||||
profile_save(profile_name, "menu")
|
||||
|
||||
static func profile_save(profile_name, _gamestate):
|
||||
var path = "user://"+profile_name+".cosmic"
|
||||
if not FileAccess.file_exists(path):
|
||||
profile_create(profile_name)
|
||||
return
|
||||
var profile_meta = profile_load(profile_name)
|
||||
profile_meta['meta']['lastversion'] = gameversion
|
||||
profile_meta['meta']['lastupdated'] = Time.get_datetime_string_from_system()
|
||||
var profile_meta_keys = profile_meta['meta'].keys()
|
||||
for i in range(len(profile_meta_keys)):
|
||||
if profile_meta_keys[i][0] == "_":
|
||||
profile_meta_keys.remove_at(i)
|
||||
for i in range(len(profile_meta_keys)):
|
||||
profile_meta['hash'][i] = str(profile_meta['meta'][profile_meta_keys[i]]).sha256_buffer().hex_encode()
|
||||
var file = FileAccess.open(path, FileAccess.WRITE)
|
||||
var json_string = JSON.stringify(profile_meta, "\t")
|
||||
file.store_string(json_string)
|
||||
|
||||
|
||||
static func profile_load(profile_name):
|
||||
var path = "user://"+profile_name+".cosmic"
|
||||
if not FileAccess.file_exists(path):
|
||||
return
|
||||
var file = FileAccess.open(path, FileAccess.READ)
|
||||
var string = file.get_as_text()
|
||||
var profile_meta = JSON.parse_string(string)
|
||||
for meta in profile_meta:
|
||||
print(meta, ": ", profile_meta[meta])
|
||||
print(profile_meta[meta].keys())
|
||||
return profile_meta
|
||||
Loading…
Add table
Add a link
Reference in a new issue