source: Studio/Globals.gd@ 25e7b67

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

Got Food item to increase player stats by 10 when walking into the food space.

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