added main menu and can continue from last level
This commit is contained in:
@@ -35,6 +35,12 @@ 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()
|
||||
GameGlobals.current_level = str(self.scene_file_path)
|
||||
|
||||
if GameGlobals.loading_gamemode != null:
|
||||
gamemode = GameGlobals.loading_gamemode
|
||||
GameGlobals.loading_gamemode = null
|
||||
|
||||
#connect to signals
|
||||
SignalBus.enemy_count_changed.connect(enemy_count)
|
||||
|
||||
@@ -60,6 +66,8 @@ func _ready():
|
||||
if crown_target:
|
||||
crown_target.add_child(crown_spawn)
|
||||
crown_spawn.position = Vector3(0,2,0)
|
||||
if crown_target.is_in_group("enemy"):
|
||||
crown_target.loot_amount = 10
|
||||
#global randomize function
|
||||
randomize()
|
||||
|
||||
@@ -208,19 +216,20 @@ func pickup_spawn(randomized):
|
||||
var i_weight
|
||||
match int(i):
|
||||
0:
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["light"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(gamemode.expected_ammo["light"]),0,1)
|
||||
1:
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["medium"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(gamemode.expected_ammo["medium"]),0,1)
|
||||
2:
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["heavy"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(gamemode.expected_ammo["heavy"]),0,1)
|
||||
3:
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["shotgun"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(gamemode.expected_ammo["shotgun"]),0,1)
|
||||
4:
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(expected_ammo["rocket"]),0,1)
|
||||
i_weight = 1.0 - clamp(float(GameGlobals.ammo_reserve[str(i)]) / float(gamemode.expected_ammo["rocket"]),0,1)
|
||||
5:
|
||||
i_weight = 0
|
||||
if i_weight > ammo_weight:
|
||||
ammo_weight = i_weight
|
||||
ammo_type_weight.erase(5)
|
||||
ammo_type_weight[i] = i_weight + drop_chance_minimum
|
||||
|
||||
pickup_type = HelperFuncs.weighted_random({"0" : ammo_weight, "1" : stamina_weight,"2" : health_weight,"3" : money_weight})
|
||||
@@ -244,5 +253,6 @@ func pickup_spawn(randomized):
|
||||
return {"pickup_type" : pickup_type,"ammo_type" : ammo_type,"value" : value}
|
||||
|
||||
func save_quit():
|
||||
SignalBus.emit_signal("player_exiting_tree")
|
||||
SaveLoad.save_game_data(level_name)
|
||||
get_tree().quit()
|
||||
|
||||
@@ -9,14 +9,24 @@ var held_guns = []
|
||||
var current_gun_index
|
||||
var gun_ammo = {}
|
||||
var ammo_reserve = {}
|
||||
var loading_gamemode
|
||||
var current_level
|
||||
var current_gamemode
|
||||
|
||||
#Player Stats
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
SignalBus.money_deposited.connect(deposit_money)
|
||||
|
||||
func deposit_money():
|
||||
deposited_money = money
|
||||
if money > deposited_money:
|
||||
deposited_money = money
|
||||
if deposited_money > high_score:
|
||||
high_score = deposited_money
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
#print("current level : ",get_tree().current_scene.scene_file_path)
|
||||
|
||||
func money_penalty():
|
||||
var level_control = get_tree().current_scene
|
||||
|
||||
@@ -111,12 +111,16 @@ func _process(delta: float) -> void:
|
||||
current_stam_bar.value = player.remaining_stamina
|
||||
|
||||
if player.gun != null:
|
||||
if GameGlobals.gun_ammo.has(player.gun.gun_name):
|
||||
if GameGlobals.gun_ammo.has(player.gun.gun_name) and GameGlobals.gun_ammo[player.gun.gun_name] != null:
|
||||
ammo_current.text = str(GameGlobals.gun_ammo[player.gun.gun_name]).pad_zeros(2)
|
||||
lerp_color(ammo_current,RED_COLOR,FULL_WHITE,GameGlobals.gun_ammo[player.gun.gun_name],player.gun.max_ammo,.5)
|
||||
else:
|
||||
ammo_current.text = "-"
|
||||
if GameGlobals.ammo_reserve.has(str(player.gun.ammo_type)):
|
||||
ammo_reserve.text = str(GameGlobals.ammo_reserve[str(player.gun.ammo_type)]).pad_zeros(3)
|
||||
lerp_color(ammo_reserve,RED_COLOR,FULL_WHITE,GameGlobals.ammo_reserve[str(player.gun.ammo_type)],player.gun.max_ammo*2,.5)
|
||||
else:
|
||||
ammo_reserve.text = "-"
|
||||
else:
|
||||
fade_in_out(ammo_current,1,false,10,delta)
|
||||
fade_in_out(ammo_reserve,1,false,10,delta)
|
||||
|
||||
@@ -9,7 +9,7 @@ extends Node3D
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
level_name.text = portal_node.scene_name
|
||||
gamemode_label.text = portal_node.gamemode.gamemode_name
|
||||
gamemode_label.text = portal_node.level_gamemode.gamemode_name
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
25
scripts/main_menu.gd
Normal file
25
scripts/main_menu.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends Node
|
||||
|
||||
var last_scene
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
SaveLoad.load_persistent_data()
|
||||
|
||||
func _on_continue_pressed() -> void:
|
||||
var level
|
||||
var load_to_gamemode
|
||||
|
||||
if GameGlobals.current_level == null:
|
||||
level = "res://scenes/HUBWORLD.tscn"
|
||||
load_to_gamemode = "res://GameModes/hubworld.tres"
|
||||
else:
|
||||
level = GameGlobals.current_level
|
||||
load_to_gamemode = GameGlobals.current_gamemode
|
||||
|
||||
get_tree().change_scene_to_file(level)
|
||||
GameGlobals.loading_gamemode = load(load_to_gamemode)
|
||||
print("LEVEL : ",GameGlobals.current_level)
|
||||
|
||||
func _on_exit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
@@ -667,14 +667,16 @@ func holster_gun(holster):
|
||||
|
||||
func add_ammo(new_gun,gun_name,ammo_type,max_ammo,start_mags):
|
||||
if new_gun:
|
||||
GameGlobals.gun_ammo[gun_name] = max_ammo
|
||||
|
||||
if ammo_type != 5: #if ammo is not melee
|
||||
GameGlobals.gun_ammo[gun_name] = max_ammo
|
||||
else:
|
||||
GameGlobals.gun_ammo[gun_name] = null
|
||||
if GameGlobals.ammo_reserve.has(str(ammo_type)):
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] += start_mags * max_ammo
|
||||
else:
|
||||
#if melee weapon don't do max ammo calc
|
||||
if ammo_type == 5:
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] = 0
|
||||
pass
|
||||
#otherwise calculate starting ammo
|
||||
else:
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] = start_mags * max_ammo
|
||||
|
||||
@@ -35,7 +35,10 @@ func save_persistent_data():
|
||||
print("LAST HIT PATH " + str(last_hit_path))
|
||||
file.store_var(last_hit_path)
|
||||
file.store_var(player.velocity)
|
||||
file.store_var(get_tree().current_scene.scene_file_path)
|
||||
file.store_var(get_tree().current_scene.gamemode.resource_path)
|
||||
file.store_var(GameGlobals.money)
|
||||
file.store_var(GameGlobals.deposited_money)
|
||||
file.store_var(GameGlobals.health)
|
||||
file.store_var(GameGlobals.high_score)
|
||||
file.store_var(player_deaths)
|
||||
@@ -52,24 +55,20 @@ func save_persistent_data():
|
||||
|
||||
func load_persistent_data():
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
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_velocity_cache = file.get_var()
|
||||
GameGlobals.current_level = str(file.get_var())
|
||||
GameGlobals.current_gamemode = file.get_var()
|
||||
GameGlobals.money = set_nulls_zero(file.get_var())
|
||||
print("MONEY : ", GameGlobals.money)
|
||||
GameGlobals.deposited_money = set_nulls_zero(file.get_var())
|
||||
GameGlobals.health = file.get_var()
|
||||
print("HEALTH : ", GameGlobals.health)
|
||||
GameGlobals.high_score = file.get_var()
|
||||
print("HIGH SCORE : ",GameGlobals.high_score)
|
||||
player_deaths = set_nulls_zero(file.get_var())
|
||||
print("PLAYER DEATHS : " + str(player_deaths))
|
||||
enemies_killed = set_nulls_zero(file.get_var())
|
||||
print("ENEMIES KILLED : " + str(enemies_killed))
|
||||
shots_fired = set_nulls_zero(file.get_var())
|
||||
print("SHOTS FIRED ",shots_fired)
|
||||
|
||||
|
||||
var held_guns_encoded = file.get_var()
|
||||
GameGlobals.held_guns = load_resource_path(held_guns_encoded)
|
||||
@@ -77,7 +76,8 @@ func load_persistent_data():
|
||||
GameGlobals.ammo_reserve = file.get_var()
|
||||
GameGlobals.current_gun_index = file.get_var()
|
||||
if GameGlobals.current_gun_index != null:
|
||||
get_tree().current_scene.gun_spawn(GameGlobals.current_gun_index)
|
||||
if !get_tree().current_scene.is_in_group("ui"):
|
||||
get_tree().current_scene.gun_spawn(GameGlobals.current_gun_index)
|
||||
|
||||
data_cleared = file.get_var()
|
||||
file.close()
|
||||
|
||||
@@ -2,7 +2,7 @@ extends Area3D
|
||||
|
||||
@export var scene_path : String
|
||||
@export var scene_name : String
|
||||
@export var gamemode : gamemode
|
||||
@export var level_gamemode : gamemode
|
||||
@export var scene_thumbnail : Texture2D
|
||||
|
||||
var active = false
|
||||
@@ -19,7 +19,11 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if active:
|
||||
#Let the Bounds detector know player is exiting
|
||||
SignalBus.emit_signal("player_exiting_tree")
|
||||
#Set incoming gamemode
|
||||
GameGlobals.loading_gamemode = level_gamemode
|
||||
#Save data
|
||||
if get_tree().current_scene.gamemode.load_save == true:
|
||||
SaveLoad.save_game_data(get_tree().current_scene.get_name())
|
||||
SaveLoad.save_persistent_data()
|
||||
|
||||
@@ -45,10 +45,17 @@ func vend():
|
||||
##SET VARIABLES
|
||||
item_vend.pickup_type = pickup_type
|
||||
if level_control.player.gun != null:
|
||||
item_vend.ammo_type = level_control.player.gun.ammo_type
|
||||
if level_control.player.gun.ammo_type != 5:
|
||||
item_vend.ammo_type = level_control.player.gun.ammo_type
|
||||
else:
|
||||
item_vend.ammo_type = item_stats["ammo_type"]
|
||||
item_vend.value = pickup_amount
|
||||
if pickup_type == 0:
|
||||
if level_control.player.gun != null:
|
||||
item_vend.value = level_control.player.gun.max_ammo
|
||||
else:
|
||||
item_vend.value = item_stats["value"]
|
||||
else:
|
||||
item_vend.value = pickup_amount
|
||||
print("ITEM : ",item_vend.pickup_type,item_vend.ammo_type,item_vend.value)
|
||||
else:
|
||||
item_vend = item.instantiate()
|
||||
|
||||
Reference in New Issue
Block a user