substantial work on saving and loading and hub mechanic

This commit is contained in:
Derek
2025-02-22 17:09:47 -06:00
parent 777063ddeb
commit 3ee1f261d1
31 changed files with 584 additions and 212 deletions

View File

@@ -73,8 +73,6 @@ var instance_bullet
var instance_casing
var instance_mag
var reloading = false
var gun_ammo = {}
var ammo_reserve = {}
var bullet_damage
var def_weapon_holder_pos : Vector3
var weapon_holder_start_rot
@@ -314,8 +312,8 @@ func _physics_process(delta):
camera.fov = lerp(camera.fov, target_fov, delta * 8)
# Health Indicator
var health_opacity = 1.5 - level_control.health / level_control.gamemode.start_health
if level_control.health < (level_control.gamemode.start_health/2):
var health_opacity = 1.5 - GameGlobals.health / level_control.gamemode.start_health
if GameGlobals.health < (level_control.gamemode.start_health/2):
health_indicator.color = lerp(Color(0.471, 0, 0, 0), Color(0.471, 0, 0, .25),health_opacity)
else:
health_indicator.color = Color(0.471, 0, 0, 0)
@@ -414,8 +412,8 @@ func _physics_process(delta):
if gun != null:
if !gun.anim_player.is_playing():
if held_item == null:
if level_control.held_guns.size() > 1:
weapon_select(level_control.current_gun_index + 1)
if GameGlobals.held_guns.size() > 1:
weapon_select(GameGlobals.current_gun_index + 1)
else:
moveable_holder.rotation.y += deg_to_rad(45)
else:
@@ -427,8 +425,8 @@ func _physics_process(delta):
if gun != null:
if !gun.anim_player.is_playing():
if held_item == null:
if level_control.held_guns.size() > 1:
weapon_select(level_control.current_gun_index - 1)
if GameGlobals.held_guns.size() > 1:
weapon_select(GameGlobals.current_gun_index - 1)
else:
moveable_holder.rotation.y -= deg_to_rad(45)
else:
@@ -439,7 +437,7 @@ func _physics_process(delta):
if Input.is_action_just_pressed("numb_" + str(i)):
if gun != null:
if !gun.anim_player.is_playing():
if i-1 != level_control.current_gun_index and i <= level_control.held_guns.size():
if i-1 != GameGlobals.current_gun_index and i <= GameGlobals.held_guns.size():
weapon_select((i - 1))
if Input.is_action_just_pressed("holster"):
@@ -455,7 +453,7 @@ func _physics_process(delta):
Engine.time_scale = .01
elif Input.is_action_just_released("weapon_select"):
var selection = weapon_select_menu.close()
if selection != null and selection != level_control.current_gun_index :
if selection != null and selection != GameGlobals.current_gun_index :
weapon_select(selection)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
gamespeed_controlled = false
@@ -487,9 +485,9 @@ func _physics_process(delta):
animation_player.play("punch")
if Input.is_action_just_pressed("kill_self"):
level_control.health = 0
GameGlobals.health = 0
if level_control.health <= 0:
if GameGlobals.health <= 0:
level_control.die()
focus_on_target()
@@ -660,7 +658,7 @@ func holster_gun(holster):
if holster:
gun_is_holstered = true
if gun != null:
holstered_gun_id = level_control.current_gun_index
holstered_gun_id = GameGlobals.current_gun_index
gun.anim_player.play("swap_out")
else:
gun_is_holstered = false
@@ -669,20 +667,20 @@ func holster_gun(holster):
func add_ammo(new_gun,gun_name,ammo_type,max_ammo,start_mags):
if new_gun:
gun_ammo[gun_name] = max_ammo
GameGlobals.gun_ammo[gun_name] = max_ammo
if ammo_reserve.has(str(ammo_type)):
ammo_reserve[str(ammo_type)] += start_mags * max_ammo
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:
ammo_reserve[str(ammo_type)] = 0
GameGlobals.ammo_reserve[str(ammo_type)] = 0
#otherwise calculate starting ammo
else:
ammo_reserve[str(ammo_type)] = start_mags * max_ammo
GameGlobals.ammo_reserve[str(ammo_type)] = start_mags * max_ammo
print("GUN AMMO ",gun_ammo)
print("RESERVE AMMO ", ammo_reserve)
print("GUN AMMO ",GameGlobals.gun_ammo)
print("RESERVE AMMO ", GameGlobals.ammo_reserve)
## MISC
@@ -712,16 +710,17 @@ func pickup_apply(type,ammo_type,value):
match type:
0: #AMMO
if ammo_reserve.has(str(ammo_type)):
ammo_reserve[str(ammo_type)] += value
if GameGlobals.ammo_reserve.has(str(ammo_type)):
GameGlobals.ammo_reserve[str(ammo_type)] += value
else:
ammo_reserve[str(ammo_type)] = value
GameGlobals.ammo_reserve[str(ammo_type)] = value
1: #STAMINA
remaining_stamina = clamp(remaining_stamina + value,0,100)
2: #HEALTH
level_control.health = clamp(level_control.health + value,0,level_control.gamemode.start_health)
GameGlobals.health = clamp(GameGlobals.health + value,0,level_control.gamemode.start_health)
3: #MONEY
level_control.money += value
GameGlobals.money += value * level_control.gamemode.money_multiplier
SignalBus.emit_signal("money_changed")
func focus_on_target():
@@ -793,7 +792,7 @@ func toggle_hud(hud_on):
func hit(damage, fired_by, target_type):
SignalBus.emit_signal("player_hit")
level_control.health -= damage
GameGlobals.health -= damage
level_control.last_hit = fired_by
level_control.target_type = target_type
recoil.add_recoil(Vector3(.5,.1,.1),10,10)
@@ -815,7 +814,5 @@ func save():
"rot_z" : rotation.z,
"crouched" : crouched,
"flashlight_on" : flashlight_on,
"gun_ammo" : gun_ammo,
"ammo_reserve" : ammo_reserve
}
return save_dict