55 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
| extends Node2D
 | |
| 
 | |
| var timer:= Timer.new()
 | |
| var secondCount= 99
 | |
| var totalCrates := 0
 | |
| var cratesDestroyed := 0
 | |
| 
 | |
| # level info
 | |
| var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn"]
 | |
| var timers = [20, 15]
 | |
| var currentLevel = 0
 | |
| 
 | |
| #Gamecontroller signals
 | |
| signal destroyBox(body)
 | |
| signal levelComplete(leveltoLoad)
 | |
| 
 | |
| # Called when the node enters the scene tree for the first time.
 | |
| func _ready() -> void:
 | |
| 	print("Number of levels: "+str(levels.size()))
 | |
| 	add_child(timer)
 | |
| 	timer.wait_time = 1
 | |
| 	timer.one_shot = false
 | |
| 	timer.connect("timeout", secondCounter)
 | |
| 	timer.start()
 | |
| 	
 | |
| func reset():
 | |
| 	secondCount = timers[currentLevel]
 | |
| 
 | |
| func secondCounter():
 | |
| 	print("time left: ", secondCount)
 | |
| 	secondCount -=1
 | |
| 	if secondCount <= 0:
 | |
| 		print("TIME IS UP")
 | |
| 		levelComplete.emit(levels[currentLevel])
 | |
| 
 | |
| func bulletHit(body):
 | |
| 	print("Game controller knows bullet hit something")
 | |
| 	if body.is_in_group("destructables"):
 | |
| 		destroyBox.emit(body)
 | |
| 		totalCrates -= 1
 | |
| 		cratesDestroyed += 1
 | |
| 		
 | |
| 		if totalCrates <=0:
 | |
| 			print("You Won...")
 | |
| 			currentLevel +=1
 | |
| 			if currentLevel >= levels.size():
 | |
| 				currentLevel =  0
 | |
| 			levelComplete.emit(levels[currentLevel])
 | |
| 		else:
 | |
| 			print("Crates Remaining: "+str(totalCrates) )
 | |
| 		
 | |
| # Coming from scenemanager
 | |
| func countCrates(value):
 | |
| 	totalCrates = value
 |