source: Studio/Globals.gd@ 5a9a237

sandbox
Last change on this file since 5a9a237 was c8c895d, checked in by Kevin Chapman <victory2b@…>, 3 years ago

Updated the INI file to hold the basic player stats like health. Made the slider for the mouse sensitivity work

  • Property mode set to 100644
File size: 6.8 KB
RevLine 
[f7b09c8]1extends Node
2
[c8c895d]3
4# Player related universal vars
5
6var player_data = {}
7var player_config = ConfigFile.new()
8var player_filepath = "res://config/player.ini"
9var player = "player"
10var health = 100
11var stamina = 100
12var mana = 100
13var lifeforce = 100
14var xp = 0
15var dead = false
16
17
18# A variable to hold the mouse sensitivity (so Player.gd can load it)
19var mouse_sensitivity = 8.0
20
21# Task updates hand off
22var food_task = false
23
24
[f7b09c8]25# The path to the title screen scene
26const 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
33const POPUP_SCENE = preload("res://Pause_Popup.tscn")
34var popup = null
[994b0da]35var DEAD_SCENE = preload("res://Dead_Popup.tscn")
[3c8ca52]36
[f7b09c8]37# A canvas layer node so our GUI/UI is always drawn on top
38var canvas_layer = null
39
40# The debug display scene, and a variable to hold the debug display
41const DEBUG_DISPLAY_SCENE = preload("res://Debug_Display.tscn")
42var debug_display = null
43
44# ------------------------------------
45
46
47# A variable to hold all of the respawn points in a level
48var 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
75var keybind_filepath = "res://config/keybinds.ini"
76var keybind_configfile
77var keybinds = {}
[f7b09c8]78
[aa1db83]79# ------------------------------------
[f7b09c8]80
81func _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]115func 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
135func 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
148func 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
157func 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
167func 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
182func _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
205func 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
217func 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
232func 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)
Note: See TracBrowser for help on using the repository browser.