timer
This commit is contained in:
parent
afe089fdcd
commit
ccdc54f587
@ -12,6 +12,7 @@
|
||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_8cj0n"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
position = Vector2(6, 2)
|
||||
script = ExtResource("1_lbhrr")
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||
@ -43,12 +44,12 @@ shape = SubResource("RectangleShape2D_8cj0n")
|
||||
[node name="Crate" parent="." instance=ExtResource("1_uwrxv")]
|
||||
position = Vector2(112, 186)
|
||||
|
||||
[node name="RigidBody2D2" type="RigidBody2D" parent="."]
|
||||
[node name="Crate2" type="RigidBody2D" parent="."]
|
||||
position = Vector2(147.99998, 202.99994)
|
||||
rotation = 2.6595373
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D2"]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Crate2"]
|
||||
shape = SubResource("RectangleShape2D_uwrxv")
|
||||
debug_color = Color(0.90240496, 0.29881617, 0.21305403, 0.41960785)
|
||||
|
||||
@ -69,5 +70,10 @@ intent = "powerup"
|
||||
[node name="CharacterBody2D" parent="." instance=ExtResource("3_lnu2h")]
|
||||
position = Vector2(96, 206)
|
||||
|
||||
[node name="TimerLabel" type="Label" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
text = "0000"
|
||||
|
||||
[connection signal="triggerFiredSignal" from="Trigger" to="." method="_on_trigger_fired"]
|
||||
[connection signal="triggerFiredSignal" from="Trigger2" to="." method="_on_trigger_fired"]
|
||||
|
@ -1,21 +1,35 @@
|
||||
extends Node2D
|
||||
|
||||
var totalCrates = 2 #This will be updated in the future, see SceneManager
|
||||
var cratesDestroyed = 0
|
||||
var timeLimit = 10
|
||||
var timer:= Timer.new()
|
||||
|
||||
# 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 _ready():
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
timer.connect("timeout", secondCounter)
|
||||
timer.start()
|
||||
$TimerLabel.text = str(timeLimit)
|
||||
|
||||
func secondCounter():
|
||||
timeLimit -= 1
|
||||
$TimerLabel.text = str(timeLimit)
|
||||
if timeLimit <=0:
|
||||
print("You lose baby!")
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
func _on_trigger_fired(intent: Variant, body) -> void:
|
||||
print("GC knows trigger fired " +intent)
|
||||
#print("GC knows trigger fired " +intent)
|
||||
match intent:
|
||||
"destroy":
|
||||
print("destroy this thing")
|
||||
body.queue_free()
|
||||
if body.name.begins_with("Crate"):
|
||||
cratesDestroyed +=1
|
||||
body.queue_free() # destroy the crate - again will move to SceneManager
|
||||
if cratesDestroyed>=totalCrates:
|
||||
print("You win baby!")
|
||||
get_tree().reload_current_scene()
|
||||
"powerup":
|
||||
print("power up this thing")
|
||||
|
@ -11,5 +11,5 @@ func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_body_entered(body):
|
||||
print("trigger fired")
|
||||
#print("trigger fired")
|
||||
triggerFiredSignal.emit(intent, body)
|
||||
|
Loading…
Reference in New Issue
Block a user