Added player save function to "persistent" tag, added UI elements
This commit is contained in:
@@ -18,4 +18,5 @@ func _ready():
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
text = str(player.gun.gun_name) + "\n Ammo: " + str(level_control.ammo_current[level_control.current_gun_index]) +" " + str(level_control.ammo_reserve[level_control.current_gun_index])
|
||||
pass
|
||||
#text = str(player.gun.gun_name) + "\n Ammo: " + str(level_control.ammo_current[level_control.current_gun_index]) +" " + str(level_control.ammo_reserve[level_control.current_gun_index])
|
||||
|
||||
@@ -183,7 +183,7 @@ func die():
|
||||
player.toggle_hud(true)
|
||||
player.gun.visible = false
|
||||
player.health_indicator.color = Color(0.471, 0, 0, 0)
|
||||
player.crosshair.visible = false
|
||||
|
||||
|
||||
|
||||
func pickup_spawn():
|
||||
|
||||
@@ -18,4 +18,5 @@ func _ready():
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
text = "health " + str(clamp(level_control.health,0,100))+ "\n$" + str(int(level_control.money)) + "\nStamina: " + str(int((player.remaining_stamina/player.MAX_STAMINA)*100)) + "%"
|
||||
pass
|
||||
#text = "health " + str(clamp(level_control.health,0,100))+ "\n$" + str(int(level_control.money)) + "\nStamina: " + str(int((player.remaining_stamina/player.MAX_STAMINA)*100)) + "%"
|
||||
|
||||
@@ -10,6 +10,7 @@ var cycle_count
|
||||
@export var gun_name : String
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var ads : bool = false
|
||||
@export var recoil_amount : Vector3 = Vector3(.2,0,0)
|
||||
@export var spread : Vector3 = Vector3(1,1,1)
|
||||
@export var kick_amount : float = 5
|
||||
|
||||
@@ -39,9 +39,6 @@ func _ready():
|
||||
#set FOV
|
||||
camera.fov = respawn_fov
|
||||
|
||||
level_control.player.ammo_counter.visible = false
|
||||
level_control.player.stamina_counter.visible = false
|
||||
|
||||
#start timer
|
||||
timer.start(.3)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ extends Node3D
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var hitscan_enabled : bool = false
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var ads : bool = false
|
||||
@export var recoil_amount : Vector3 = Vector3(.2,.05,.05)
|
||||
@export var kick_amount : float = .1
|
||||
@export var max_ammo = 15
|
||||
|
||||
31
scripts/hud.gd
Normal file
31
scripts/hud.gd
Normal file
@@ -0,0 +1,31 @@
|
||||
extends Control
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var player = level_control.player
|
||||
@onready var stamina_bar: TextureProgressBar = $StaminaBar
|
||||
@onready var health_bar: ProgressBar = $LeftMargin/HealthBar
|
||||
@onready var gun_name: Label = $"MarginContainer/VBoxContainer/Gun Name"
|
||||
@onready var ammo: Label = $MarginContainer/VBoxContainer/Ammo
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
health_bar.max_value = level_control.start_health
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
player = level_control.player
|
||||
if player != null:
|
||||
health_bar.value = level_control.health
|
||||
if player.remaining_stamina/player.MAX_STAMINA >= .99:
|
||||
stamina_bar.visible = false
|
||||
else:
|
||||
stamina_bar.visible = true
|
||||
stamina_bar.value = player.remaining_stamina
|
||||
|
||||
ammo.text = str(level_control.ammo_current[level_control.current_gun_index]) +" - " + str(level_control.ammo_reserve[level_control.current_gun_index])
|
||||
|
||||
if player.gun != null:
|
||||
gun_name.text = player.gun.gun_name
|
||||
else:
|
||||
gun_name.visible = false
|
||||
@@ -5,6 +5,7 @@ var start_rotation
|
||||
var random_spread_start
|
||||
var cycle_count_start
|
||||
var cycle_count
|
||||
var ads = false
|
||||
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
|
||||
@@ -20,7 +20,7 @@ var reserve_ammo
|
||||
|
||||
## SAVE DATA PATHS
|
||||
var persistent_save_path = "user://persistent_data.save"
|
||||
var game_save_path = "user://game_save_data.save"
|
||||
var game_save_path = "user://gamesave.save"
|
||||
|
||||
func _ready() -> void:
|
||||
if player_deaths == null:
|
||||
@@ -76,8 +76,6 @@ func save_game_data():
|
||||
reserve_ammo = level_control.ammo_reserve
|
||||
|
||||
#SAVE DATA
|
||||
file.store_var(player_loc)
|
||||
file.store_var(player_rot)
|
||||
file.store_var(player_health)
|
||||
file.store_var(player_money)
|
||||
file.store_var(held_guns)
|
||||
@@ -126,8 +124,6 @@ func load_save_game_data():
|
||||
|
||||
#GET DATA
|
||||
if !data_cleared:
|
||||
player_loc = file.get_var()
|
||||
player_rot = file.get_var()
|
||||
player_health = file.get_var()
|
||||
player_money = file.get_var()
|
||||
var held_guns_encoded = file.get_var()
|
||||
@@ -137,7 +133,7 @@ func load_save_game_data():
|
||||
reserve_ammo = file.get_var()
|
||||
var current_nodes = get_tree().get_nodes_in_group("persist")
|
||||
for i in current_nodes:
|
||||
if i.get_class() == "CharacterBody3D":
|
||||
if i.is_in_group("enemy"):
|
||||
i.quiet_remove()
|
||||
else:
|
||||
i.queue_free()
|
||||
@@ -151,13 +147,17 @@ func load_save_game_data():
|
||||
continue
|
||||
var node_data = json.data
|
||||
var new_object = load(node_data["filename"]).instantiate()
|
||||
print("NEW OBJECT : ",new_object)
|
||||
|
||||
get_node(node_data["parent"]).add_child(new_object)
|
||||
|
||||
|
||||
#apply transform if available
|
||||
if node_data["pos_x"] != null:
|
||||
new_object.position = Vector3(node_data["pos_x"],node_data["pos_y"],node_data["pos_z"])
|
||||
if node_data["rot_x"] != null:
|
||||
new_object.rotation = Vector3(node_data["rot_x"],node_data["rot_y"],node_data["rot_z"])
|
||||
print("NEW OBJECT PLACED AT ", new_object.position)
|
||||
|
||||
#apply other save data
|
||||
for i in node_data.keys():
|
||||
if i == "filename" or i == "pos_x" or i == "pos_y" or i == "pos_z":
|
||||
continue
|
||||
@@ -165,14 +165,13 @@ func load_save_game_data():
|
||||
|
||||
|
||||
#APPLY DATA
|
||||
player.global_position = player_loc
|
||||
player.global_rotation = player_rot
|
||||
level_control.health = player_health
|
||||
level_control.money = player_money
|
||||
level_control.held_guns = held_guns
|
||||
if player.gun:
|
||||
player.gun.queue_free()
|
||||
level_control.gun_spawn(current_gun)
|
||||
if current_gun != null:
|
||||
level_control.gun_spawn(current_gun)
|
||||
level_control.ammo_current = current_ammo
|
||||
level_control.ammo_reserve = reserve_ammo
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ extends Node3D
|
||||
@export var gun_name : String
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var hitscan_enabled : bool = false
|
||||
@export var ads : bool = false
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var recoil_amount : Vector3 = Vector3(.2,.05,.05)
|
||||
@export var kick_amount : float = .1
|
||||
|
||||
Reference in New Issue
Block a user