Skip to content

Commit

Permalink
UI and objectives (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mineiwik authored Oct 2, 2023
2 parents 08b485d + a1b6f92 commit 7b409ff
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 97 deletions.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/logo.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bjxu5n6jwtw21"
path="res://.godot/imported/logo.png-e2220799298e3631eb0e245316e0501a.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/logo.png"
dest_files=["res://.godot/imported/logo.png-e2220799298e3631eb0e245316e0501a.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
107 changes: 107 additions & 0 deletions prefabs/Level.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
[gd_scene load_steps=4 format=3 uid="uid://cq6ckyed0ps4t"]

[ext_resource type="Theme" uid="uid://dsugnc7jkb7q5" path="res://themes/main.tres" id="1_njgw4"]
[ext_resource type="Script" path="res://scripts/Level.gd" id="2_rrx3j"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ge2tl"]
bg_color = Color(0.0745098, 0.0745098, 0.0745098, 0.921569)

[node name="Level" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme = ExtResource("1_njgw4")
script = ExtResource("2_rrx3j")

[node name="Control" type="Control" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 20.0
offset_top = 20.0
offset_right = -20.0
offset_bottom = -20.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2

[node name="Time" type="Label" parent="Control"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -90.0
offset_bottom = 38.0
grow_horizontal = 0
theme_override_font_sizes/font_size = 30
text = "00:01"

[node name="VBoxContainer" type="VBoxContainer" parent="Control"]
layout_mode = 1
anchors_preset = 9
anchor_bottom = 1.0
offset_right = 167.0
grow_vertical = 2

[node name="Label" type="Label" parent="Control/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 30
text = "Objectives"

[node name="HSeparator" type="HSeparator" parent="Control/VBoxContainer"]
layout_mode = 2

[node name="Spacer" type="Control" parent="Control/VBoxContainer"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2

[node name="GameOver" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_ge2tl")

[node name="VBoxContainer" type="VBoxContainer" parent="GameOver"]
layout_mode = 1
anchors_preset = 13
anchor_left = 0.5
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -173.5
offset_right = 173.5
grow_horizontal = 2
grow_vertical = 2
alignment = 1

[node name="Label" type="Label" parent="GameOver/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 60
text = "GAME OVER"
horizontal_alignment = 1
vertical_alignment = 1

[node name="Control" type="Control" parent="GameOver/VBoxContainer"]
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
mouse_filter = 2

[node name="HBoxContainer" type="HBoxContainer" parent="GameOver/VBoxContainer"]
layout_mode = 2
theme_override_constants/separation = 20
alignment = 1

[node name="Button" type="Button" parent="GameOver/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "main menu"

[node name="Button2" type="Button" parent="GameOver/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "restart level"
2 changes: 1 addition & 1 deletion prefabs/TrainRoute.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

[ext_resource type="Script" path="res://scripts/TrainRoute.gd" id="1_xh0bb"]

[node name="TrainRoute" type="Node2D"]
[node name="TrainRoute" type="Node2D" groups=["train_route"]]
script = ExtResource("1_xh0bb")
metadata/_edit_lock_ = true
4 changes: 2 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ config_version=5
[application]

config/name="LD54"
run/main_scene="res://scenes/Level1.tscn"
run/main_scene="res://scenes/MainMenu.tscn"
config/features=PackedStringArray("4.1", "Forward Plus")
config/icon="res://assets/icon.svg"
config/icon="res://assets/logo.png"

[input]

Expand Down
94 changes: 35 additions & 59 deletions scenes/Level1.tscn

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions scenes/MainMenu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[gd_scene load_steps=5 format=3 uid="uid://6a8n0e0kkslr"]

[ext_resource type="Theme" uid="uid://dsugnc7jkb7q5" path="res://themes/main.tres" id="1_05twq"]
[ext_resource type="Script" path="res://scripts/MainMenu.gd" id="2_6abnn"]
[ext_resource type="Texture2D" uid="uid://c2udkkfuwbis0" path="res://assets/warn.png" id="2_ca7mh"]
[ext_resource type="PackedScene" uid="uid://bhjkcskfwdbug" path="res://scenes/Level1.tscn" id="3_nclby"]

[node name="MainMenu" type="CenterContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_05twq")
script = ExtResource("2_6abnn")
start_level = ExtResource("3_nclby")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="Control" type="Control" parent="VBoxContainer"]
custom_minimum_size = Vector2(500, 100)
layout_mode = 2
size_flags_vertical = 3

[node name="TextureRect" type="TextureRect" parent="VBoxContainer/Control"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -43.9999
offset_top = -85.0
offset_right = -11.9999
offset_bottom = -53.0
grow_horizontal = 0
rotation = 0.401426
scale = Vector2(4.5, 4.5)
texture = ExtResource("2_ca7mh")

[node name="Label" type="Label" parent="VBoxContainer/Control"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = 1.0
offset_bottom = 2.0
grow_horizontal = 2
grow_vertical = 2
theme_override_font_sizes/font_size = 86
text = "LOCO LOGIC"
horizontal_alignment = 1
vertical_alignment = 1
uppercase = true

[node name="Control2" type="Control" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 15)
layout_mode = 2

[node name="Button" type="Button" parent="VBoxContainer"]
custom_minimum_size = Vector2(75, 0)
layout_mode = 2
size_flags_horizontal = 4
text = "Start"

[connection signal="pressed" from="VBoxContainer/Button" to="." method="_on_start_button_pressed"]
49 changes: 49 additions & 0 deletions scripts/Level.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extends Control

@onready var _time_display: Label = $Control/Time
@onready var _objective_container: Container = $Control/VBoxContainer
@onready var _game_over: Control = $GameOver

var _start_time_ms: int
var _routes: Array[TrainRoute]
var _route_labels: Array[Label]
var _objective_counters: Array[int]

func _ready() -> void:
self._start_time_ms = Time.get_ticks_msec()
self._game_over.set_visible(false)

var tree := self.get_tree()
self._routes.assign(tree.get_nodes_in_group("train_route"))

var route_idx := 0
for route in self._routes:
route.train_stopped.connect(self._on_train_stopped.bind(route_idx))
route.train_game_over.connect(self._on_train_game_over.bind(route_idx))

var label := Label.new()
self._objective_container.add_child(label)
self._route_labels.push_back(label)
self._objective_counters.push_back(0)
self._update_objective(route_idx)

route_idx += 1

func _process(_delta: float) -> void:
var offset_ms := Time.get_ticks_msec() - self._start_time_ms
var secs := int(offset_ms / 1000.0) % 60
var minutes = int(offset_ms / 60_000.0)
self._time_display.text = "%d:%02d" % [minutes, secs]

func _on_train_game_over(_train: TrainEngine, _route_idx: int) -> void:
self._game_over.set_visible(true)

func _on_train_stopped(_train: TrainEngine, route_idx: int) -> void:
self._objective_counters[route_idx] += 1
self._update_objective(route_idx)

func _update_objective(route_idx: int) -> void:
var route := self._routes[route_idx]
var label := self._route_labels[route_idx]
var counter := self._objective_counters[route_idx]
label.text = "%s: %s/5" % [route.route_name, counter]
18 changes: 0 additions & 18 deletions scripts/Levels/Level1.gd

This file was deleted.

6 changes: 6 additions & 0 deletions scripts/MainMenu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends CenterContainer

@export var start_level: PackedScene

func _on_start_button_pressed() -> void:
self.get_tree().change_scene_to_packed(self.start_level)
4 changes: 4 additions & 0 deletions scripts/TrainEngine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func _ready() -> void:
self.front_wheel.new_track_entered.connect(self._on_track_entered)
self._update_frictions()

func set_color(new_color: Color) -> void:
self.color = new_color
super.set_color(new_color)

func connect_tracks_controller(tracks_controller: TracksController) -> void:
tracks_controller.track_changed.connect(self._on_track_change)

Expand Down
Loading

0 comments on commit 7b409ff

Please sign in to comment.