diff --git a/week2/updated_files/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg b/week2/updated_files/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg index e72f1ee..078ed84 100644 --- a/week2/updated_files/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg +++ b/week2/updated_files/.godot/editor/bullet.tscn-editstate-6d8e6ff1e6f20a36e0402d27c623c86c.cfg @@ -175,4 +175,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Game/SceneManager")]) +selected_nodes=Array[NodePath]([]) diff --git a/week2/updated_files/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg b/week2/updated_files/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg index 38fc33e..691dd05 100644 --- a/week2/updated_files/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg +++ b/week2/updated_files/.godot/editor/character.tscn-editstate-b6bd7a241034177d7fe082a7597ba8ea.cfg @@ -175,4 +175,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Game/SceneManager")]) +selected_nodes=Array[NodePath]([]) diff --git a/week2/updated_files/.godot/editor/editor_layout.cfg b/week2/updated_files/.godot/editor/editor_layout.cfg index 19ba4a2..3fe6251 100644 --- a/week2/updated_files/.godot/editor/editor_layout.cfg +++ b/week2/updated_files/.godot/editor/editor_layout.cfg @@ -20,7 +20,7 @@ dock_filesystem_display_mode=0 dock_filesystem_file_sort=0 dock_filesystem_file_list_display_mode=1 dock_filesystem_selected_paths=PackedStringArray("res://scripts/SceneManager.gd") -dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scripts/", "res://scenes/") +dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://") dock_bottom=[] dock_closed=[] dock_filesystem_h_split_offset=240 @@ -32,11 +32,11 @@ dock_5="Inspector,Node,History" [EditorNode] open_scenes=PackedStringArray("res://scenes/game.tscn", "res://scenes/character.tscn", "res://scenes/bullet.tscn") -current_scene="res://scenes/game.tscn" +current_scene="res://scenes/character.tscn" center_split_offset=0 -selected_default_debugger_tab_idx=0 +selected_default_debugger_tab_idx=1 selected_main_editor_idx=2 -selected_bottom_panel_item=0 +selected_bottom_panel_item=1 [ScriptEditor] diff --git a/week2/updated_files/.godot/editor/filesystem_update4 b/week2/updated_files/.godot/editor/filesystem_update4 index 999ce34..245200f 100644 --- a/week2/updated_files/.godot/editor/filesystem_update4 +++ b/week2/updated_files/.godot/editor/filesystem_update4 @@ -3,3 +3,4 @@ res://scripts/CharacterBody2D.gd res://scenes/character.tscn res://scenes/bullet.tscn res://scripts/SceneManager.gd +res://scripts/bullet.gd diff --git a/week2/updated_files/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg b/week2/updated_files/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg index 38fc33e..691dd05 100644 --- a/week2/updated_files/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg +++ b/week2/updated_files/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg @@ -175,4 +175,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Game/SceneManager")]) +selected_nodes=Array[NodePath]([]) diff --git a/week2/updated_files/.godot/editor/script_editor_cache.cfg b/week2/updated_files/.godot/editor/script_editor_cache.cfg index 140088f..b8c1c75 100644 --- a/week2/updated_files/.godot/editor/script_editor_cache.cfg +++ b/week2/updated_files/.godot/editor/script_editor_cache.cfg @@ -3,10 +3,10 @@ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 38, +"column": 52, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 44, +"row": 41, "scroll_position": 31.0, "selection": false, "syntax_highlighter": "GDScript" @@ -20,7 +20,7 @@ state={ "column": 30, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 11, +"row": 12, "scroll_position": 0.0, "selection": false, "syntax_highlighter": "GDScript" @@ -45,11 +45,11 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 22, +"column": 0, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 13, -"scroll_position": 0.0, +"row": 21, +"scroll_position": 11.0, "selection": false, "syntax_highlighter": "GDScript" } diff --git a/week2/updated_files/.godot/global_script_class_cache.cfg b/week2/updated_files/.godot/global_script_class_cache.cfg index 1775a2f..72ba349 100644 --- a/week2/updated_files/.godot/global_script_class_cache.cfg +++ b/week2/updated_files/.godot/global_script_class_cache.cfg @@ -1 +1,7 @@ -list=Array[Dictionary]([]) +list=Array[Dictionary]([{ +"base": &"Area2D", +"class": &"Bullet", +"icon": "", +"language": &"GDScript", +"path": "res://scripts/bullet.gd" +}]) diff --git a/week2/updated_files/scripts/CharacterBody2D.gd b/week2/updated_files/scripts/CharacterBody2D.gd index 3f711e1..2fe8a15 100644 --- a/week2/updated_files/scripts/CharacterBody2D.gd +++ b/week2/updated_files/scripts/CharacterBody2D.gd @@ -16,8 +16,6 @@ var pushLeftEnabled = false var pushRightEnabled = false var pushTarget -var bullet = preload("res://scenes/bullet.tscn") - # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") @@ -39,10 +37,9 @@ func _physics_process(delta): if Input.is_action_just_pressed("shoot"): #make a bullet - var myBullet = bullet.instantiate() + var myBullet = %SceneManager.bulletFactory() #set bullet speed? myBullet.transform = marker_right.global_transform - %SceneManager.manageBullet(myBullet) # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. var direction = Input.get_axis("ui_left", "ui_right") diff --git a/week2/updated_files/scripts/SceneManager.gd b/week2/updated_files/scripts/SceneManager.gd index a8df008..84c3a27 100644 --- a/week2/updated_files/scripts/SceneManager.gd +++ b/week2/updated_files/scripts/SceneManager.gd @@ -1,16 +1,27 @@ extends Node var bulletsFiredTotal := 0 -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. +var bulletsMadeTotal := 0 +var bulletArray:Array = [] + +var bullet = preload("res://scenes/bullet.tscn") + +func bulletFactory(): + var mybullet + + if bulletArray.size() < 4: + mybullet = bullet.instantiate() + mybullet.connect("hit", onBulletHit) + owner.add_child(mybullet) + else: + mybullet = bulletArray.pop_back() + mybullet.setSpeed(700) + bulletArray.push_front(mybullet) + bulletsMadeTotal +=1 + return mybullet -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass - -func manageBullet(bullet): - bulletsFiredTotal +=1 - owner.add_child(bullet) - print("Total bullets fired "+str(bulletsFiredTotal)) +func onBulletHit(bullet, body): + #deactivate bullet + #put back in queue + bullet.setSpeed(1) diff --git a/week2/updated_files/scripts/bullet.gd b/week2/updated_files/scripts/bullet.gd index eeb30ef..2260327 100644 --- a/week2/updated_files/scripts/bullet.gd +++ b/week2/updated_files/scripts/bullet.gd @@ -1,6 +1,7 @@ -extends Area2D +class_name Bullet extends Area2D var speed = 750 +signal hit(bullet, body) func setSpeed(speedVal): speed = speedVal @@ -12,4 +13,5 @@ func _on_body_entered(body): print("bullet hit something") if not body.is_in_group("player"): - queue_free() + hit.emit(self, body) +