multiple levels!
This commit is contained in:
1 parent
8ad0f7b627
commit
e0f48061e7
7 files changed
+515
-39
No files matched your search
@@ -82,7 +82,6 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
pushTarget = false
|
||||
if left_ray.is_colliding():
|
||||
print("Left ray collision")
|
||||
var collider = left_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("pushables"):
|
||||
@@ -92,7 +91,6 @@ func _physics_process(delta: float) -> void:
|
||||
pushLeftEnabled = false
|
||||
|
||||
if right_ray.is_colliding():
|
||||
print("Right ray collision")
|
||||
var collider = right_ray.get_collider()
|
||||
if collider is Node:
|
||||
if collider.is_in_group("pushables"):
|
||||
|
||||
+29
-19
@@ -1,44 +1,54 @@
|
||||
extends Node2D
|
||||
|
||||
var timer:= Timer.new()
|
||||
@export var secondCount= 99999999
|
||||
|
||||
var secondCount= 99
|
||||
var totalCrates := 0
|
||||
var cratesDestroyed := 0
|
||||
|
||||
signal destroyBox
|
||||
# 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("A loser is you")
|
||||
get_tree().reload_current_scene()
|
||||
print("TIME IS UP")
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
func _on_trigger(_effect: Variant, body) -> void:
|
||||
print("they were triggered!")
|
||||
if body is RigidBody2D:
|
||||
print("crate spotted")
|
||||
body.queue_free()
|
||||
|
||||
|
||||
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
|
||||
+14
-3
@@ -1,17 +1,28 @@
|
||||
extends Node
|
||||
@onready var game: Node2D = $".."
|
||||
# @onready var game: Node2D = $".."
|
||||
|
||||
@onready var crates: Node2D = $"../crates"
|
||||
|
||||
var theBullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array = []
|
||||
|
||||
var totalCrates := 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
game.destroyBox.connect(boxDestroy)
|
||||
GameController.reset()
|
||||
GameController.destroyBox.connect(boxDestroy)
|
||||
for obj in crates.get_children():
|
||||
if obj.is_in_group("destructables"):
|
||||
totalCrates += 1
|
||||
GameController.countCrates(totalCrates)
|
||||
|
||||
# Subscribe to signals
|
||||
GameController.levelComplete.connect(changeLevel)
|
||||
|
||||
func changeLevel(level):
|
||||
print("New level")
|
||||
get_tree().change_scene_to_file(level)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(_delta: float) -> void:
|
||||
@@ -42,7 +53,7 @@ func onBulletHit(bullet, body):
|
||||
bullet.position = Vector2(-100, -100)
|
||||
bullet.setSpeed(0)
|
||||
print("Scene manager knows bullet hit")
|
||||
game.bulletHit(body)
|
||||
GameController.bulletHit(body)
|
||||
|
||||
func boxDestroy(body):
|
||||
print("sceneMgr knows body destroyed")
|
||||
|
||||
Reference in new issue
Block a user