diff options
author | IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com> | 2022-07-16 21:09:11 +0200 |
---|---|---|
committer | IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com> | 2022-07-16 21:09:11 +0200 |
commit | 9c061b9997d0add3298b1230426dd7332b91420f (patch) | |
tree | e26c6f23178e6dc3078ddc1948cd37180336e7d4 /godot/scripts | |
parent | 28e29e51e2c48868d0a75586ba3f8d73858342e3 (diff) | |
download | 2022-9c061b9997d0add3298b1230426dd7332b91420f.tar.gz 2022-9c061b9997d0add3298b1230426dd7332b91420f.tar.bz2 2022-9c061b9997d0add3298b1230426dd7332b91420f.zip |
goal post hitbox and level loader in gd script
Diffstat (limited to 'godot/scripts')
-rw-r--r-- | godot/scripts/GoalTriggerBox.gd | 22 | ||||
-rw-r--r-- | godot/scripts/LevelLoader.gd | 30 |
2 files changed, 52 insertions, 0 deletions
diff --git a/godot/scripts/GoalTriggerBox.gd b/godot/scripts/GoalTriggerBox.gd new file mode 100644 index 0000000..9281f0f --- /dev/null +++ b/godot/scripts/GoalTriggerBox.gd @@ -0,0 +1,22 @@ +extends Area + +const Loader = preload("res://scripts/LevelLoader.gd") +var loader: Loader = null + +# Called when the node enters the scene tree for the first time. +func _ready(): + loader = get_node("../LevelLoader") + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + + +func _on_Area2_body_entered(body: RigidBody): + # return when body is not a rigidbody + if body == null: + return + + loader.load_next_level() + diff --git a/godot/scripts/LevelLoader.gd b/godot/scripts/LevelLoader.gd new file mode 100644 index 0000000..538d4ef --- /dev/null +++ b/godot/scripts/LevelLoader.gd @@ -0,0 +1,30 @@ +extends Node + +const NUM_LEVELS = 9 + +var current_level_id = 0 +var levels = [] + +# Called when the node enters the scene tree for the first time. +func _ready(): + for i in range(NUM_LEVELS): + levels.append(get_node("/root/Game/Level%d" % (i+1))) + + levels[0].show() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + +func load_next_level(): + levels[current_level_id].hide() + current_level_id = current_level_id + 1 + + if current_level_id >= NUM_LEVELS: + # TODO load main menu + return + + # TODO teleport the die to the start point + levels[current_level_id].show() + |