aboutsummaryrefslogtreecommitdiffstats
path: root/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/car_behaviour.gd3
-rw-r--r--Scripts/drawing.gd28
-rw-r--r--Scripts/game.gd104
-rw-r--r--Scripts/main_menu.gd25
4 files changed, 145 insertions, 15 deletions
diff --git a/Scripts/car_behaviour.gd b/Scripts/car_behaviour.gd
index d5fc292..2ef9fb9 100644
--- a/Scripts/car_behaviour.gd
+++ b/Scripts/car_behaviour.gd
@@ -95,8 +95,7 @@ func own_movement(delta):
var desired_velocity = chosen_dir.rotated(rotation) * max_speed
var actual_speed = lerpf(velocity.length(), max_speed, acceleration)
- var actual_angle = lerp_angle(velocity.angle(), desired_velocity.angle(),
- steer_force)
+ var actual_angle = lerp_angle(velocity.angle(), desired_velocity.angle(), steer_force)
velocity = Vector2.from_angle(actual_angle) * actual_speed
rotation = actual_angle
diff --git a/Scripts/drawing.gd b/Scripts/drawing.gd
index 2e4af95..51e7f21 100644
--- a/Scripts/drawing.gd
+++ b/Scripts/drawing.gd
@@ -14,19 +14,21 @@ func _process(delta):
func _physics_process(delta):
pass
+
+func _start_drawing():
+ line.clear_points()
+ path.curve.clear_points()
+ drawing = true
+ owner.set_driving(false)
+
+
+func _end_drawing():
+ drawing = false
+ owner.set_driving(true)
+
+
func _input(event):
- if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
- drawing = event.pressed
- if drawing:
- # start a new drawing
- line.clear_points()
- path.curve.clear_points()
- owner.set_driving(false)
- else:
- # start driving
- owner.set_driving(true)
-
- if event is InputEventMouseMotion and drawing:
- # extend the line
+ if drawing and event is InputEventMouseMotion:
line.add_point(event.position)
path.curve.add_point(event.position)
+
diff --git a/Scripts/game.gd b/Scripts/game.gd
new file mode 100644
index 0000000..bacb709
--- /dev/null
+++ b/Scripts/game.gd
@@ -0,0 +1,104 @@
+extends Node2D
+
+const NUM_LEVELS = 3
+
+# level control
+var current_level_id = 0
+var levels = []
+var post_game = false
+
+var scenes = [
+# preload("res://Nodes/levels/level1/level1.tscn"),
+# preload("res://Nodes/levels/level2/level2.tscn")
+ preload("res://Nodes/Level_test.tscn")
+ ]
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+# $JinglePlayer.stream.loop_mode = AudioStream.LOOP_DISABLED
+ load_scene_by_index(0)
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+ if Input.is_action_just_pressed("ui_cancel"):
+ close_scoreboard()
+ get_tree().paused = true
+ $PausePopup.show()
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+
+
+func _on_QuitButton_pressed():
+ get_tree().quit()
+
+
+func _on_ResumeButton_pressed():
+ print('aaaa')
+ $PausePopup.hide()
+ get_tree().paused = false
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+
+
+func _on_MainMenuButton_pressed():
+ get_tree().paused = false
+ get_tree().change_scene_to_file("res://Nodes/main_menu.tscn")
+
+
+func end_level():
+ open_scoreboard()
+# evaluate_player(current_strokes, PAR[current_level_id])
+ $BGMPLayer.stream_paused = true
+ $JinglePlayer.play()
+ post_game = true
+
+
+func open_scoreboard():
+# strokes_per_level[current_level_id] = current_strokes
+# $Scoreboard.update_values(strokes_per_level, PAR)
+# $Scoreboard.show()
+ pass
+
+
+func close_scoreboard():
+# $Scoreboard.hide()
+ pass
+
+
+func is_post_game():
+ return post_game
+
+
+func next_level():
+ post_game = false
+ current_level_id += 1
+
+ if current_level_id >= NUM_LEVELS:
+ get_tree().change_scene("res://scenes/levels/MainMenu.tscn")
+ return
+
+ load_scene_by_index(current_level_id)
+ close_scoreboard()
+ $Evaluation.hide()
+
+ $BGMPLayer.stream_paused = false
+ $JinglePlayer.stop()
+
+
+func evaluate_player(strokes, par):
+ $Evaluation/EvaluationLabel.text = "%d Seconds" % 42
+ $Evaluation.show()
+
+
+func _on_JinglePlayer_finished():
+ $BGMPLayer.stream_paused = false
+
+
+func load_scene_by_index(index):
+ # clear level
+ for n in $LoadedLevel.get_children():
+ $LoadedLevel.remove_child(n)
+ n.queue_free()
+
+ # add new level
+ var instance = scenes[index].instantiate()
+ $LoadedLevel.add_child(instance)
diff --git a/Scripts/main_menu.gd b/Scripts/main_menu.gd
new file mode 100644
index 0000000..3bfe28e
--- /dev/null
+++ b/Scripts/main_menu.gd
@@ -0,0 +1,25 @@
+extends Control
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+ pass
+
+
+func _on_StartButton_pressed():
+ get_tree().change_scene_to_file("res://Nodes/game.tscn")
+
+
+
+func _on_QuitButton_pressed():
+ get_tree().quit()