substantial work on saving and loading and hub mechanic
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
extends Node3D
|
||||
class_name map
|
||||
|
||||
@export var map_name : String = "Map Name"
|
||||
@export var gamemode : gamemode
|
||||
@export var player : Node
|
||||
@export var MAX_PARTICLES = 100
|
||||
@@ -13,20 +15,14 @@ extends Node3D
|
||||
@onready var item_pickup = preload("res://assets/item_pickup.tscn")
|
||||
@onready var crown = preload("res://assets/crown.tscn")
|
||||
var dead_player = preload("res://assets/dead_cam.tscn")
|
||||
const CLEARED_ANNOUNCE = preload("res://assets/cleared_announce.tscn")
|
||||
const DEAD_ANNOUNCE = preload("res://assets/dead_announce.tscn")
|
||||
|
||||
var level_name
|
||||
var paused = false
|
||||
var health
|
||||
var money
|
||||
var pickups = []
|
||||
var held_guns = []
|
||||
var ammo_current = [0]
|
||||
var ammo_reserve = [0]
|
||||
|
||||
var keys = []
|
||||
var guns_dict = {}
|
||||
var current_gun_index
|
||||
var particle_number = 0
|
||||
var enemy_hiveminds = []
|
||||
var remaining_enemies
|
||||
@@ -40,13 +36,10 @@ var engine_time_scale_cache : float = 1.0
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
level_name = self.get_name()
|
||||
print("LEVEL NAME ",level_name)
|
||||
#connect to signals
|
||||
SignalBus.enemy_count_changed.connect(enemy_count)
|
||||
|
||||
health = gamemode.start_health
|
||||
money = gamemode.money
|
||||
|
||||
GameGlobals.health = gamemode.start_health
|
||||
|
||||
#LOAD DATA
|
||||
SaveLoad.load_persistent_data()
|
||||
@@ -83,7 +76,7 @@ func _ready():
|
||||
enemy_count()
|
||||
|
||||
func refresh_scene():
|
||||
health = gamemode.start_health
|
||||
GameGlobals.health = gamemode.start_health
|
||||
|
||||
respawn_position = player.camera.global_position
|
||||
respawn_cam_rotation = player.global_transform.basis
|
||||
@@ -91,18 +84,18 @@ func refresh_scene():
|
||||
if player:
|
||||
#Set up starting guns and ammo
|
||||
if gamemode.gun_1 != null:
|
||||
held_guns = [gamemode.gun_1]
|
||||
var instance_gun = held_guns[0].instantiate()
|
||||
GameGlobals.held_guns = [gamemode.gun_1]
|
||||
var instance_gun = GameGlobals.held_guns[0].instantiate()
|
||||
player.add_ammo(true,instance_gun.gun_name,instance_gun.ammo_type,instance_gun.max_ammo,instance_gun.start_mags)
|
||||
|
||||
if gamemode.gun_2 != null:
|
||||
held_guns.append(gamemode.gun_2)
|
||||
var instance_gun_2 = held_guns[1].instantiate()
|
||||
GameGlobals.held_guns.append(gamemode.gun_2)
|
||||
var instance_gun_2 = GameGlobals.held_guns[1].instantiate()
|
||||
player.add_ammo(true,instance_gun_2.gun_name,instance_gun_2.ammo_type,instance_gun_2.max_ammo,instance_gun_2.start_mags)
|
||||
|
||||
# Spawn first gun
|
||||
if gamemode.gun_1 != null:
|
||||
current_gun_index = 0
|
||||
GameGlobals.current_gun_index = 0
|
||||
gun_spawn(0)
|
||||
|
||||
|
||||
@@ -114,15 +107,15 @@ func _process(_delta):
|
||||
func gun_spawn(index):
|
||||
|
||||
#loop around if scrolling past available guns
|
||||
if index > held_guns.size() - 1:
|
||||
if index > GameGlobals.held_guns.size() - 1:
|
||||
index = 0
|
||||
elif index < 0:
|
||||
index = held_guns.size() - 1
|
||||
index = GameGlobals.held_guns.size() - 1
|
||||
|
||||
current_gun_index = index
|
||||
GameGlobals.current_gun_index = index
|
||||
|
||||
if held_guns != []:
|
||||
var instance_gun = held_guns[index].instantiate()
|
||||
if GameGlobals.held_guns != []:
|
||||
var instance_gun = GameGlobals.held_guns[index].instantiate()
|
||||
instance_gun.global_transform.origin = player.weapon_spawner.position
|
||||
player.gun = instance_gun
|
||||
player.def_weapon_holder_pos = player.weapon_holder.position
|
||||
@@ -142,13 +135,12 @@ func enemy_count():
|
||||
cleared()
|
||||
|
||||
func cleared():
|
||||
var clearedmsg = CLEARED_ANNOUNCE.instantiate()
|
||||
get_parent().add_child(clearedmsg)
|
||||
await get_tree().create_timer(1).timeout
|
||||
clearedmsg.queue_free()
|
||||
pass
|
||||
|
||||
func die():
|
||||
#record stats
|
||||
GameGlobals.money_penalty()
|
||||
GameGlobals.weapon_penalty()
|
||||
if SaveLoad.player_deaths:
|
||||
SaveLoad.player_deaths += 1
|
||||
else:
|
||||
@@ -184,14 +176,14 @@ func pickup_spawn(randomized):
|
||||
pickup_type = randi_range(0,3)
|
||||
#if item type is ammo, pick random ammo
|
||||
if pickup_type == 0:
|
||||
var player_ammo = player.ammo_reserve.keys()
|
||||
var player_ammo = GameGlobals.ammo_reserve.keys()
|
||||
ammo_type = int(player_ammo.pick_random())
|
||||
#random value of pickup
|
||||
value = randi_range(1,50)
|
||||
else:
|
||||
var health_weight
|
||||
if gamemode.health_drop_enabled:
|
||||
health_weight = (1.0 - (health / gamemode.start_health)) + drop_chance_minimum
|
||||
health_weight = (1.0 - (GameGlobals.health / gamemode.start_health)) + drop_chance_minimum
|
||||
else:
|
||||
health_weight = 0
|
||||
var stamina_weight
|
||||
@@ -201,7 +193,7 @@ func pickup_spawn(randomized):
|
||||
stamina_weight = 0
|
||||
var money_weight
|
||||
if money_drop_enabled:
|
||||
money_weight = (1.0 - clamp(float(money) / float(500),0,1)) + drop_chance_minimum #fix this logic later once the economy makes sense
|
||||
money_weight = (1.0 - clamp(float(GameGlobals.money) / float(500),0,1)) + drop_chance_minimum #fix this logic later once the economy makes sense
|
||||
else:
|
||||
money_weight = 0
|
||||
var ammo_weight
|
||||
@@ -212,19 +204,19 @@ func pickup_spawn(randomized):
|
||||
|
||||
# weight ammo player owns against expected ammo values
|
||||
if ammo_drop_enabled:
|
||||
for i in player.ammo_reserve.keys():
|
||||
for i in GameGlobals.ammo_reserve.keys():
|
||||
var i_weight
|
||||
match int(i):
|
||||
0:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["light"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["light"]),0,1)
|
||||
1:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["medium"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["medium"]),0,1)
|
||||
2:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["heavy"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["heavy"]),0,1)
|
||||
3:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["shotgun"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["shotgun"]),0,1)
|
||||
4:
|
||||
i_weight = 1.0 - clamp(float(player.ammo_reserve[str(i)]) / float(expected_ammo["rocket"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["rocket"]),0,1)
|
||||
5:
|
||||
i_weight = 0
|
||||
if i_weight > ammo_weight:
|
||||
|
||||
Reference in New Issue
Block a user