Add a clock, scheduler and schedule the postie's arrival

This commit is contained in:
Olivier 'reivilibre' 2023-01-08 23:21:54 +00:00
parent f41f32380a
commit 1585a2d7b3
17 changed files with 350 additions and 9 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2] [gd_scene load_steps=9 format=2]
[ext_resource path="res://scenery/tiles/ohld_tileset.tres" type="TileSet" id=1] [ext_resource path="res://scenery/tiles/ohld_tileset.tres" type="TileSet" id=1]
[ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://characters/player/Player.tscn" type="PackedScene" id=2]
@ -6,7 +6,6 @@
[ext_resource path="res://scenery/facilities/Wheelbarrow.tscn" type="PackedScene" id=4] [ext_resource path="res://scenery/facilities/Wheelbarrow.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenery/facilities/Press.tscn" type="PackedScene" id=5] [ext_resource path="res://scenery/facilities/Press.tscn" type="PackedScene" id=5]
[ext_resource path="res://scenery/tiles/road.png" type="Texture" id=6] [ext_resource path="res://scenery/tiles/road.png" type="Texture" id=6]
[ext_resource path="res://vehicles/Postie.tscn" type="PackedScene" id=7]
[ext_resource path="res://ui/Hud.tscn" type="PackedScene" id=8] [ext_resource path="res://ui/Hud.tscn" type="PackedScene" id=8]
[sub_resource type="TileSet" id=1] [sub_resource type="TileSet" id=1]
@ -66,12 +65,7 @@ position = Vector2( 135, 190 )
[node name="Node2D3" parent="World/YSort" instance=ExtResource( 4 )] [node name="Node2D3" parent="World/YSort" instance=ExtResource( 4 )]
position = Vector2( 542, 475 ) position = Vector2( 542, 475 )
[node name="Postie" parent="World/YSort" instance=ExtResource( 7 )]
position = Vector2( 418, 768 )
[node name="MarkerRoadPoint" type="Node2D" parent="World"] [node name="MarkerRoadPoint" type="Node2D" parent="World"]
position = Vector2( 328, 770 ) position = Vector2( 328, 770 )
[node name="Hud" parent="." instance=ExtResource( 8 )] [node name="Hud" parent="." instance=ExtResource( 8 )]
margin_right = 1261.0
margin_bottom = 740.0

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://ui/normal_font.tres" type="DynamicFont" id=1] [ext_resource path="res://ui/normal_font.tres" type="DynamicFont" id=1]
[ext_resource path="res://ui/coin.png" type="Texture" id=2] [ext_resource path="res://ui/coin.png" type="Texture" id=2]
[ext_resource path="res://ui/Hud.gd" type="Script" id=3] [ext_resource path="res://ui/Hud.gd" type="Script" id=3]
[ext_resource path="res://ui/Scheduler.tscn" type="PackedScene" id=4]
[node name="Hud" type="Node2D"] [node name="Hud" type="Node2D"]
z_index = 50 z_index = 50
@ -32,3 +33,9 @@ text = "0"
[node name="Coin" type="Sprite" parent="HudInner/Panel"] [node name="Coin" type="Sprite" parent="HudInner/Panel"]
position = Vector2( 31, 37 ) position = Vector2( 31, 37 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="Scheduler" parent="HudInner/Panel" instance=ExtResource( 4 )]
margin_left = 120.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -88.0

55
ui/Scheduler.gd Normal file
View File

@ -0,0 +1,55 @@
extends Control
var DAY_PER_SEC = 0.02
func _ready():
# TODO set up calendar
# set up clock
_set_up_postie_clock()
_start_schedule()
func _set_up_postie_clock():
for start_time in postie_times:
var end_time = start_time + postie_length
var start_segment = round(10 * start_time)
var end_segment = round(10 * end_time)
for i in range(start_segment, end_segment):
$Clock/PostieRegions.get_child(i % 10).visible = true
var days_on_this_level = 5
var postie_times = [0.1]
var postie_length = .3
var day_num = 0
var time_of_day = 0.0
func _start_schedule():
# schedule all events for the day...
for day in range(days_on_this_level):
var parent = find_parent("Level*").get_node("World/YSort")
for postie_time in postie_times:
# 5s early so the postie has time to drive there.
_postie_in(parent, (postie_time / DAY_PER_SEC) - 5.0, postie_length / DAY_PER_SEC)
yield(get_tree().create_timer(1 / DAY_PER_SEC, false), "timeout")
func _postie_in(parent: Node2D, time: float, idling_time: float):
yield(get_tree().create_timer(time, false), "timeout")
var new_postie = preload("res://vehicles/Postie.tscn").instance()
new_postie.position = Vector2(-500, 0)
new_postie.idling_time = idling_time
parent.add_child(new_postie)
func _process(delta):
var old_time = time_of_day
time_of_day += delta * DAY_PER_SEC
$Clock/ClockHand.rotation = 2 * PI * fmod(time_of_day, 1.0)

120
ui/Scheduler.tscn Normal file
View File

@ -0,0 +1,120 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://ui/calendar.png" type="Texture" id=1]
[ext_resource path="res://ui/clock.png" type="Texture" id=2]
[ext_resource path="res://ui/normal_theme.tres" type="Theme" id=3]
[ext_resource path="res://ui/clock_hand.png" type="Texture" id=4]
[ext_resource path="res://ui/Scheduler.gd" type="Script" id=5]
[ext_resource path="res://ui/clock_postie_region.png" type="Texture" id=6]
[node name="Scheduler" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 5 )
[node name="Calendar" type="Sprite" parent="."]
position = Vector2( 139, 119 )
texture = ExtResource( 1 )
offset = Vector2( -91, -87 )
[node name="LabelCalendar" type="Label" parent="."]
margin_top = 66.0
margin_right = 94.0
margin_bottom = 93.0
rect_pivot_offset = Vector2( 139, 53 )
theme = ExtResource( 3 )
text = "Calendar"
align = 1
[node name="Clock" type="Sprite" parent="."]
position = Vector2( 151, 36 )
texture = ExtResource( 2 )
[node name="ClockHand" type="Sprite" parent="Clock"]
texture = ExtResource( 4 )
centered = false
offset = Vector2( -4, -20 )
[node name="PostieRegions" type="Node2D" parent="Clock"]
[node name="PostieRegion1" type="Sprite" parent="Clock/PostieRegions"]
visible = false
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion2" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = 0.628319
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion3" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = 1.25664
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion4" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = 1.88496
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion5" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = 2.51327
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion6" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = -3.14159
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion7" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = -2.51327
scale = Vector2( 1, 1 )
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion8" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = -1.88496
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion9" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = -1.25664
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="PostieRegion10" type="Sprite" parent="Clock/PostieRegions"]
visible = false
rotation = -0.628319
texture = ExtResource( 6 )
centered = false
offset = Vector2( -2, -32 )
[node name="LabelClock" type="Label" parent="."]
margin_left = 103.0
margin_top = 66.0
margin_right = 197.0
margin_bottom = 93.0
rect_pivot_offset = Vector2( 139, 53 )
theme = ExtResource( 3 )
text = "Clock"
align = 1
[node name="Timer" type="Timer" parent="."]

BIN
ui/calendar.kra (Stored with Git LFS) Normal file

Binary file not shown.

BIN
ui/calendar.png (Stored with Git LFS) Normal file

Binary file not shown.

35
ui/calendar.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/calendar.png-dd732786e3f6374d05829fdf0dad7f88.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/calendar.png"
dest_files=[ "res://.import/calendar.png-dd732786e3f6374d05829fdf0dad7f88.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
ui/clock.kra (Stored with Git LFS) Normal file

Binary file not shown.

BIN
ui/clock.png (Stored with Git LFS) Normal file

Binary file not shown.

35
ui/clock.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/clock.png-09b4a660a58c86478b8ce31163fe5a4d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/clock.png"
dest_files=[ "res://.import/clock.png-09b4a660a58c86478b8ce31163fe5a4d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
ui/clock_hand.kra (Stored with Git LFS) Normal file

Binary file not shown.

BIN
ui/clock_hand.png (Stored with Git LFS) Normal file

Binary file not shown.

35
ui/clock_hand.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/clock_hand.png-6b703f276e30e448e2d424ebe0e182f6.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/clock_hand.png"
dest_files=[ "res://.import/clock_hand.png-6b703f276e30e448e2d424ebe0e182f6.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
ui/clock_postie_region.kra (Stored with Git LFS) Normal file

Binary file not shown.

BIN
ui/clock_postie_region.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/clock_postie_region.png-ce30bb29082ee859f65c40c5bb09037f.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/clock_postie_region.png"
dest_files=[ "res://.import/clock_postie_region.png-ce30bb29082ee859f65c40c5bb09037f.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -6,6 +6,7 @@ extends Node2D
# var b = "text" # var b = "text"
var marker: Node2D = null var marker: Node2D = null
var idling_time: float = 5.0
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -41,7 +42,7 @@ func _on_driven_in():
$BackgateOpenSfx.pitch_scale = rand_range(0.8, 1.2) $BackgateOpenSfx.pitch_scale = rand_range(0.8, 1.2)
$BackgateOpenSfx.play() $BackgateOpenSfx.play()
$Tween.interpolate_callback(self, 5.0, "_drive_off") $Tween.interpolate_callback(self, idling_time, "_drive_off")
$Tween.start() $Tween.start()
func _drive_off(): func _drive_off():