source: Studio/Globals.gd@ 0249beb

sandbox
Last change on this file since 0249beb was f7b09c8, checked in by Kevin Chapman <victory2b@…>, 4 years ago

First Draft of world test with working movement and loading screen.

  • Property mode set to 100644
File size: 5.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
13
14# A canvas layer node so our GUI/UI is always drawn on top
15var canvas_layer = null
16
17# The debug display scene, and a variable to hold the debug display
18const DEBUG_DISPLAY_SCENE = preload("res://Debug_Display.tscn")
19var debug_display = null
20
21# ------------------------------------
22
23
24# A variable to hold all of the respawn points in a level
25var respawn_points = null
26
27# A variable to hold the mouse sensitivity (so Player.gd can load it)
28var mouse_sensitivity = 0.08
29# A variable to hold the joypad sensitivity (so Player.gd can load it)
30var joypad_sensitivity = 2
31
32
33# ------------------------------------
34# All of the audio files.
35
36# You will need to provide your own sound files.
37# One site I'd recommend is GameSounds.xyz. I'm using Sonniss' GDC Game Audio bundle for 2017.
38# The tracks I've used (with some minor editing) are as follows:
39# Gamemaster audio gun sound pack:
40# gun_revolver_pistol_shot_04,
41# gun_semi_auto_rifle_cock_02,
42# gun_submachine_auto_shot_00_automatic_preview_01
43var audio_clips = {
44 "pistol_shot":null, #preload("res://path_to_your_audio_here!")
45 "rifle_shot":null, #preload("res://path_to_your_audio_here!")
46 "gun_cock":null, #preload("res://path_to_your_audio_here!")
47}
48
49# The simple audio player scene
50const SIMPLE_AUDIO_PLAYER_SCENE = preload("res://Simple_Audio_Player.tscn")
51
52# A list to hold all of the created audio nodes
53var created_audio = []
54
55# ------------------------------------
56
57
58func _ready():
59 # Randomize the random number generator, so we get random values
60 randomize()
61
62 # Make a new canvas layer.
63 # This is so our popup always appears on top of everything else
64 canvas_layer = CanvasLayer.new()
65 add_child(canvas_layer)
66
67
68
69func get_respawn_position():
70 # If we do not have any respawn points, return origin
71 if respawn_points == null:
72 return Vector3(0, 0, 0)
73 # If we have respawn points, get a random one and return it's global position
74 else:
75 var respawn_point = rand_range(0, respawn_points.size()-1)
76 return respawn_points[respawn_point].global_transform.origin
77
78
79func load_new_scene(new_scene_path):
80 # Set respawn points to null so when/if we get to a level with no respawn points,
81 # we do not respawn at the respawn points in the level prior.
82 respawn_points = null
83
84 # Delete all of the sounds
85 for sound in created_audio:
86 if (sound != null):
87 sound.queue_free()
88 created_audio.clear()
89
90 # Change scenes
91 get_tree().change_scene(new_scene_path)
92
93
94func _process(delta):
95 # If ui_cancel is pressed, we want to open a popup if one is not already open
96 if Input.is_action_just_pressed("ui_cancel"):
97 if popup == null:
98 # Make a new popup scene
99 popup = POPUP_SCENE.instance()
100
101 # Connect the signals
102 popup.get_node("Button_quit").connect("pressed", self, "popup_quit")
103 popup.connect("popup_hide", self, "popup_closed")
104 popup.get_node("Button_resume").connect("pressed", self, "popup_closed")
105
106 # Add it as a child, and make it pop up in the center of the screen
107 canvas_layer.add_child(popup)
108 popup.popup_centered()
109
110 # Make sure the mouse is visible
111 Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
112
113 # Pause the game
114 get_tree().paused = true
115
116
117func popup_closed():
118 # Unpause the game
119 get_tree().paused = false
120
121 # If we have a popup, destoy it
122 if popup != null:
123 popup.queue_free()
124 popup = null
125
126func popup_quit():
127 get_tree().paused = false
128
129 # Make sure the mouse is visible
130 Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
131
132 # If we have a popup, destoy it
133 if popup != null:
134 popup.queue_free()
135 popup = null
136
137 # Go back to the title screen scene
138 load_new_scene(MAIN_MENU_PATH)
139
140
141func set_debug_display(display_on):
142 # If we are turning off the debug display
143 if display_on == false:
144 # If we have a debug display, then free it and set debug_display to null
145 if debug_display != null:
146 debug_display.queue_free()
147 debug_display = null
148 # If we are turning on the debug display
149 else:
150 # If we do not have a debug display, instance/spawn a new one and set it to debug_display
151 if debug_display == null:
152 debug_display = DEBUG_DISPLAY_SCENE.instance()
153 canvas_layer.add_child(debug_display)
154
155
156func play_sound(sound_name, loop_sound=false, sound_position=null):
157 # If we have a audio clip with with the name sound_name
158 if audio_clips.has(sound_name):
159 # Make a new simple audio player and set it's looping variable to the loop_sound
160 var new_audio = SIMPLE_AUDIO_PLAYER_SCENE.instance()
161 new_audio.should_loop = loop_sound
162
163 # Add it as a child and add it to created_audio
164 add_child(new_audio)
165 created_audio.append(new_audio)
166
167 # Send the newly created simple audio player the audio stream and sound position
168 new_audio.play_sound(audio_clips[sound_name], sound_position)
169
170 # If we do not have an audio clip with the name sound_name, print a error message
171 else:
172 print ("ERROR: cannot play sound that does not exist in audio_clips!")
173
174
Note: See TracBrowser for help on using the repository browser.