added a bullet pool to scene manager

This commit is contained in:
OddlyTimbot 2024-09-09 17:27:42 -04:00
parent cbd41bb063
commit f9b3966231
10 changed files with 48 additions and 31 deletions

View File

@ -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]([])

View File

@ -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]([])

View File

@ -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]

View File

@ -3,3 +3,4 @@ res://scripts/CharacterBody2D.gd
res://scenes/character.tscn
res://scenes/bullet.tscn
res://scripts/SceneManager.gd
res://scripts/bullet.gd

View File

@ -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]([])

View File

@ -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"
}

View File

@ -1 +1,7 @@
list=Array[Dictionary]([])
list=Array[Dictionary]([{
"base": &"Area2D",
"class": &"Bullet",
"icon": "",
"language": &"GDScript",
"path": "res://scripts/bullet.gd"
}])

View File

@ -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")

View File

@ -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)

View File

@ -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)