From cc8c7ba477207ab51bd1fcebe74559b2ccae5261 Mon Sep 17 00:00:00 2001 From: Eljakim Herrewijnen Date: Fri, 28 May 2021 23:01:56 +0200 Subject: [PATCH] Added game functions and bubble speech --- .../speech_bubble/SpeachBubbleBoarder.png | Bin 0 -> 159 bytes .../SpeachBubbleBoarder.png.import | 34 +++++++++++++ GameScenes/speech_bubble/Speech.gd | 44 ++++++++++++++++ GameScenes/speech_bubble/Speech.tscn | 47 ++++++++++++++++++ Global_Game.gd | 9 ++++ MiscCodes/KinematicBody2D.gd | 4 ++ MiscCodes/Menu.gd | 3 ++ MiscCodes/background_script.gd | 3 ++ base_tilemap/base_tilemap.tscn | 1 + project.godot | 1 + 10 files changed, 146 insertions(+) create mode 100644 GameScenes/speech_bubble/SpeachBubbleBoarder.png create mode 100644 GameScenes/speech_bubble/SpeachBubbleBoarder.png.import create mode 100644 GameScenes/speech_bubble/Speech.gd create mode 100644 GameScenes/speech_bubble/Speech.tscn create mode 100644 Global_Game.gd diff --git a/GameScenes/speech_bubble/SpeachBubbleBoarder.png b/GameScenes/speech_bubble/SpeachBubbleBoarder.png new file mode 100644 index 0000000000000000000000000000000000000000..8b79f45119427b70f4ed230899d6a8849a4f8674 GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^xSh8sWDaPU;cPEB*=VV?2Igy?&jv*1P zZ*OemJYc}X;Hasb6|i=OPJ%ewXO|D*QD>7wG?N$azJIqTD0F94{fi0GZf?)zuRXYO zV!qj|B$J~VT^B_bYq|yZER*mxoMmKGRTgTe~ HDWM4f*l9Qh literal 0 HcmV?d00001 diff --git a/GameScenes/speech_bubble/SpeachBubbleBoarder.png.import b/GameScenes/speech_bubble/SpeachBubbleBoarder.png.import new file mode 100644 index 0000000..607859d --- /dev/null +++ b/GameScenes/speech_bubble/SpeachBubbleBoarder.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/SpeachBubbleBoarder.png-0786cb6596266c43c2897b48768509b4.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://GameScenes/speech_bubble/SpeachBubbleBoarder.png" +dest_files=[ "res://.import/SpeachBubbleBoarder.png-0786cb6596266c43c2897b48768509b4.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/GameScenes/speech_bubble/Speech.gd b/GameScenes/speech_bubble/Speech.gd new file mode 100644 index 0000000..c40f5e9 --- /dev/null +++ b/GameScenes/speech_bubble/Speech.gd @@ -0,0 +1,44 @@ +#Thanks to: https://github.com/trolog/GodotanimatedSpeedbubble + +extends Node2D + +var bubble_text = "this is just a test" +var can_shrink = true +var bubble_text_length = 0 +var bubble_text_index = 0 +var current_text = "" + +onready var lbltext = get_node("VBoxContainer/Label") +onready var ninerect = get_node("VBoxContainer/Label/NinePatchRect") +onready var timer = get_node("Timer") + +var do_close = false + +func _ready(): + bubble_text_length = bubble_text.length() + timer.start(1) + +func _on_Timer_timeout(): + if(!do_close): + current_text += bubble_text[bubble_text_index] + lbltext.text = current_text + + if(bubble_text_index < bubble_text_length -1): + timer.start(0.04) + bubble_text_index += 1 + else: + if(!do_close): + do_close = true + timer.start(1) + else: + if(bubble_text_length > 0): + current_text.erase(bubble_text_length -1,1) + lbltext.text = current_text + bubble_text_length -= 1 + if(can_shrink): + ninerect.rect_size -= Vector2(6,0) + ninerect.rect_position += Vector2(3,0) + + timer.start(0.04) + else: + queue_free() diff --git a/GameScenes/speech_bubble/Speech.tscn b/GameScenes/speech_bubble/Speech.tscn new file mode 100644 index 0000000..c2f20eb --- /dev/null +++ b/GameScenes/speech_bubble/Speech.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://GameScenes/speech_bubble/SpeachBubbleBoarder.png" type="Texture" id=1] +[ext_resource path="res://GameScenes/speech_bubble/Speech.gd" type="Script" id=2] + +[node name="Speech" type="Node2D"] +script = ExtResource( 2 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label" type="Label" parent="VBoxContainer"] +margin_bottom = 14.0 +grow_horizontal = 2 +grow_vertical = 2 +custom_colors/font_color = Color( 0, 0, 0, 1 ) +align = 1 +valign = 1 + +[node name="NinePatchRect" type="NinePatchRect" parent="VBoxContainer/Label"] +show_behind_parent = true +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = -17.8063 +margin_top = -3.31948 +margin_right = 18.1937 +margin_bottom = 3.68052 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource( 1 ) +patch_margin_left = 18 +patch_margin_top = 11 +patch_margin_right = 18 +patch_margin_bottom = 10 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Timer" type="Timer" parent="."] +one_shot = true +[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/Global_Game.gd b/Global_Game.gd new file mode 100644 index 0000000..6429d05 --- /dev/null +++ b/Global_Game.gd @@ -0,0 +1,9 @@ +extends Node2D + +#Global functions for the game, like speech bubbles + +func RenderSpeech(load_on, text): + var speech = preload("res://GameScenes/speech_bubble/Speech.tscn").instance() + speech.bubble_text = text + speech.set_position(Vector2(0,-40)) + load_on.add_child(speech) \ No newline at end of file diff --git a/MiscCodes/KinematicBody2D.gd b/MiscCodes/KinematicBody2D.gd index a632915..a276148 100644 --- a/MiscCodes/KinematicBody2D.gd +++ b/MiscCodes/KinematicBody2D.gd @@ -55,6 +55,10 @@ func InteractWithCell(): Global.AddInventoryItem(plant_cell_character/2, 1) plants_map.set_cell(int(self.position.x / cell_size.x), int(self.position.y / cell_size.y), (plant_cell_character-1)) AnimationOnInteraction(1) + else: + #space is now a test function + GlobalGameFunctions.RenderSpeech(self, "joe") + pass func _interaction_process(): diff --git a/MiscCodes/Menu.gd b/MiscCodes/Menu.gd index e1e2c75..248d695 100644 --- a/MiscCodes/Menu.gd +++ b/MiscCodes/Menu.gd @@ -19,6 +19,9 @@ func _on_Btn_PlayGame_pressed(): var game = load("res://base_tilemap/base_tilemap.tscn").instance() game.load_scene(game_data) + #save this scene to global scenes + Global.AddScene(self, "menu", false) + #set this scene as main Global.mainscene = "startmap1" Global.AddScene(game, "startmap1", true) diff --git a/MiscCodes/background_script.gd b/MiscCodes/background_script.gd index 95d6b97..4987efa 100644 --- a/MiscCodes/background_script.gd +++ b/MiscCodes/background_script.gd @@ -17,6 +17,9 @@ func _unhandled_input(event): if(pl_tile != -1): set_cellv(pl_pos_tile, -1) +func _on_Settings_pressed(): + Global.GoToScene("menu") + func _on_Inventory_pressed(): var inventory_screen = preload("res://MiscScenes/Inventory.tscn").instance() Global.AddScene(inventory_screen, "inventory_screen", true) diff --git a/base_tilemap/base_tilemap.tscn b/base_tilemap/base_tilemap.tscn index 8c20f58..84db229 100644 --- a/base_tilemap/base_tilemap.tscn +++ b/base_tilemap/base_tilemap.tscn @@ -90,6 +90,7 @@ rotation = -3.14158 scale = Vector2( 1.22003, 1.11562 ) z_index = 13 normal = ExtResource( 11 ) +action = "settings_button" [node name="Map" type="TouchScreenButton" parent="Camera2D/Interactive/GameButtons"] position = Vector2( 88.136, 1376.12 ) diff --git a/project.godot b/project.godot index d03545f..7c94512 100644 --- a/project.godot +++ b/project.godot @@ -29,6 +29,7 @@ config/icon="res://pictures/gui/buttons/delete_ringofraces.png" Global="*res://Global.gd" Database="*res://Storage/Database.gd" GlobalStructures="*res://Global_structures.gd" +GlobalGameFunctions="*res://Global_Game.gd" [display]