diff options
author | rom <romangraef@gmail.com> | 2021-04-25 16:05:09 +0200 |
---|---|---|
committer | rom <romangraef@gmail.com> | 2021-04-25 16:05:17 +0200 |
commit | 8ff102c632d39433c0a8d276e4bdacbca362dc51 (patch) | |
tree | 7f7d1f18f58af8ed5094efbc793857cc002d216c | |
parent | 2115f2305a09fce17cb2ebc74c42c2a48f4dff21 (diff) | |
download | ldjam48-8ff102c632d39433c0a8d276e4bdacbca362dc51.tar.gz ldjam48-8ff102c632d39433c0a8d276e4bdacbca362dc51.tar.bz2 ldjam48-8ff102c632d39433c0a8d276e4bdacbca362dc51.zip |
camera movement and signals
-rw-r--r-- | components/CameraTrackFollower.gd | 1 | ||||
-rw-r--r-- | components/Level.gd | 10 | ||||
-rw-r--r-- | scenes/levels/base_level.gd | 23 | ||||
-rw-r--r-- | scenes/menu.tscn | 1 |
4 files changed, 31 insertions, 4 deletions
diff --git a/components/CameraTrackFollower.gd b/components/CameraTrackFollower.gd index 22420d9..819e13b 100644 --- a/components/CameraTrackFollower.gd +++ b/components/CameraTrackFollower.gd @@ -29,7 +29,6 @@ func _process(delta): return var next_point = _points[_pidx] var dist : Vector2 = next_point - position - print("Camera movement", dist) if _t < speedup_time: current_speed += speedup * max(0, min(speedup_time-_t, delta)) _t += delta diff --git a/components/Level.gd b/components/Level.gd index 135a2cf..c3cb338 100644 --- a/components/Level.gd +++ b/components/Level.gd @@ -1,6 +1,16 @@ extends Node2D class_name Level +signal lost_heart() +signal level_finished() + func start(): print("Level starting.") + +func lose_heart(): + emit_signal("lost_heart") + +func finish_level(): + emit_signal("level_finished") + diff --git a/scenes/levels/base_level.gd b/scenes/levels/base_level.gd index b6f8a2e..d7dc3f7 100644 --- a/scenes/levels/base_level.gd +++ b/scenes/levels/base_level.gd @@ -13,23 +13,40 @@ const _levels = [ var _current_level = 0 var _loaded_level : Level var _track : Path2D +var _health = 10 # Called when the node enters the scene tree for the first time. func _ready(): - _health_bar.set_health(2) + _health_bar.maxhealth = 10 _load_current_level() func _get_next_level_pos() -> Vector2: - return Vector2(500, 0) + var dir = (randi() % 2) * 2 -1 + return _last_camera_location + Vector2(500, dir * (500 + randi() % 500)) func _create_path_from(from: Vector2, to: Vector2): var path = Path2D.new() var curve = Curve2D.new() + var diff = to -from curve.add_point(from) + curve.add_point(from + Vector2(diff.x, 0)) curve.add_point(to) path.curve = curve return path +func _add_hooks(): + _loaded_level.connect("level_finished", self, "_on_Level_level_finished") + _loaded_level.connect("lost_heart", self, "_on_Level_lost_heart") + +func _on_Level_level_finished(): + pass # TODO + +func _on_Level_lost_heart(): + _health -= 1 + if _health == 0: + pass # TODO: lose scenario + _health_bar.set_health(_health) + func _load_current_level(): if _loaded_level != null: push_error("Tried to load level, while another level was already loaded.") @@ -38,6 +55,7 @@ func _load_current_level(): print("Loading level at ",pos) _loaded_level = _levels[_current_level].instance() _loaded_level.position = pos + _add_hooks() _level_holder.add_child(_loaded_level) print("Level loaded") _track = _create_path_from(_last_camera_location, pos) @@ -46,7 +64,6 @@ func _load_current_level(): _path_renderer.path = _track _camera.path = _track - func _on_MenuButton_on_click(): _pause_menu.pause() diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 3c1a67d..126c482 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -131,6 +131,7 @@ anims/startgame = SubResource( 2 ) [node name="Outgoing" type="AnimationPlayer" parent="."] anims/tointro = SubResource( 3 ) + [connection signal="on_click" from="Content/Exit" to="." method="_on_Exit_on_click"] [connection signal="on_click" from="Content/Strart" to="." method="_on_Strart_on_click"] [connection signal="animation_finished" from="Transitions" to="." method="_on_Transitions_animation_finished"] |