summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Camera2D.gd29
-rw-r--r--components/CameraTrackFollower.gd45
-rw-r--r--components/Level.gd6
-rw-r--r--components/PathRenderer.gd28
-rw-r--r--hackingscene.gd9
-rw-r--r--hackingscene.tscn41
-rw-r--r--project.godot18
-rw-r--r--scenes/introduction.gd4
-rw-r--r--scenes/introduction.tscn1
-rw-r--r--scenes/levels/base_level.gd53
-rw-r--r--scenes/levels/base_level.tscn34
11 files changed, 150 insertions, 118 deletions
diff --git a/Camera2D.gd b/Camera2D.gd
deleted file mode 100644
index a86c692..0000000
--- a/Camera2D.gd
+++ /dev/null
@@ -1,29 +0,0 @@
-extends Camera2D
-
-onready var path : Path2D = get_node(@"../Path2D")
-onready var points = path.curve.get_baked_points()
-export var speedup = 600
-export var speedup_time = 5
-export var initial_speed = 100
-onready var current_speed = initial_speed
-var pidx = 0
-var t = 0
-
-func _process(delta):
- if pidx == -1:
- return
- var next_point = points[pidx]
- var dist : Vector2 = next_point - position
- if t < speedup_time:
- current_speed += speedup * max(0, min(speedup_time-t, delta))
- t += delta
- if dist.length() - current_speed * delta < 0.5:
- position = next_point
- pidx += 1
- if pidx >= points.size():
- pidx = -1
- _process(delta - dist.length() / current_speed )
- return
- var velocity = dist.normalized() * current_speed * delta
- position += velocity
-
diff --git a/components/CameraTrackFollower.gd b/components/CameraTrackFollower.gd
new file mode 100644
index 0000000..22420d9
--- /dev/null
+++ b/components/CameraTrackFollower.gd
@@ -0,0 +1,45 @@
+extends Camera2D
+class_name CameraTrackFollower
+var path : Path2D setget _path
+
+signal done()
+
+var _points
+func _path(value):
+ path = value
+ _pidx = 0
+ _t = 0
+ _points = value.curve.get_baked_points()
+ current_speed = 0
+ _done_emitted = false
+ print("New path set to CameraTrackFollower")
+export var speedup = 100
+export var speedup_time = 5
+export var initial_speed = 100
+var current_speed = initial_speed
+var _pidx = -1
+var _done_emitted = true
+var _t = 0
+
+func _process(delta):
+ if _pidx == -1:
+ if not _done_emitted:
+ emit_signal("done")
+ _done_emitted = true
+ 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
+ if dist.length() - current_speed * delta < 0.5:
+ position = next_point
+ _pidx += 1
+ if _pidx >= _points.size():
+ _pidx = -1
+ _process(delta - dist.length() / current_speed)
+ return
+ var velocity = dist.normalized() * current_speed * delta
+ position += velocity
+
diff --git a/components/Level.gd b/components/Level.gd
new file mode 100644
index 0000000..135a2cf
--- /dev/null
+++ b/components/Level.gd
@@ -0,0 +1,6 @@
+extends Node2D
+
+class_name Level
+
+func start():
+ print("Level starting.")
diff --git a/components/PathRenderer.gd b/components/PathRenderer.gd
index 75c7163..14853ce 100644
--- a/components/PathRenderer.gd
+++ b/components/PathRenderer.gd
@@ -1,13 +1,31 @@
extends Node2D
-onready var path : Path2D = $Path2D
-onready var points = path.curve.get_baked_points()
+class_name PathRenderer
+
+export var path_color : Color = Color.brown setget _color
+export var stroke_width : int = 6 setget _width
+var path : Path2D = null setget _path
+
+func _width(value):
+ stroke_width = value
+ update()
+
+func _color(value):
+ path_color = value
+ update()
+
+func _path(value):
+ path = value
+ update()
func _draw():
- var last_point = 0
+ if path == null:
+ return
+ var last_point = null
+ var points = path.curve.get_baked_points()
for point in points:
- if last_point is int:
+ if last_point == null:
last_point = point
continue
- draw_line(last_point, point, Color.brown, 6, false)
+ draw_line(last_point, point, path_color, stroke_width, false)
last_point = point
diff --git a/hackingscene.gd b/hackingscene.gd
deleted file mode 100644
index 641cc93..0000000
--- a/hackingscene.gd
+++ /dev/null
@@ -1,9 +0,0 @@
-extends Node2D
-
-
-var button_presses = 0
-
-
-func _on_HackButton_on_click():
- button_presses += 1
- print(button_presses)
diff --git a/hackingscene.tscn b/hackingscene.tscn
deleted file mode 100644
index 992ef96..0000000
--- a/hackingscene.tscn
+++ /dev/null
@@ -1,41 +0,0 @@
-[gd_scene load_steps=8 format=2]
-
-[ext_resource path="res://textures/backgrounds/background_blue.png" type="Texture" id=1]
-[ext_resource path="res://Camera2D.gd" type="Script" id=3]
-[ext_resource path="res://default_env.tres" type="Environment" id=4]
-[ext_resource path="res://components/HackButton.tscn" type="PackedScene" id=5]
-[ext_resource path="res://hackingscene.gd" type="Script" id=6]
-[ext_resource path="res://textures/icons/heart.png" type="Texture" id=7]
-
-[sub_resource type="Curve2D" id=1]
-_data = {
-"points": PoolVector2Array( 0, 0, 0, 0, -74.612, 128.932, 0, 0, 0, 0, 390.299, 185.629, 0, 0, 0, 0, 520.071, -115.492, 0, 0, 0, 0, 182.412, -341.018, 0, 0, 0, 0, -153.987, 20.5792, 0, 0, 0, 0, -131.308, 224.686 )
-}
-
-[node name="Node2D" type="Node2D"]
-script = ExtResource( 6 )
-
-[node name="Camera2D" type="Camera2D" parent="."]
-current = true
-script = ExtResource( 3 )
-speedup = 150
-speedup_time = 10
-
-[node name="Sprite" type="Sprite" parent="Camera2D"]
-position = Vector2( 1.49817, -2.26822 )
-scale = Vector2( 0.667, 0.681832 )
-texture = ExtResource( 1 )
-
-[node name="Path2D" type="Path2D" parent="."]
-curve = SubResource( 1 )
-
-[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
-environment = ExtResource( 4 )
-
-[node name="HackButton" parent="." instance=ExtResource( 5 )]
-
-[node name="heart" type="Sprite" parent="."]
-position = Vector2( 467.501, -263.722 )
-texture = ExtResource( 7 )
-
-[connection signal="on_click" from="HackButton" to="." method="_on_HackButton_on_click"]
diff --git a/project.godot b/project.godot
index 54a8fe2..c22efe0 100644
--- a/project.godot
+++ b/project.godot
@@ -14,11 +14,26 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://components/button.gd"
}, {
+"base": "Camera2D",
+"class": "CameraTrackFollower",
+"language": "GDScript",
+"path": "res://components/CameraTrackFollower.gd"
+}, {
"base": "",
"class": "GitAPI",
"language": "NativeScript",
"path": "res://git_api.gdns"
}, {
+"base": "Node2D",
+"class": "Level",
+"language": "GDScript",
+"path": "res://components/Level.gd"
+}, {
+"base": "Node2D",
+"class": "PathRenderer",
+"language": "GDScript",
+"path": "res://components/PathRenderer.gd"
+}, {
"base": "Label",
"class": "TextReveal",
"language": "GDScript",
@@ -26,7 +41,10 @@ _global_script_classes=[ {
} ]
_global_script_class_icons={
"ButtonTest": "",
+"CameraTrackFollower": "",
"GitAPI": "",
+"Level": "",
+"PathRenderer": "",
"TextReveal": ""
}
diff --git a/scenes/introduction.gd b/scenes/introduction.gd
index ad898f2..383091b 100644
--- a/scenes/introduction.gd
+++ b/scenes/introduction.gd
@@ -1,4 +1,4 @@
-extends Node
+extends Level
# Called when the node enters the scene tree for the first time.
@@ -10,7 +10,7 @@ func _ready():
func _on_TextReveal_finished_reveal():
$Continue.visible = true
-
+ $Skip.visible = false
func _on_Button_on_click():
diff --git a/scenes/introduction.tscn b/scenes/introduction.tscn
index 2e39729..66fc128 100644
--- a/scenes/introduction.tscn
+++ b/scenes/introduction.tscn
@@ -34,6 +34,7 @@ text = "Continue"
[node name="Skip" parent="." instance=ExtResource( 3 )]
position = Vector2( 557.234, 339.165 )
text = "Skip"
+
[connection signal="finished_reveal" from="TextReveal" to="." method="_on_TextReveal_finished_reveal"]
[connection signal="on_click" from="Continue" to="." method="_on_Button_on_click"]
[connection signal="on_click" from="Skip" to="." method="_on_Skip_on_click"]
diff --git a/scenes/levels/base_level.gd b/scenes/levels/base_level.gd
index b6967c6..b6f8a2e 100644
--- a/scenes/levels/base_level.gd
+++ b/scenes/levels/base_level.gd
@@ -1,11 +1,56 @@
extends Node2D
-onready var pause_menu = $Camera2D/PauseMenu
+onready var _pause_menu = $Camera2D/PauseMenu
+onready var _level_holder = $LevelHolder
+onready var _camera : CameraTrackFollower = $Camera2D
+onready var _path_renderer : PathRenderer = $PathRenderer
+onready var _health_bar = $Camera2D/healthbar
+onready var _last_camera_location : Vector2 = $Camera2D.position
+const _levels = [
+ preload("res://scenes/introduction.tscn")
+]
+
+var _current_level = 0
+var _loaded_level : Level
+var _track : Path2D
# Called when the node enters the scene tree for the first time.
func _ready():
- $Control/TextReveal.start()
- $Camera2D/healthbar.set_health(2)
+ _health_bar.set_health(2)
+ _load_current_level()
+
+func _get_next_level_pos() -> Vector2:
+ return Vector2(500, 0)
+
+func _create_path_from(from: Vector2, to: Vector2):
+ var path = Path2D.new()
+ var curve = Curve2D.new()
+ curve.add_point(from)
+ curve.add_point(to)
+ path.curve = curve
+ return path
+
+func _load_current_level():
+ if _loaded_level != null:
+ push_error("Tried to load level, while another level was already loaded.")
+ assert(false)
+ var pos = _get_next_level_pos()
+ print("Loading level at ",pos)
+ _loaded_level = _levels[_current_level].instance()
+ _loaded_level.position = pos
+ _level_holder.add_child(_loaded_level)
+ print("Level loaded")
+ _track = _create_path_from(_last_camera_location, pos)
+ add_child(_track)
+ print("Tracks loaded")
+ _path_renderer.path = _track
+ _camera.path = _track
+
func _on_MenuButton_on_click():
- pause_menu.pause()
+ _pause_menu.pause()
+
+
+func _on_Camera2D_done():
+ print("Camera movement done")
+ _loaded_level.start()
diff --git a/scenes/levels/base_level.tscn b/scenes/levels/base_level.tscn
index ed3023a..3092a5a 100644
--- a/scenes/levels/base_level.tscn
+++ b/scenes/levels/base_level.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=9 format=2]
+[gd_scene load_steps=8 format=2]
[ext_resource path="res://textures/backgrounds/background_grey.png" type="Texture" id=1]
[ext_resource path="res://components/PathRenderer.gd" type="Script" id=2]
@@ -6,12 +6,7 @@
[ext_resource path="res://components/button.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenes/pause.tscn" type="PackedScene" id=5]
[ext_resource path="res://scenes/levels/base_level.gd" type="Script" id=6]
-[ext_resource path="res://components/textreveal.gd" type="Script" id=7]
-
-[sub_resource type="Curve2D" id=1]
-_data = {
-"points": PoolVector2Array( 0, 0, 0, 0, 498.557, 573.469, 0, 0, 0, 0, 260.715, 288.06, 0, 0, 0, 0, 18.117, 259.519, 0, 0, 0, 0, -224.481, 259.519, 0, 0, 0, 0, -348.159, 264.276, 0, 0, 0, 0, -362.429, 378.439, 0, 0, 0, 0, -357.672, 559.199 )
-}
+[ext_resource path="res://components/CameraTrackFollower.gd" type="Script" id=7]
[node name="BaseLevel" type="Node2D"]
script = ExtResource( 6 )
@@ -19,6 +14,7 @@ script = ExtResource( 6 )
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2( 153.457, 427.259 )
current = true
+script = ExtResource( 7 )
[node name="healthbar" parent="Camera2D" instance=ExtResource( 3 )]
position = Vector2( -595.377, -321.363 )
@@ -35,31 +31,13 @@ texture = ExtResource( 1 )
[node name="PathRenderer" type="Node2D" parent="."]
script = ExtResource( 2 )
-
-[node name="Path2D" type="Path2D" parent="PathRenderer"]
-curve = SubResource( 1 )
+path_color = Color( 0, 0.741176, 1, 1 )
[node name="MenuButton" parent="." instance=ExtResource( 4 )]
position = Vector2( 725.099, 115.66 )
text = "Menu"
-[node name="Control" type="Control" parent="."]
-margin_left = 57.67
-margin_top = 289.516
-margin_right = 97.67
-margin_bottom = 329.516
-
-[node name="TextReveal" type="Label" parent="Control"]
-margin_right = 40.0
-margin_bottom = 14.0
-script = ExtResource( 7 )
-__meta__ = {
-"_edit_use_anchors_": false
-}
-to_render = "Im Folgenden finden Sie Neuerungen/Änderungen zu den nationalen und internationalen Beförderungsbedingungen der DB Fernverkehr AG und der DB Regio AG gemäß Paragraph 12 Absatz 6 Allgemeines Eisenbahngesetz (AEG).
-Tarifbekanntmachung national DB Fernverkehr AG und DB Regio AG, Stand 16.04.2021 (PDF, 261KB)
-Tarifbekanntmachungen international DB Fernverkehr AG, Stand 24.04.2021 (PDF, 128KB)"
-speed = 10.0
-
[node name="LevelHolder" type="Node2D" parent="."]
+
+[connection signal="done" from="Camera2D" to="." method="_on_Camera2D_done"]
[connection signal="on_click" from="MenuButton" to="." method="_on_MenuButton_on_click"]