Adding global variables

This commit is contained in:
Jonathan Herrewijnen 2022-10-13 17:09:42 +02:00
parent 57b312a3a5
commit 645b252da9
8 changed files with 34 additions and 30 deletions

View File

@ -11,6 +11,14 @@ var dev_stats = true
var dbname = "storage.db" var dbname = "storage.db"
var mainscene = "" var mainscene = ""
var base_tilemap = preload("res://Other/base_tilemap/base_tilemap.tscn") var base_tilemap = preload("res://Other/base_tilemap/base_tilemap.tscn")
var map_name
func load_scene(map_data):
map_name = map_data
var scene = load(map_data+".tscn")
print("MAP NAME ",map_data+".tscn")
var map = scene.instance()
return map
func AddInventoryItem(itemid, amount): func AddInventoryItem(itemid, amount):
for x in range(40): for x in range(40):

View File

@ -1,5 +1,5 @@
extends Node2D extends Node2D
#Global functions for the game, like speech bubbles and sounds const gamevariables = "res://MiscScenes/GameVariables.tscn"
func RenderSpeech(load_on, text): func RenderSpeech(load_on, text):
var speech = preload("res://MiscScenes/Speech.tscn").instance() var speech = preload("res://MiscScenes/Speech.tscn").instance()
@ -8,9 +8,7 @@ func RenderSpeech(load_on, text):
load_on.add_child(speech) load_on.add_child(speech)
func SoundOnInteraction(load_on, sound_name): func SoundOnInteraction(load_on, sound_name):
var audio = preload("res://MiscScenes/Sound.tscn").instance() var audio = preload(gamevariables).instance().get_node("Sound")
var format_string = "res://Sounds/%s.wav" audio.stream = load("res://Sounds/%s.wav" % sound_name)
var actual_string = format_string % sound_name
var Sound = load(actual_string)
audio.stream = Sound
load_on.add_child(audio) load_on.add_child(audio)
Global.Log("Sound playing "+sound_name, 1)

View File

@ -55,11 +55,6 @@ func InteractWithCell():
print("plant cell mouse line 1: ", interaction_map.get_cell(12, 36)) print("plant cell mouse line 1: ", interaction_map.get_cell(12, 36))
print('plant_cell_mouse=',plant_cell_mouse,' | plant_cell_character=', plant_cell_character,' | background_cell=', background_cell,' | interaction_cell=',interaction_cell) print('plant_cell_mouse=',plant_cell_mouse,' | plant_cell_character=', plant_cell_character,' | background_cell=', background_cell,' | interaction_cell=',interaction_cell)
GlobalGameFunctions.SoundOnInteraction(self, "standard") GlobalGameFunctions.SoundOnInteraction(self, "standard")
for i in 150:
for j in 150:
if interaction_map.get_cell(int(i),int(j)) != -1:
print(interaction_map.get_cell(int(i),int(j)))
print(i, j)
if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0: if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0:
Global.AddInventoryItem(plant_cell_mouse/2, 1) Global.AddInventoryItem(plant_cell_mouse/2, 1)
@ -84,3 +79,4 @@ func AnimationOnInteraction(Item):
func _ready(): func _ready():
Global.player_inventory_items = Database.GetInventoryItems().duplicate() Global.player_inventory_items = Database.GetInventoryItems().duplicate()
print("Map = ", Global.map_name)

View File

@ -6,15 +6,6 @@ func _ready():
func _on_Btn_PlayGame_pressed(): func _on_Btn_PlayGame_pressed():
Global.LoadSave() Global.LoadSave()
Global.GoToScene("res://Other/base_tilemap/base_tilemap.tscn") #Hier kan eventueel de mapnaam van de database ingevoerd worden! Global.GoToScene("res://Other/base_tilemap/base_tilemap.tscn") #Hier kan eventueel de mapnaam van de database ingevoerd worden!
#
#
# #save this scene to global scenes
# Global.AddScene(self, "menu", false)
#
# #set this scene as main
# Global.mainscene = "startmap1"
# Global.AddScene(game, "startmap1", true)
## get_tree().get_root().add_child(game)
func _on_Btn_LoadGame_pressed(): func _on_Btn_LoadGame_pressed():
Global.GoToScene("loadgame_screen") Global.GoToScene("loadgame_screen")

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Sounds/standard.wav" type="AudioStream" id=1]
[node name="GameVariables" type="Node"]
[node name="Sound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 1 )
autoplay = true

View File

@ -1,4 +1,3 @@
[gd_scene format=2] [gd_scene format=2]
[node name="Sound" type="AudioStreamPlayer"] [node name="Sound" type="AudioStreamPlayer"]
autoplay = true

View File

@ -1,12 +1,5 @@
extends Node2D extends Node2D
func load_scene(map_data):
var scene = load(map_data+".tscn")
print("MAP NAME ",map_data+".tscn")
var map = scene.instance()
return map
func _ready(): func _ready():
var map = "res://Maps/river_intersection" var map_name = "res://Maps/river_intersection"
self.add_child(load_scene(map)) self.add_child(Global.load_scene(map_name))

10
default_bus_layout.tres Normal file
View File

@ -0,0 +1,10 @@
[gd_resource type="AudioBusLayout" format=2]
[resource]
bus/0/solo = true
bus/1/name = "New Bus"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 6.02
bus/1/send = "Master"