From 6529ed8b650ba45a87f256c03f46bffb8c4ab159 Mon Sep 17 00:00:00 2001 From: Jonathan Herrewijnen Date: Tue, 11 Oct 2022 19:21:46 +0200 Subject: [PATCH] Changed sound behaviour. Working on interaction map. --- Global_InGame.gd | 11 +++++++++-- MiscCodes/KinematicBody2D.gd | 10 ++-------- MiscCodes/Menu_Buttons.gd | 14 +------------- MiscCodes/background_script.gd | 3 --- MiscScenes/Control.tscn | 1 - MiscScenes/Sound.tscn | 4 ++++ MiscScenes/Speech.tscn | 1 - Other/base_tilemap/base_tilemap.tscn | 7 +------ Other/base_tilemap/init.gd | 13 ------------- 9 files changed, 17 insertions(+), 47 deletions(-) create mode 100644 MiscScenes/Sound.tscn diff --git a/Global_InGame.gd b/Global_InGame.gd index 29455da..dc4a4a9 100644 --- a/Global_InGame.gd +++ b/Global_InGame.gd @@ -1,9 +1,16 @@ extends Node2D - -#Global functions for the game, like speech bubbles +#Global functions for the game, like speech bubbles and sounds func RenderSpeech(load_on, text): var speech = preload("res://MiscScenes/Speech.tscn").instance() speech.bubble_text = text speech.set_position(Vector2(0,-40)) load_on.add_child(speech) + +func SoundOnInteraction(load_on, sound_name): + var audio = preload("res://MiscScenes/Sound.tscn").instance() + var format_string = "res://Sounds/%s.wav" + var actual_string = format_string % sound_name + var Sound = load(actual_string) + audio.stream = Sound + load_on.add_child(audio) diff --git a/MiscCodes/KinematicBody2D.gd b/MiscCodes/KinematicBody2D.gd index ca4d3e7..12330b5 100644 --- a/MiscCodes/KinematicBody2D.gd +++ b/MiscCodes/KinematicBody2D.gd @@ -4,8 +4,8 @@ const GRAVITY = 0.0 const WALK_SPEED = 200 const interaction_circle_size = 150 onready var background_map = get_node("/root/base_scene/background") -onready var player = get_node("/root/base_scene/Player") onready var cell_size = background_map._get_cell_size() +onready var player = get_node("/root/base_scene/Player") onready var interaction_map = get_node("/root/base_scene/interaction_map") onready var player_interaction = get_node("/root/base_scene/player_interaction") @@ -48,6 +48,7 @@ func InteractWithCell(): 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) + GlobalGameFunctions.SoundOnInteraction(self, "standard") if plant_cell_mouse > 0 and plant_cell_mouse % 2 == 0: Global.AddInventoryItem(plant_cell_mouse/2, 1) @@ -71,12 +72,5 @@ func AnimationOnInteraction(Item): var itemimage = TextureRect.new() var item = null -func SoundOnInteraction(x): - var format_string = "res://Sounds/%s.wav" - var actual_string = format_string % x - var Sound = load(actual_string) - $AudioStreamPlayer.stream = Sound - $AudioStreamPlayer.play() - func _ready(): Global.player_inventory_items = Database.GetInventoryItems().duplicate() diff --git a/MiscCodes/Menu_Buttons.gd b/MiscCodes/Menu_Buttons.gd index 5e08f24..9d53b7c 100644 --- a/MiscCodes/Menu_Buttons.gd +++ b/MiscCodes/Menu_Buttons.gd @@ -1,16 +1,4 @@ extends Button - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - - -# Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass + pass diff --git a/MiscCodes/background_script.gd b/MiscCodes/background_script.gd index 362a235..c1d8ac9 100644 --- a/MiscCodes/background_script.gd +++ b/MiscCodes/background_script.gd @@ -3,9 +3,6 @@ extends TileMap onready var player = get_node("/root/base_scene/Player") onready var camera = get_node("/root/base_scene/Camera2D") -func _ready(): - pass - func _get_cell_size(): return cell_size diff --git a/MiscScenes/Control.tscn b/MiscScenes/Control.tscn index 1bda344..a5fa2b3 100644 --- a/MiscScenes/Control.tscn +++ b/MiscScenes/Control.tscn @@ -2,7 +2,6 @@ [ext_resource path="res://pictures/arrow_down.png" type="Texture" id=1] - [sub_resource type="GradientTexture" id=1] [node name="Control" type="Control"] diff --git a/MiscScenes/Sound.tscn b/MiscScenes/Sound.tscn new file mode 100644 index 0000000..be9290b --- /dev/null +++ b/MiscScenes/Sound.tscn @@ -0,0 +1,4 @@ +[gd_scene format=2] + +[node name="Sound" type="AudioStreamPlayer"] +autoplay = true diff --git a/MiscScenes/Speech.tscn b/MiscScenes/Speech.tscn index 2121ac9..8820534 100644 --- a/MiscScenes/Speech.tscn +++ b/MiscScenes/Speech.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://pictures/gui/dialogue/SpeachBubbleBoarder.png" type="Texture" id=1] [ext_resource path="res://MiscCodes/Speech.gd" type="Script" id=2] - [node name="Speech" type="Node2D"] script = ExtResource( 2 ) diff --git a/Other/base_tilemap/base_tilemap.tscn b/Other/base_tilemap/base_tilemap.tscn index 6b9b4e5..699b63b 100644 --- a/Other/base_tilemap/base_tilemap.tscn +++ b/Other/base_tilemap/base_tilemap.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=20 format=2] +[gd_scene load_steps=19 format=2] [ext_resource path="res://pictures/gui/player_interaction.tres" type="TileSet" id=1] [ext_resource path="res://MiscCodes/background_script.gd" type="Script" id=2] @@ -16,7 +16,6 @@ [ext_resource path="res://pictures/gui/buttons/crafting_alchemy.png" type="Texture" id=14] [ext_resource path="res://pictures/surroundings/bomen/boom_stand3.png" type="Texture" id=15] [ext_resource path="res://pictures/gui/buttons/quick_item_button.png" type="Texture" id=16] -[ext_resource path="res://Sounds/night-chip.ogg" type="AudioStream" id=17] [sub_resource type="CapsuleShape2D" id=1] radius = 20.0 @@ -192,10 +191,6 @@ z_index = 11 shape = SubResource( 2 ) action = "map_interaction" -[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="Player"] -pause_mode = 2 -stream = ExtResource( 17 ) - [node name="Tween" type="Tween" parent="."] [connection signal="released" from="Camera2D/Interactive/GameButtons/Inventory" to="background" method="_on_Inventory_released"] [connection signal="pressed" from="Camera2D/Interactive/GameButtons/MoveDown" to="Player" method="_on_TouchScreenButton_pressed"] diff --git a/Other/base_tilemap/init.gd b/Other/base_tilemap/init.gd index 2db0196..1069b76 100644 --- a/Other/base_tilemap/init.gd +++ b/Other/base_tilemap/init.gd @@ -1,16 +1,6 @@ extends Node2D func load_scene(map_data): - #$background.tile_set = load("base_tilemap/tilesets/background_ts.tres") - #$vegetation.tile_set = load("res://river_intersection_home2.tscn::1") - -# for x in range(map_data.width): -# for y in range(map_data.height): -# $background.set_cell(x, y, map_data.background_map[x][y]) -# $vegetation.set_cell(x, y, -1) -# $interaction_map.set_cell(x, y, -1) -# $player_interaction.set_cell(x, y, -1) - var scene = load(map_data+".tscn") print("MAP NAME ",map_data+".tscn") var map = scene.instance() @@ -19,6 +9,3 @@ func load_scene(map_data): func _ready(): self.add_child(load_scene("res://Maps/river_intersection")) -# var scene = load("res://Maps/river_intersection.tscn") -# var map = scene.instance() -# self.add_child(map)