From eebf4c292217332cdd03bc5e3f863e912ada6c6f Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Mon, 12 Aug 2024 15:32:24 -0400 Subject: [PATCH] moved game manager to unique object --- ...ditstate-e196a632ea77e9a0d8baa608f164a4d2.cfg | 2 +- ...ditstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg | 2 +- ...ditstate-b6bd7a241034177d7fe082a7597ba8ea.cfg | 2 +- ...ditstate-65637dc57c83dac3d15ec1cb22439bd7.cfg | 2 +- .../.godot/editor/create_recent.Node | 1 + .../.godot/editor/editor_layout.cfg | 8 ++++---- .../.godot/editor/filesystem_update4 | 1 + ...ditstate-c2a7af834e91ff64325daddf58e45dc0.cfg | 2 +- .../.godot/editor/project_metadata.cfg | 2 +- week5/updated_project/.godot/editor/recent_dirs | 2 +- .../.godot/editor/script_editor_cache.cfg | 16 ++++++++-------- week5/updated_project/scenes/game.tscn | 5 ++++- week5/updated_project/scripts/badguy.gd | 3 ++- week5/updated_project/scripts/coin.gd | 3 ++- week5/updated_project/scripts/gamecontroller.gd | 9 +++++---- 15 files changed, 34 insertions(+), 26 deletions(-) diff --git a/week5/updated_project/.godot/editor/badguy.tscn-editstate-e196a632ea77e9a0d8baa608f164a4d2.cfg b/week5/updated_project/.godot/editor/badguy.tscn-editstate-e196a632ea77e9a0d8baa608f164a4d2.cfg index 5b4ab8e..b821847 100644 --- a/week5/updated_project/.godot/editor/badguy.tscn-editstate-e196a632ea77e9a0d8baa608f164a4d2.cfg +++ b/week5/updated_project/.godot/editor/badguy.tscn-editstate-e196a632ea77e9a0d8baa608f164a4d2.cfg @@ -172,4 +172,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game")]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game/crates/boxtrap")]) diff --git a/week5/updated_project/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg b/week5/updated_project/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg index 3fca208..50d95f1 100644 --- a/week5/updated_project/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg +++ b/week5/updated_project/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg @@ -172,4 +172,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game")]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game/crates/boxtrap")]) diff --git a/week5/updated_project/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg b/week5/updated_project/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg index 06f70e7..0abfa1c 100644 --- a/week5/updated_project/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg +++ b/week5/updated_project/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg @@ -172,4 +172,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game/crates/boxtrap")]) diff --git a/week5/updated_project/.godot/editor/crate.tscn-editstate-65637dc57c83dac3d15ec1cb22439bd7.cfg b/week5/updated_project/.godot/editor/crate.tscn-editstate-65637dc57c83dac3d15ec1cb22439bd7.cfg index 6ec1d6d..59e4bdb 100644 --- a/week5/updated_project/.godot/editor/crate.tscn-editstate-65637dc57c83dac3d15ec1cb22439bd7.cfg +++ b/week5/updated_project/.godot/editor/crate.tscn-editstate-65637dc57c83dac3d15ec1cb22439bd7.cfg @@ -172,4 +172,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game")]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game/crates/boxtrap")]) diff --git a/week5/updated_project/.godot/editor/create_recent.Node b/week5/updated_project/.godot/editor/create_recent.Node index 547b774..2771d99 100644 --- a/week5/updated_project/.godot/editor/create_recent.Node +++ b/week5/updated_project/.godot/editor/create_recent.Node @@ -1,3 +1,4 @@ +Node RayCast2D CollisionShape2D AnimatedSprite2D diff --git a/week5/updated_project/.godot/editor/editor_layout.cfg b/week5/updated_project/.godot/editor/editor_layout.cfg index c208a7c..bdc6931 100644 --- a/week5/updated_project/.godot/editor/editor_layout.cfg +++ b/week5/updated_project/.godot/editor/editor_layout.cfg @@ -19,7 +19,7 @@ dock_filesystem_split=0 dock_filesystem_display_mode=0 dock_filesystem_file_sort=0 dock_filesystem_file_list_display_mode=1 -dock_filesystem_selected_paths=PackedStringArray("res://scenes/badguy.tscn") +dock_filesystem_selected_paths=PackedStringArray("res://scenes/game.tscn") dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scripts/", "res://scenes/", "res://graphics/") dock_3="Scene,Import" dock_4="FileSystem" @@ -28,16 +28,16 @@ dock_5="Inspector,Node,History" [EditorNode] open_scenes=PackedStringArray("res://scenes/game.tscn", "res://scenes/character.tscn", "res://scenes/bullet.tscn", "res://scenes/crate.tscn", "res://scenes/badguy.tscn") -current_scene="res://scenes/character.tscn" +current_scene="res://scenes/game.tscn" center_split_offset=-325 selected_default_debugger_tab_idx=0 selected_main_editor_idx=2 -selected_bottom_panel_item=0 +selected_bottom_panel_item=1 [ScriptEditor] open_scripts=["res://scripts/badguy.gd", "res://scripts/bullet.gd", "res://scripts/CharacterBody2D.gd", "res://scripts/coin.gd", "res://scripts/gamecontroller.gd", "res://scripts/Trigger.gd"] -selected_script="res://scripts/CharacterBody2D.gd" +selected_script="res://scripts/gamecontroller.gd" open_help=[] script_split_offset=70 list_split_offset=0 diff --git a/week5/updated_project/.godot/editor/filesystem_update4 b/week5/updated_project/.godot/editor/filesystem_update4 index d6285e7..70ad809 100644 --- a/week5/updated_project/.godot/editor/filesystem_update4 +++ b/week5/updated_project/.godot/editor/filesystem_update4 @@ -5,3 +5,4 @@ res://scenes/character.tscn res://scenes/bullet.tscn res://scenes/crate.tscn res://scripts/gamecontroller.gd +res://scripts/coin.gd diff --git a/week5/updated_project/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg b/week5/updated_project/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg index ec932da..cee7e56 100644 --- a/week5/updated_project/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg +++ b/week5/updated_project/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg @@ -172,4 +172,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game")]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@17140/@Panel@13/@VBoxContainer@14/@HSplitContainer@17/@HSplitContainer@25/@HSplitContainer@33/@VBoxContainer@34/@VSplitContainer@36/@VSplitContainer@62/@VBoxContainer@63/@PanelContainer@110/MainScreen/@CanvasItemEditor@9462/@VSplitContainer@9281/@HSplitContainer@9283/@HSplitContainer@9285/@Control@9286/@SubViewportContainer@9287/@SubViewport@9288/Game/crates/boxtrap")]) diff --git a/week5/updated_project/.godot/editor/project_metadata.cfg b/week5/updated_project/.godot/editor/project_metadata.cfg index ddc35ac..dda02ac 100644 --- a/week5/updated_project/.godot/editor/project_metadata.cfg +++ b/week5/updated_project/.godot/editor/project_metadata.cfg @@ -14,7 +14,7 @@ run_debug_collisions=true [recent_files] -scenes=["res://scenes/badguy.tscn", "res://scenes/area_trigger.tscn", "res://scenes/coin.tscn", "res://scenes/menu.tscn", "res://scenes/platform.tscn", "res://scenes/crate.tscn", "res://scenes/bullet.tscn", "res://scenes/character.tscn", "res://scenes/game.tscn", "res://scenes/animatedcoin.tscn"] +scenes=["res://scenes/game.tscn", "res://scenes/badguy.tscn", "res://scenes/area_trigger.tscn", "res://scenes/coin.tscn", "res://scenes/menu.tscn", "res://scenes/platform.tscn", "res://scenes/crate.tscn", "res://scenes/bullet.tscn", "res://scenes/character.tscn", "res://scenes/animatedcoin.tscn"] scripts=["res://scripts/badguy.gd", "res://scripts/coin.gd", "res://scripts/Trigger.gd", "res://scripts/bullet.gd", "res://scripts/CharacterBody2D.gd", "res://scripts/gamecontroller.gd"] [linked_properties] diff --git a/week5/updated_project/.godot/editor/recent_dirs b/week5/updated_project/.godot/editor/recent_dirs index 6e6eb36..84cfc79 100644 --- a/week5/updated_project/.godot/editor/recent_dirs +++ b/week5/updated_project/.godot/editor/recent_dirs @@ -1,5 +1,5 @@ -res://scenes res://scripts +res://scenes res://graphics res://graphics/Player Jump res://graphics/Player Run diff --git a/week5/updated_project/.godot/editor/script_editor_cache.cfg b/week5/updated_project/.godot/editor/script_editor_cache.cfg index 4a2fa00..57ea8cd 100644 --- a/week5/updated_project/.godot/editor/script_editor_cache.cfg +++ b/week5/updated_project/.godot/editor/script_editor_cache.cfg @@ -3,11 +3,11 @@ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 25, +"column": 43, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 27, -"scroll_position": 6.0, +"row": 7, +"scroll_position": 1.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -45,10 +45,10 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 22, +"column": 17, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 6, +"row": 2, "scroll_position": 0.0, "selection": false, "syntax_highlighter": "GDScript" @@ -73,11 +73,11 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 20, +"column": 17, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 23, -"scroll_position": 10.0, +"row": 7, +"scroll_position": 0.0, "selection": false, "syntax_highlighter": "GDScript" } diff --git a/week5/updated_project/scenes/game.tscn b/week5/updated_project/scenes/game.tscn index f76701d..20cdcc0 100644 --- a/week5/updated_project/scenes/game.tscn +++ b/week5/updated_project/scenes/game.tscn @@ -520,6 +520,9 @@ _data = { } [node name="Game" type="Node2D"] + +[node name="GameManager" type="Node" parent="."] +unique_name_in_owner = true script = ExtResource("1_77wyw") [node name="TileMap" type="TileMap" parent="."] @@ -591,4 +594,4 @@ position = Vector2(79, 88) [node name="Area2D" parent="." instance=ExtResource("11_ghgxt")] position = Vector2(-28, 84) -[connection signal="areatrigger" from="AreaTrigger" to="." method="_on_area_2d_areatrigger"] +[connection signal="areatrigger" from="AreaTrigger" to="GameManager" method="_on_area_2d_areatrigger"] diff --git a/week5/updated_project/scripts/badguy.gd b/week5/updated_project/scripts/badguy.gd index 6d5d035..22a8180 100644 --- a/week5/updated_project/scripts/badguy.gd +++ b/week5/updated_project/scripts/badguy.gd @@ -5,7 +5,8 @@ var direction = 1 @onready var cast_right = $CastRight @onready var cast_left = $CastLeft @onready var sprite = $AnimatedSprite2D -@onready var game = $".." +@onready var game = %GameManager + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): diff --git a/week5/updated_project/scripts/coin.gd b/week5/updated_project/scripts/coin.gd index 442fcfe..568542f 100644 --- a/week5/updated_project/scripts/coin.gd +++ b/week5/updated_project/scripts/coin.gd @@ -1,6 +1,7 @@ extends Area2D -@onready var game = $".." +@onready var game = %GameManager + func _on_body_entered(body): if body.is_in_group("player"): diff --git a/week5/updated_project/scripts/gamecontroller.gd b/week5/updated_project/scripts/gamecontroller.gd index f3b8962..30ed015 100644 --- a/week5/updated_project/scripts/gamecontroller.gd +++ b/week5/updated_project/scripts/gamecontroller.gd @@ -1,10 +1,11 @@ -extends Node2D +extends Node var coinsCollected = 0 var crate = preload("res://scenes/crate.tscn") -@onready var boxtrap = $crates/boxtrap -@onready var player = $CharacterBody2D +@onready var boxtrap = $"../crates/boxtrap" + +@onready var player = $"../CharacterBody2D" func _on_area_2d_areatrigger(effect, body): print("Game Controller sees the trigger "+effect) @@ -14,7 +15,7 @@ func _on_area_2d_areatrigger(effect, body): if body.is_in_group("player"): for n in 3: var box = crate.instantiate() - add_child(box) + owner.add_child(box) box.position = boxtrap.position "powerup": print("you got power")