now saving persistent data
includes number of enemies killed, number of times died, last killed
This commit is contained in:
@@ -13,6 +13,7 @@ extends Node3D
|
||||
@export var health_drop_enabled = true
|
||||
@export var money_drop_enabled = true
|
||||
|
||||
@onready var crown = preload("res://assets/crown.tscn")
|
||||
var ammo_drop = [[load("res://assets/ammo_pickup.tscn")],["ammo"]]
|
||||
var stamina_drop = [[load("res://assets/stamina_pickup.tscn")],["stamina"]]
|
||||
var health_drop = [[load("res://assets/health_pickup.tscn")],["health"]]
|
||||
@@ -42,6 +43,17 @@ var engine_time_scale_cache : float = 1.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
##LOAD DATA
|
||||
SaveLoad.load_persistent_data()
|
||||
|
||||
#Spawn Crown
|
||||
var crown_spawn = crown.instantiate()
|
||||
print("LEVELMANAGER LAST HIT " + str(SaveLoad.last_hit_path))
|
||||
if SaveLoad.last_hit_path:
|
||||
var crown_target = get_node(SaveLoad.last_hit_path)
|
||||
crown_target.add_child(crown_spawn)
|
||||
else:
|
||||
get_tree().get_root().add_child(crown_spawn)
|
||||
#global randomize function
|
||||
randomize()
|
||||
|
||||
@@ -133,6 +145,13 @@ func cleared():
|
||||
clearedmsg.queue_free()
|
||||
|
||||
func die():
|
||||
#record stats
|
||||
if SaveLoad.player_deaths:
|
||||
SaveLoad.player_deaths += 1
|
||||
else:
|
||||
SaveLoad.player_deaths = 1
|
||||
SaveLoad.save_persistent_data()
|
||||
|
||||
var deadmsg = DEAD_ANNOUNCE.instantiate()
|
||||
get_parent().add_child(deadmsg)
|
||||
var instance_dead = dead_player.instantiate()
|
||||
@@ -140,6 +159,7 @@ func die():
|
||||
instance_dead.transform.basis = player.global_transform.basis
|
||||
if last_hit != null:
|
||||
instance_dead.target = last_hit
|
||||
SaveLoad.last_hit_path = str(last_hit.get_path())
|
||||
instance_dead.target_type = target_type
|
||||
instance_dead.respawn_position = respawn_position
|
||||
instance_dead.respawn_rotation = respawn_cam_rotation
|
||||
@@ -176,4 +196,6 @@ func pause_menu():
|
||||
paused = !paused
|
||||
|
||||
func save_quit():
|
||||
SaveLoad.save_persistent_data()
|
||||
SaveLoad.save_game_data()
|
||||
get_tree().quit()
|
||||
|
||||
15
scripts/crown.gd
Normal file
15
scripts/crown.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
print("CROWN IN SCENE")
|
||||
var target = get_node(SaveLoad.last_hit_path)
|
||||
if target:
|
||||
global_rotation = Vector3(0,0,0)
|
||||
global_transform.origin = target.global_position + Vector3(0,2,0)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
@@ -53,9 +53,6 @@ func _ready():
|
||||
taunt_spawn.global_transform.origin = target.global_position + Vector3(0,2,0)
|
||||
taunt_node = taunt_spawn
|
||||
|
||||
var crown_spawn = crown.instantiate()
|
||||
target.add_child(crown_spawn)
|
||||
crown_spawn.global_transform.origin = target.global_position + Vector3(0,2,0)
|
||||
|
||||
for i in target.outline_meshes:
|
||||
i.visible = true
|
||||
@@ -123,6 +120,7 @@ func _on_timer_timeout():
|
||||
anim_step += 1
|
||||
|
||||
func reload_level():
|
||||
SaveLoad.save_persistent_data()
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
func focus_on_target(focus_target):
|
||||
|
||||
@@ -111,7 +111,6 @@ var controlled_elsewhere = false
|
||||
@onready var moveable_holder: Node3D = $Head/MoveableHolder
|
||||
@onready var stand_check: RayCast3D = $StandCheck
|
||||
@onready var r_hand_test: MeshInstance3D = $Head/Recoil/Camera3D/WeaponHolder/RHandTest
|
||||
@onready var l_hand_test: MeshInstance3D = $Head/Recoil/Camera3D/WeaponHolder/LHandTest
|
||||
@onready var enemy_killed_audio: AudioStreamPlayer = $Audio/EnemyKilled
|
||||
|
||||
|
||||
@@ -422,6 +421,12 @@ func enemy_hit():
|
||||
hit_indicator.play()
|
||||
|
||||
func enemy_killed():
|
||||
if SaveLoad.enemies_killed:
|
||||
SaveLoad.enemies_killed += 1
|
||||
else:
|
||||
SaveLoad.enemies_killed = 1
|
||||
|
||||
SaveLoad.save_persistent_data()
|
||||
enemy_killed_audio.play()
|
||||
|
||||
func toggle_hud(hud_on):
|
||||
|
||||
63
scripts/save_load.gd
Normal file
63
scripts/save_load.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
extends Node
|
||||
|
||||
## SAVE DATA
|
||||
#Persistent
|
||||
var last_hit_path
|
||||
var player_deaths
|
||||
var enemies_killed
|
||||
|
||||
## SAVE DATA PATHS
|
||||
var persistent_save_path = "user://persistent_data.save"
|
||||
|
||||
func _ready() -> void:
|
||||
if player_deaths == null:
|
||||
player_deaths = 0
|
||||
if enemies_killed == null:
|
||||
enemies_killed = 0
|
||||
|
||||
func save_persistent_data():
|
||||
var file = FileAccess.open(persistent_save_path, FileAccess.WRITE)
|
||||
print("LAST HIT PATH " + str(last_hit_path))
|
||||
file.store_var(last_hit_path)
|
||||
file.store_var(player_deaths)
|
||||
print("SAVING PLAYER DEATHS " + str(player_deaths))
|
||||
file.store_var(enemies_killed)
|
||||
print("SAVING ENEMIES KILLED " + str(enemies_killed))
|
||||
|
||||
func load_persistent_data():
|
||||
if FileAccess.file_exists(persistent_save_path):
|
||||
var file = FileAccess.open(persistent_save_path, FileAccess.READ)
|
||||
last_hit_path = file.get_var()
|
||||
print("CROWN PARENT : " + str(last_hit_path))
|
||||
player_deaths = file.get_var()
|
||||
print("PLAYER DEATHS : " + str(player_deaths))
|
||||
enemies_killed = file.get_var()
|
||||
print("ENEMIES KILLED : " + str(enemies_killed))
|
||||
else:
|
||||
print("no data saved...")
|
||||
last_hit_path = null
|
||||
player_deaths = null
|
||||
enemies_killed = null
|
||||
|
||||
func save_game_data():
|
||||
pass
|
||||
|
||||
func load_save_game_data():
|
||||
pass
|
||||
|
||||
func data_validate(file,variable):
|
||||
if file.get_var(variable):
|
||||
return file.get_var(variable)
|
||||
else:
|
||||
return null
|
||||
|
||||
func persistent_data_calc(variable,amount):
|
||||
if variable == null:
|
||||
variable = amount
|
||||
print(str(variable) +" "+ str(amount))
|
||||
else:
|
||||
variable += amount
|
||||
|
||||
func load_data():
|
||||
load_persistent_data()
|
||||
load_save_game_data()
|
||||
Reference in New Issue
Block a user