[f7b09c8] | 1 | extends Node
|
---|
| 2 |
|
---|
[c8c895d] | 3 |
|
---|
| 4 | # Player related universal vars
|
---|
| 5 |
|
---|
| 6 | var player_data = {}
|
---|
| 7 | var player_config = ConfigFile.new()
|
---|
| 8 | var player_filepath = "res://config/player.ini"
|
---|
| 9 | var player = "player"
|
---|
| 10 | var health = 100
|
---|
| 11 | var stamina = 100
|
---|
| 12 | var mana = 100
|
---|
| 13 | var lifeforce = 100
|
---|
| 14 | var xp = 0
|
---|
| 15 | var dead = false
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | # A variable to hold the mouse sensitivity (so Player.gd can load it)
|
---|
| 19 | var mouse_sensitivity = 8.0
|
---|
| 20 |
|
---|
| 21 | # Task updates hand off
|
---|
| 22 | var food_task = false
|
---|
| 23 |
|
---|
| 24 |
|
---|
[f7b09c8] | 25 | # The path to the title screen scene
|
---|
| 26 | const MAIN_MENU_PATH = "res://Main_Menu.tscn"
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | # ------------------------------------
|
---|
| 30 | # All of the GUI/UI related variables
|
---|
| 31 |
|
---|
| 32 | # The popup scene, and a variable to hold the popup
|
---|
| 33 | const POPUP_SCENE = preload("res://Pause_Popup.tscn")
|
---|
| 34 | var popup = null
|
---|
[994b0da] | 35 | var DEAD_SCENE = preload("res://Dead_Popup.tscn")
|
---|
[3c8ca52] | 36 |
|
---|
[f7b09c8] | 37 | # A canvas layer node so our GUI/UI is always drawn on top
|
---|
| 38 | var canvas_layer = null
|
---|
| 39 |
|
---|
| 40 | # The debug display scene, and a variable to hold the debug display
|
---|
| 41 | const DEBUG_DISPLAY_SCENE = preload("res://Debug_Display.tscn")
|
---|
| 42 | var debug_display = null
|
---|
| 43 |
|
---|
| 44 | # ------------------------------------
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | # A variable to hold all of the respawn points in a level
|
---|
| 48 | var respawn_points = null
|
---|
| 49 |
|
---|
[c8c895d] | 50 |
|
---|
[f7b09c8] | 51 |
|
---|
| 52 | # ------------------------------------
|
---|
| 53 | # All of the audio files.
|
---|
| 54 |
|
---|
| 55 | # You will need to provide your own sound files.
|
---|
| 56 | # One site I'd recommend is GameSounds.xyz. I'm using Sonniss' GDC Game Audio bundle for 2017.
|
---|
| 57 | # The tracks I've used (with some minor editing) are as follows:
|
---|
| 58 | # Gamemaster audio gun sound pack:
|
---|
| 59 | # gun_revolver_pistol_shot_04,
|
---|
| 60 | # gun_semi_auto_rifle_cock_02,
|
---|
| 61 | # gun_submachine_auto_shot_00_automatic_preview_01
|
---|
[c8c895d] | 62 | #var audio_clips = {
|
---|
| 63 | # "pistol_shot":null, #preload("res://path_to_your_audio_here!")
|
---|
| 64 | # "rifle_shot":null, #preload("res://path_to_your_audio_here!")
|
---|
| 65 | # "gun_cock":null, #preload("res://path_to_your_audio_here!")
|
---|
| 66 | #}
|
---|
[f7b09c8] | 67 |
|
---|
| 68 | # The simple audio player scene
|
---|
[c8c895d] | 69 | # const SIMPLE_AUDIO_PLAYER_SCENE = preload("res://Simple_Audio_Player.tscn")
|
---|
[f7b09c8] | 70 |
|
---|
| 71 | # A list to hold all of the created audio nodes
|
---|
[c8c895d] | 72 | # var created_audio = []
|
---|
[f7b09c8] | 73 |
|
---|
[aa1db83] | 74 | # Config file key bindings
|
---|
| 75 | var keybind_filepath = "res://config/keybinds.ini"
|
---|
| 76 | var keybind_configfile
|
---|
| 77 | var keybinds = {}
|
---|
[f7b09c8] | 78 |
|
---|
[aa1db83] | 79 | # ------------------------------------
|
---|
[f7b09c8] | 80 |
|
---|
| 81 | func _ready():
|
---|
[c8c895d] | 82 |
|
---|
[f7b09c8] | 83 | # Randomize the random number generator, so we get random values
|
---|
| 84 | randomize()
|
---|
| 85 |
|
---|
| 86 | # Make a new canvas layer.
|
---|
| 87 | # This is so our popup always appears on top of everything else
|
---|
| 88 | canvas_layer = CanvasLayer.new()
|
---|
| 89 | add_child(canvas_layer)
|
---|
| 90 |
|
---|
[c8c895d] | 91 | if player_config.load(player_filepath) == OK:
|
---|
| 92 | health = player_config.get_value(player, "health")
|
---|
| 93 | stamina = player_config.get_value(player, "stamina")
|
---|
| 94 | mana = player_config.get_value(player, "mana")
|
---|
| 95 | lifeforce = player_config.get_value(player, "lifeforce")
|
---|
| 96 | xp = player_config.get_value(player, "xp")
|
---|
| 97 | dead = player_config.get_value(player, "dead")
|
---|
| 98 |
|
---|
| 99 |
|
---|
[aa1db83] | 100 | # Loads in the keybindings
|
---|
| 101 | keybind_configfile = ConfigFile.new()
|
---|
| 102 | if keybind_configfile.load(keybind_filepath) == OK:
|
---|
| 103 | for key in keybind_configfile.get_section_keys("keybinds"):
|
---|
| 104 | var key_value = keybind_configfile.get_value("keybinds", key)
|
---|
| 105 | if str(key_value) != "":
|
---|
| 106 | keybinds[key] = key_value
|
---|
| 107 | else:
|
---|
| 108 | keybinds[key] = null
|
---|
| 109 | print(key, " : ", OS.get_scancode_string(key_value))
|
---|
| 110 | else:
|
---|
| 111 | print("Keybinds Config File Not Found")
|
---|
| 112 |
|
---|
| 113 | set_game_binds()
|
---|
| 114 |
|
---|
[994b0da] | 115 | func player_dead():
|
---|
[ef2ca13] | 116 | if popup == null:
|
---|
| 117 | # Make a new popup scene
|
---|
| 118 | popup = DEAD_SCENE.instance()
|
---|
| 119 |
|
---|
[994b0da] | 120 | # Connect the signals
|
---|
[ef2ca13] | 121 | popup.get_node("Button_quit").connect("pressed", self, "popup_quit")
|
---|
| 122 | popup.get_node("Button_respawn").connect("pressed", self, "popup_closed")
|
---|
| 123 |
|
---|
[994b0da] | 124 | # Add it as a child, and make it pop up in the center of the screen
|
---|
[ef2ca13] | 125 | canvas_layer.add_child(popup)
|
---|
| 126 | popup.popup_centered()
|
---|
| 127 |
|
---|
[994b0da] | 128 | # Make sure the mouse is visible
|
---|
| 129 | Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
---|
[ef2ca13] | 130 |
|
---|
[994b0da] | 131 | # Pause the game
|
---|
| 132 | get_tree().paused = true
|
---|
| 133 |
|
---|
[aa1db83] | 134 | # Set the keybinds
|
---|
| 135 | func set_game_binds():
|
---|
| 136 | for key in keybinds.keys():
|
---|
| 137 | var value = keybinds[key]
|
---|
| 138 |
|
---|
| 139 | var actionlist = InputMap.get_action_list(key)
|
---|
| 140 | if !actionlist.empty():
|
---|
| 141 | InputMap.action_erase_event(key, actionlist[0])
|
---|
| 142 |
|
---|
| 143 | if value != null:
|
---|
| 144 | var new_key = InputEventKey.new()
|
---|
| 145 | new_key.set_scancode(value)
|
---|
| 146 | InputMap.action_add_event(key, new_key)
|
---|
| 147 |
|
---|
| 148 | func write_config():
|
---|
| 149 | for key in keybinds.keys():
|
---|
| 150 | var key_value = keybinds[key]
|
---|
| 151 | if key_value != null:
|
---|
| 152 | keybind_configfile.set_value("keybinds", key, key_value)
|
---|
| 153 | else:
|
---|
| 154 | keybind_configfile.set_value("keybinds", key, "")
|
---|
| 155 | keybind_configfile.save(keybind_filepath)
|
---|
[f7b09c8] | 156 |
|
---|
| 157 | func get_respawn_position():
|
---|
| 158 | # If we do not have any respawn points, return origin
|
---|
| 159 | if respawn_points == null:
|
---|
| 160 | return Vector3(0, 0, 0)
|
---|
| 161 | # If we have respawn points, get a random one and return it's global position
|
---|
| 162 | else:
|
---|
| 163 | var respawn_point = rand_range(0, respawn_points.size()-1)
|
---|
| 164 | return respawn_points[respawn_point].global_transform.origin
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | func load_new_scene(new_scene_path):
|
---|
| 168 | # Set respawn points to null so when/if we get to a level with no respawn points,
|
---|
| 169 | # we do not respawn at the respawn points in the level prior.
|
---|
| 170 | respawn_points = null
|
---|
| 171 |
|
---|
| 172 | # Delete all of the sounds
|
---|
[c8c895d] | 173 | # for sound in created_audio:
|
---|
| 174 | # if (sound != null):
|
---|
| 175 | # sound.queue_free()
|
---|
| 176 | #created_audio.clear()
|
---|
[f7b09c8] | 177 |
|
---|
| 178 | # Change scenes
|
---|
| 179 | get_tree().change_scene(new_scene_path)
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | func _process(delta):
|
---|
| 183 | # If ui_cancel is pressed, we want to open a popup if one is not already open
|
---|
| 184 | if Input.is_action_just_pressed("ui_cancel"):
|
---|
| 185 | if popup == null:
|
---|
| 186 | # Make a new popup scene
|
---|
| 187 | popup = POPUP_SCENE.instance()
|
---|
| 188 |
|
---|
| 189 | # Connect the signals
|
---|
| 190 | popup.get_node("Button_quit").connect("pressed", self, "popup_quit")
|
---|
| 191 | popup.connect("popup_hide", self, "popup_closed")
|
---|
| 192 | popup.get_node("Button_resume").connect("pressed", self, "popup_closed")
|
---|
| 193 |
|
---|
| 194 | # Add it as a child, and make it pop up in the center of the screen
|
---|
| 195 | canvas_layer.add_child(popup)
|
---|
| 196 | popup.popup_centered()
|
---|
| 197 |
|
---|
| 198 | # Make sure the mouse is visible
|
---|
| 199 | Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
---|
| 200 |
|
---|
| 201 | # Pause the game
|
---|
| 202 | get_tree().paused = true
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | func popup_closed():
|
---|
| 206 | # Unpause the game
|
---|
| 207 | get_tree().paused = false
|
---|
| 208 |
|
---|
| 209 | # If we have a popup, destoy it
|
---|
| 210 | if popup != null:
|
---|
| 211 | popup.queue_free()
|
---|
| 212 | popup = null
|
---|
[ef2ca13] | 213 | # Re-captures mouse when returning to game
|
---|
| 214 | if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE:
|
---|
| 215 | Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
---|
[f7b09c8] | 216 |
|
---|
| 217 | func popup_quit():
|
---|
| 218 | get_tree().paused = false
|
---|
| 219 |
|
---|
| 220 | # Make sure the mouse is visible
|
---|
| 221 | Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
---|
| 222 |
|
---|
| 223 | # If we have a popup, destoy it
|
---|
| 224 | if popup != null:
|
---|
| 225 | popup.queue_free()
|
---|
| 226 | popup = null
|
---|
| 227 |
|
---|
| 228 | # Go back to the title screen scene
|
---|
| 229 | load_new_scene(MAIN_MENU_PATH)
|
---|
| 230 |
|
---|
| 231 |
|
---|
| 232 | func set_debug_display(display_on):
|
---|
| 233 | # If we are turning off the debug display
|
---|
| 234 | if display_on == false:
|
---|
| 235 | # If we have a debug display, then free it and set debug_display to null
|
---|
| 236 | if debug_display != null:
|
---|
| 237 | debug_display.queue_free()
|
---|
| 238 | debug_display = null
|
---|
| 239 | # If we are turning on the debug display
|
---|
| 240 | else:
|
---|
| 241 | # If we do not have a debug display, instance/spawn a new one and set it to debug_display
|
---|
| 242 | if debug_display == null:
|
---|
| 243 | debug_display = DEBUG_DISPLAY_SCENE.instance()
|
---|
| 244 | canvas_layer.add_child(debug_display)
|
---|