44 lines
		
	
	
		
			994 B
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			994 B
		
	
	
	
		
			GDScript
		
	
	
	
	
	
class_name GameController extends Node2D
 | 
						|
 | 
						|
 | 
						|
# Game Data
 | 
						|
var totalcrates=4
 | 
						|
var cratesdestroyed = 0
 | 
						|
 | 
						|
 | 
						|
 | 
						|
# Called when the node enters the scene tree for the first time.
 | 
						|
func _ready() -> void:
 | 
						|
	pass # Replace with function body.
 | 
						|
 | 
						|
 | 
						|
# Called every frame. 'delta' is the elapsed time since the previous frame.
 | 
						|
func _process(delta: float) -> void:
 | 
						|
	pass
 | 
						|
 | 
						|
 | 
						|
func _on_trigger_areatrigger(effect, body) -> void:
 | 
						|
	print("Do effect " +effect)
 | 
						|
	match effect:
 | 
						|
		"destroy":
 | 
						|
			#write code to destroy
 | 
						|
			if body is Crate:
 | 
						|
				%SceneManager.destroy(body)
 | 
						|
				cratesdestroyed +=1
 | 
						|
		"powerup":
 | 
						|
			#write code to power up
 | 
						|
			if body is Player:
 | 
						|
				print ("power up the player")
 | 
						|
	
 | 
						|
func bulletHit(body):
 | 
						|
	print("Game Controller knows bullet hit")
 | 
						|
	if body is Crate:
 | 
						|
		print ("you hit a crate")
 | 
						|
		cratesdestroyed +=1
 | 
						|
		%SceneManager.destroy(body)
 | 
						|
		print("Crates remaining::"+str(totalcrates - cratesdestroyed))
 | 
						|
 | 
						|
func numberofCrates (value):
 | 
						|
	totalcrates = value
 | 
						|
	print("Game Controller knows crates "+str(totalcrates))
 |