49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			GDScript3
		
	
	
	
	
	
		
		
			
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			GDScript3
		
	
	
	
	
	
| 
								 | 
							
								extends Node
							 | 
						||
| 
								 | 
							
								var  crate = preload("res://Scenes/Crate.tscn")
							 | 
						||
| 
								 | 
							
								var bullet = preload("res://Scenes/Bullet.tscn")
							 | 
						||
| 
								 | 
							
								var bulletPool:Array = []
							 | 
						||
| 
								 | 
							
								# crate pool thing
							 | 
						||
| 
								 | 
							
								var cratePool:Array = []
							 | 
						||
| 
								 | 
							
								@onready var box_trap_target: Node2D = $"../BoxTrapTarget"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func _ready() -> void:
							 | 
						||
| 
								 | 
							
									# pool crates
							 | 
						||
| 
								 | 
							
									for obj in owner.get_children():
							 | 
						||
| 
								 | 
							
										if obj.is_in_group("Pushable"):
							 | 
						||
| 
								 | 
							
											cratePool.push_back(obj)
							 | 
						||
| 
								 | 
							
									print("Total crate in play: "+str(cratePool.size() ) )
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func boxTrap():
							 | 
						||
| 
								 | 
							
									print("boxTrap active")
							 | 
						||
| 
								 | 
							
									var myCrate = crateFactory()
							 | 
						||
| 
								 | 
							
									myCrate.transform = box_trap_target.transform
							 | 
						||
| 
								 | 
							
									owner.add_child(myCrate)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func bulletFactory():
							 | 
						||
| 
								 | 
							
									#make/reuse bullets
							 | 
						||
| 
								 | 
							
									var myBullet
							 | 
						||
| 
								 | 
							
									print("Total bullets in play: "+str(bulletPool.size() ) )
							 | 
						||
| 
								 | 
							
									if bulletPool.size() > 5:
							 | 
						||
| 
								 | 
							
										myBullet = bulletPool.pop_front()
							 | 
						||
| 
								 | 
							
									else:
							 | 
						||
| 
								 | 
							
										myBullet = bullet.instantiate()
							 | 
						||
| 
								 | 
							
										owner.add_child(myBullet)
							 | 
						||
| 
								 | 
							
									return myBullet
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func placeBullet(speed, markerpos):
							 | 
						||
| 
								 | 
							
									print("make a bullet")
							 | 
						||
| 
								 | 
							
									var myBullet = bulletFactory()
							 | 
						||
| 
								 | 
							
									bulletPool.push_back(myBullet)
							 | 
						||
| 
								 | 
							
									print("Total bullets in play: "+str(bulletPool.size() ) )
							 | 
						||
| 
								 | 
							
									# set speed
							 | 
						||
| 
								 | 
							
									myBullet.setSpeed(speed)
							 | 
						||
| 
								 | 
							
									# set position of bullet
							 | 
						||
| 
								 | 
							
									myBullet.transform = markerpos
							 | 
						||
| 
								 | 
							
									# make bullet
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func crateFactory():
							 | 
						||
| 
								 | 
							
									var myCrate = crate.instantiate()
							 | 
						||
| 
								 | 
							
									myCrate.add_to_group("Pushable")
							 | 
						||
| 
								 | 
							
									return myCrate
							 |