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:
|
||||
|
||||
@@ -1,3 +1,40 @@
|
||||
extends Node
|
||||
|
||||
var game_loaded = false
|
||||
var high_score = 0
|
||||
var money = 0
|
||||
var health
|
||||
var held_guns = []
|
||||
var current_gun_index
|
||||
var gun_ammo = {}
|
||||
var ammo_reserve = {}
|
||||
|
||||
func _ready() -> void:
|
||||
SignalBus.money_changed.connect(money_update)
|
||||
|
||||
func money_update():
|
||||
if money > high_score:
|
||||
high_score = money
|
||||
|
||||
func money_penalty():
|
||||
var level_control = get_tree().current_scene
|
||||
|
||||
#Save High Scores
|
||||
if money >= high_score:
|
||||
high_score = money
|
||||
|
||||
#Do money penalty
|
||||
money = money * level_control.gamemode.money_lost_multiplier
|
||||
|
||||
func weapon_penalty():
|
||||
var level_control = get_tree().current_scene
|
||||
|
||||
match level_control.gamemode.weapon_penalty:
|
||||
0: #Drop All
|
||||
GameGlobals.held_guns = []
|
||||
1: #Drop Percentage
|
||||
var weapons_lost = GameGlobals.held_guns.size() * level_control.gamemode.weapon_drop_percentage
|
||||
for weapon in weapons_lost:
|
||||
GameGlobals.held_guns.erase(GameGlobals.held_guns.pick_random())
|
||||
2: #Do Nothing
|
||||
pass
|
||||
|
||||
@@ -75,17 +75,17 @@ func _process(_delta):
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
if GameGlobals.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
GameGlobals.gun_ammo[gun_name] += max_ammo
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
else:
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
GameGlobals.gun_ammo[gun_name] += GameGlobals.ammo_reserve[str(ammo_type)]
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] -= GameGlobals.ammo_reserve[str(ammo_type)]
|
||||
|
||||
func shoot(delta):
|
||||
if player.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if GameGlobals.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
GameGlobals.gun_ammo[gun_name] -= 1
|
||||
#audio and anims
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
audio_fire.play()
|
||||
@@ -108,15 +108,15 @@ func shoot(delta):
|
||||
audio_empty.play()
|
||||
|
||||
func reload():
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
if GameGlobals.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and GameGlobals.ammo_reserve[str(ammo_type)] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if player.gun_ammo[gun_name] == 0:
|
||||
player.gun_ammo[gun_name] = 0
|
||||
if GameGlobals.gun_ammo[gun_name] == 0:
|
||||
GameGlobals.gun_ammo[gun_name] = 0
|
||||
else:
|
||||
player.gun_ammo[gun_name] = 1
|
||||
GameGlobals.gun_ammo[gun_name] = 1
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = mag.instantiate()
|
||||
|
||||
@@ -84,20 +84,20 @@ func _process(delta: float) -> void:
|
||||
gun_info.visible = true
|
||||
|
||||
#HEALTH
|
||||
health_bar.value = level_control.health
|
||||
if level_control.health <= 2:
|
||||
health_bar.value = GameGlobals.health
|
||||
if GameGlobals.health <= 2:
|
||||
change_color(health_bar,RED_COLOR,10,delta)
|
||||
health_bar.position = health_bar_start_pos + shake_element(15)
|
||||
elif level_control.health < ((level_control.gamemode.start_health / 2) + 1):
|
||||
elif GameGlobals.health < ((level_control.gamemode.start_health / 2) + 1):
|
||||
change_color(health_bar,ORANGE_COLOR,10,delta)
|
||||
else:
|
||||
change_color(health_bar,FULL_WHITE,10,delta)
|
||||
|
||||
#MONEY
|
||||
if money_count < level_control.money:
|
||||
if money_count < int(GameGlobals.money):
|
||||
money_count += 1
|
||||
change_color(money,GREEN_COLOR,10,delta)
|
||||
elif money_count > level_control.money:
|
||||
elif money_count > int(GameGlobals.money):
|
||||
change_color(money,RED_COLOR,10,delta)
|
||||
money_count -= 1
|
||||
else:
|
||||
@@ -111,12 +111,12 @@ func _process(delta: float) -> void:
|
||||
current_stam_bar.value = player.remaining_stamina
|
||||
|
||||
if player.gun != null:
|
||||
if player.gun_ammo.has(player.gun.gun_name):
|
||||
ammo_current.text = str(player.gun_ammo[player.gun.gun_name]).pad_zeros(2)
|
||||
lerp_color(ammo_current,RED_COLOR,FULL_WHITE,player.gun_ammo[player.gun.gun_name],player.gun.max_ammo,.5)
|
||||
if player.ammo_reserve.has(str(player.gun.ammo_type)):
|
||||
ammo_reserve.text = str(player.ammo_reserve[str(player.gun.ammo_type)]).pad_zeros(3)
|
||||
lerp_color(ammo_reserve,RED_COLOR,FULL_WHITE,player.ammo_reserve[str(player.gun.ammo_type)],player.gun.max_ammo*2,.5)
|
||||
if GameGlobals.gun_ammo.has(player.gun.gun_name):
|
||||
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)
|
||||
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:
|
||||
fade_in_out(ammo_current,1,false,10,delta)
|
||||
fade_in_out(ammo_reserve,1,false,10,delta)
|
||||
|
||||
@@ -24,7 +24,7 @@ var ammo_type
|
||||
@onready var money: Node3D = $Meshes/money
|
||||
|
||||
|
||||
var magnetable = false
|
||||
var magnetable = true
|
||||
var pickupable = false
|
||||
var pick_up = false
|
||||
var rand_amt
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
extends Area3D
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
var player_exit = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
func _ready() -> void:
|
||||
SignalBus.player_exiting_tree.connect(player_exit_check)
|
||||
|
||||
func player_exit_check():
|
||||
player_exit = true
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
||||
func _on_area_exited(area):
|
||||
pass #level_control.die()
|
||||
|
||||
|
||||
|
||||
func _on_body_shape_exited(body_rid, body, body_shape_index, local_shape_index):
|
||||
level_control.die()
|
||||
func _on_body_exited(body: Node3D) -> void:
|
||||
if !player_exit:
|
||||
get_tree().current_scene.die()
|
||||
|
||||
11
scripts/level_sign.gd
Normal file
11
scripts/level_sign.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
@@ -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
|
||||
|
||||
@@ -68,20 +68,20 @@ func _process(_delta):
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
if GameGlobals.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
GameGlobals.gun_ammo[gun_name] += max_ammo
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
|
||||
else:
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
GameGlobals.gun_ammo[gun_name] += GameGlobals.ammo_reserve[str(ammo_type)]
|
||||
GameGlobals.ammo_reserve[str(ammo_type)] -= GameGlobals.ammo_reserve[str(ammo_type)]
|
||||
|
||||
|
||||
func shoot(delta):
|
||||
|
||||
if player.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if GameGlobals.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
GameGlobals.gun_ammo[gun_name] -= 1
|
||||
#RECOIL --- fix later to happen over a period of time
|
||||
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
@@ -107,15 +107,15 @@ func shoot(delta):
|
||||
audio_empty.play()
|
||||
|
||||
func reload():
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
if GameGlobals.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and GameGlobals.ammo_reserve[str(ammo_type)] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if player.gun_ammo[gun_name] == 0:
|
||||
player.gun_ammo[gun_name] = 0
|
||||
if GameGlobals.gun_ammo[gun_name] == 0:
|
||||
GameGlobals.gun_ammo[gun_name] = 0
|
||||
else:
|
||||
player.gun_ammo[gun_name] = 1
|
||||
GameGlobals.gun_ammo[gun_name] = 1
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = mag.instantiate()
|
||||
|
||||
@@ -12,8 +12,7 @@ var data_cleared
|
||||
var player_loc
|
||||
var player_rot
|
||||
var player_health
|
||||
var player_money
|
||||
var held_guns
|
||||
var player_velocity_cache
|
||||
var current_gun
|
||||
var current_ammo
|
||||
var reserve_ammo
|
||||
@@ -30,27 +29,56 @@ func _ready() -> void:
|
||||
enemies_killed = 0
|
||||
|
||||
func save_persistent_data():
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
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.velocity)
|
||||
file.store_var(GameGlobals.money)
|
||||
file.store_var(GameGlobals.health)
|
||||
file.store_var(GameGlobals.high_score)
|
||||
file.store_var(player_deaths)
|
||||
file.store_var(enemies_killed)
|
||||
file.store_var(shots_fired)
|
||||
var held_guns = save_resource_path(GameGlobals.held_guns)
|
||||
file.store_var(held_guns)
|
||||
file.store_var(GameGlobals.gun_ammo)
|
||||
file.store_var(GameGlobals.ammo_reserve)
|
||||
file.store_var(GameGlobals.current_gun_index)
|
||||
file.store_var(data_cleared)
|
||||
|
||||
file.close()
|
||||
|
||||
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_deaths = file.get_var()
|
||||
player_velocity_cache = file.get_var()
|
||||
GameGlobals.money = set_nulls_zero(file.get_var())
|
||||
print("MONEY : ", GameGlobals.money)
|
||||
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 = file.get_var()
|
||||
enemies_killed = set_nulls_zero(file.get_var())
|
||||
print("ENEMIES KILLED : " + str(enemies_killed))
|
||||
shots_fired = file.get_var()
|
||||
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)
|
||||
GameGlobals.gun_ammo = file.get_var()
|
||||
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)
|
||||
|
||||
data_cleared = file.get_var()
|
||||
file.close()
|
||||
else:
|
||||
@@ -70,18 +98,6 @@ func save_game_data(level_name):
|
||||
data_cleared = false
|
||||
player_loc = player.global_position
|
||||
player_rot = player.global_rotation
|
||||
player_health = level_control.health
|
||||
player_money = level_control.money
|
||||
held_guns = save_resource_path(level_control.held_guns)
|
||||
current_gun = level_control.current_gun_index
|
||||
current_ammo = player.gun_ammo
|
||||
reserve_ammo = player.ammo_reserve
|
||||
|
||||
#SAVE DATA
|
||||
file.store_var(player_health)
|
||||
file.store_var(player_money)
|
||||
file.store_var(held_guns)
|
||||
file.store_var(current_gun)
|
||||
|
||||
#save enemies
|
||||
var objects = get_tree().get_nodes_in_group("persist")
|
||||
@@ -111,6 +127,7 @@ func clear_persistent_data():
|
||||
file.store_var(null)
|
||||
file.store_var(null)
|
||||
file.store_var(null)
|
||||
file.store_var(null)
|
||||
|
||||
print("PERSISTENT DATA CLEARED")
|
||||
file.close()
|
||||
@@ -131,11 +148,6 @@ func load_save_game_data(level_name):
|
||||
|
||||
#GET DATA
|
||||
if !data_cleared:
|
||||
player_health = file.get_var()
|
||||
player_money = file.get_var()
|
||||
var held_guns_encoded = file.get_var()
|
||||
held_guns = load_resource_path(held_guns_encoded)
|
||||
current_gun = file.get_var()
|
||||
var current_nodes = get_tree().get_nodes_in_group("persist")
|
||||
for i in current_nodes:
|
||||
if i.is_in_group("enemy"):
|
||||
@@ -167,17 +179,7 @@ func load_save_game_data(level_name):
|
||||
if i == "filename" or i == "pos_x" or i == "pos_y" or i == "pos_z":
|
||||
continue
|
||||
new_object.set(i,node_data[i])
|
||||
|
||||
|
||||
#APPLY DATA
|
||||
level_control.health = player_health
|
||||
level_control.money = player_money
|
||||
level_control.held_guns = held_guns
|
||||
if player.gun:
|
||||
player.gun.queue_free()
|
||||
if current_gun != null:
|
||||
level_control.gun_spawn(current_gun)
|
||||
|
||||
|
||||
file.close()
|
||||
await get_tree().create_timer(1).timeout #need to fix this
|
||||
SignalBus.emit_signal("game_loaded")
|
||||
@@ -191,6 +193,12 @@ func data_validate(file,variable):
|
||||
else:
|
||||
return null
|
||||
|
||||
func set_nulls_zero(variable):
|
||||
if variable == null:
|
||||
return 0
|
||||
else:
|
||||
return variable
|
||||
|
||||
func null_data_check(variable,amount): #checks if value is null, adds the number to variable
|
||||
if variable == null:
|
||||
variable = amount
|
||||
@@ -209,11 +217,14 @@ func save_resource_path(array):
|
||||
return final_array
|
||||
|
||||
func load_resource_path(array):
|
||||
var final_array = []
|
||||
for i in array:
|
||||
var i_loaded = load(i)
|
||||
final_array.append(i_loaded)
|
||||
return final_array
|
||||
if array != null:
|
||||
var final_array = []
|
||||
for i in array:
|
||||
var i_loaded = load(i)
|
||||
final_array.append(i_loaded)
|
||||
return final_array
|
||||
else:
|
||||
return []
|
||||
|
||||
func shot_fired():
|
||||
shots_fired += 1 #null_data_check(shots_fired, 1)
|
||||
|
||||
30
scripts/scene_changer.gd
Normal file
30
scripts/scene_changer.gd
Normal file
@@ -0,0 +1,30 @@
|
||||
extends Area3D
|
||||
|
||||
@export var scene_path : String
|
||||
@export var scene_name : String
|
||||
@export var gamemode : gamemode
|
||||
@export var scene_thumbnail : Texture2D
|
||||
|
||||
var active = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if active:
|
||||
if get_tree().current_scene.gamemode.load_save == true:
|
||||
SaveLoad.save_game_data(get_tree().current_scene.get_name())
|
||||
SaveLoad.save_persistent_data()
|
||||
SignalBus.emit_signal("player_exiting_tree")
|
||||
get_tree().change_scene_to_file(scene_path)
|
||||
|
||||
|
||||
func _on_start_activation_timeout() -> void:
|
||||
active = true
|
||||
@@ -6,6 +6,8 @@ signal enemy_count_changed()
|
||||
signal game_loaded()
|
||||
|
||||
##PLAYER
|
||||
signal money_changed()
|
||||
signal player_exiting_tree()
|
||||
signal player_hit()
|
||||
signal shot_fired()
|
||||
signal enemy_hit()
|
||||
|
||||
@@ -4,6 +4,7 @@ extends Node3D
|
||||
@onready var kills: Label3D = $Kills
|
||||
@onready var deaths: Label3D = $Deaths
|
||||
@onready var shots_fired: Label3D = $"Shots Fired"
|
||||
@onready var high_score: Label3D = $"High Score"
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
|
||||
@@ -15,6 +16,7 @@ func _ready() -> void:
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
gamemode.text = str(level_control.gamemode.gamemode_name)
|
||||
high_score.text = str("HIGH SCORE : ",GameGlobals.high_score)
|
||||
kills.text = "Kills : " + str(SaveLoad.enemies_killed)
|
||||
deaths.text = "Deaths : " + str(SaveLoad.player_deaths)
|
||||
shots_fired.text = "Shots Fired : " + str(SaveLoad.shots_fired)
|
||||
|
||||
@@ -22,8 +22,8 @@ func _ready():
|
||||
|
||||
func interact():
|
||||
if active == true:
|
||||
if level_control.money >= item_price:
|
||||
level_control.money -= item_price
|
||||
if GameGlobals.money >= item_price:
|
||||
GameGlobals.money -= item_price
|
||||
anim_player.play("vend")
|
||||
price_label.text = "vending..."
|
||||
else:
|
||||
|
||||
@@ -18,18 +18,16 @@ func _process(delta):
|
||||
pass
|
||||
|
||||
func picked_up():
|
||||
for i in level_control.held_guns:
|
||||
for i in GameGlobals.held_guns:
|
||||
if i == gun_resource:
|
||||
gun_already_held = true
|
||||
|
||||
if !gun_already_held:
|
||||
var gun_info = gun_resource.instantiate()
|
||||
level_control.player.add_ammo(true,gun_info.gun_name,gun_info.ammo_type,gun_info.max_ammo,gun_info.start_mags)
|
||||
level_control.held_guns.append(gun_resource)
|
||||
GameGlobals.held_guns.append(gun_resource)
|
||||
var instance_gun = gun_resource.instantiate()
|
||||
level_control.ammo_current.append(instance_gun.max_ammo)
|
||||
level_control.ammo_reserve.append(instance_gun.max_ammo * instance_gun.start_mags)
|
||||
var weapon_id = level_control.held_guns.size() - 1
|
||||
var weapon_id = GameGlobals.held_guns.size() - 1
|
||||
if level_control.player.gun != null:
|
||||
level_control.player.gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(weapon_id)
|
||||
|
||||
@@ -120,7 +120,7 @@ func _draw():
|
||||
)
|
||||
|
||||
func update_weapon_list():
|
||||
options = level_control.held_guns
|
||||
options = GameGlobals.held_guns
|
||||
|
||||
func joypad_select():
|
||||
var joy_out = Vector2.ZERO
|
||||
|
||||
Reference in New Issue
Block a user