diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-02-09 00:05:05 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-02-09 00:05:05 -0500 |
commit | 46d7e793031a4ac534aa50da43408f4330abe8dc (patch) | |
tree | adfcf6211c15e1fe0b1e8cc6e8431655aea05d3c /racing | |
parent | 2ce58f86aa74f1fd904690cb3ba3438bee4b765f (diff) | |
download | lingo-race-46d7e793031a4ac534aa50da43408f4330abe8dc.tar.gz lingo-race-46d7e793031a4ac534aa50da43408f4330abe8dc.tar.bz2 lingo-race-46d7e793031a4ac534aa50da43408f4330abe8dc.zip |
Timer
Diffstat (limited to 'racing')
-rw-r--r-- | racing/load.gd | 25 | ||||
-rw-r--r-- | racing/lobby.gd | 2 | ||||
-rw-r--r-- | racing/manager.gd | 6 | ||||
-rw-r--r-- | racing/multiplayer.gd | 21 |
4 files changed, 47 insertions, 7 deletions
diff --git a/racing/load.gd b/racing/load.gd index cd60c65..1455171 100644 --- a/racing/load.gd +++ b/racing/load.gd | |||
@@ -29,14 +29,23 @@ func _load(): | |||
29 | label.align = Label.ALIGN_RIGHT | 29 | label.align = Label.ALIGN_RIGHT |
30 | label.valign = Label.VALIGN_TOP | 30 | label.valign = Label.VALIGN_TOP |
31 | 31 | ||
32 | var timer_label = Label.new() | ||
33 | timer_label.set_name("timer_label") | ||
34 | timer_label.margin_left = 20.0 | ||
35 | timer_label.margin_top = 20.0 | ||
36 | timer_label.align = Label.ALIGN_LEFT | ||
37 | timer_label.valign = Label.VALIGN_TOP | ||
38 | |||
32 | var dynamic_font = DynamicFont.new() | 39 | var dynamic_font = DynamicFont.new() |
33 | dynamic_font.font_data = load("res://fonts/Lingo.ttf") | 40 | dynamic_font.font_data = load("res://fonts/Lingo.ttf") |
34 | dynamic_font.size = 36 | 41 | dynamic_font.size = 36 |
35 | dynamic_font.outline_color = Color(0, 0, 0, 1) | 42 | dynamic_font.outline_color = Color(0, 0, 0, 1) |
36 | dynamic_font.outline_size = 2 | 43 | dynamic_font.outline_size = 2 |
37 | label.add_font_override("font", dynamic_font) | 44 | label.add_font_override("font", dynamic_font) |
45 | timer_label.add_font_override("font", dynamic_font) | ||
38 | 46 | ||
39 | add_child(label) | 47 | add_child(label) |
48 | add_child(timer_label) | ||
40 | 49 | ||
41 | var panel_script = load("res://nodes/panel_1.tscn") | 50 | var panel_script = load("res://nodes/panel_1.tscn") |
42 | var victory_panel = panel_script.instance() | 51 | var victory_panel = panel_script.instance() |
@@ -56,6 +65,13 @@ func _load(): | |||
56 | "MeshInstance5" | 65 | "MeshInstance5" |
57 | ) | 66 | ) |
58 | 67 | ||
68 | var timer = Timer.new() | ||
69 | timer.name = "Timer" | ||
70 | timer.set_wait_time(0.03) | ||
71 | timer.set_one_shot(false) | ||
72 | timer.connect("timeout", self, "bump_timer") | ||
73 | add_child(timer) | ||
74 | |||
59 | global._print("Hooked Load Stop") | 75 | global._print("Hooked Load Stop") |
60 | 76 | ||
61 | ._load() | 77 | ._load() |
@@ -66,6 +82,7 @@ func _load(): | |||
66 | 82 | ||
67 | 83 | ||
68 | func victory(): | 84 | func victory(): |
85 | get_node("Timer").stop() | ||
69 | get_node("Multiplayer").player_victory() | 86 | get_node("Multiplayer").player_victory() |
70 | ingame_achieve("Victory!") | 87 | ingame_achieve("Victory!") |
71 | 88 | ||
@@ -76,3 +93,11 @@ func set_gridmap_tile(x, y, z, tile): | |||
76 | var mapvec = gridmap.world_to_map(gridmap.to_local(Vector3(x, y, z))) | 93 | var mapvec = gridmap.world_to_map(gridmap.to_local(Vector3(x, y, z))) |
77 | 94 | ||
78 | gridmap.set_cell_item(mapvec.x, mapvec.y, mapvec.z, mesh_library.find_item_by_name(tile)) | 95 | gridmap.set_cell_item(mapvec.x, mapvec.y, mapvec.z, mesh_library.find_item_by_name(tile)) |
96 | |||
97 | |||
98 | func bump_timer(): | ||
99 | var race_manager = global.get_node("RaceManager") | ||
100 | var elapsed = float(Time.get_ticks_msec() - race_manager.started_time) / 1000.0 | ||
101 | get_node("timer_label").text = ( | ||
102 | "%d:%02d:%02.2f" % [int(elapsed) / 60 / 60, int(elapsed) / 60 % 60, fmod(elapsed, 60.0)] | ||
103 | ) | ||
diff --git a/racing/lobby.gd b/racing/lobby.gd index 38402de..c6a3e24 100644 --- a/racing/lobby.gd +++ b/racing/lobby.gd | |||
@@ -15,7 +15,7 @@ const MAX_PLAYERS = 250 | |||
15 | const PROTOCOL_VERSION = 2 | 15 | const PROTOCOL_VERSION = 2 |
16 | const RECIPIENT_BROADCAST_ALL = -1 | 16 | const RECIPIENT_BROADCAST_ALL = -1 |
17 | const LOBBY_MAP_NAME = "ll1_racing" | 17 | const LOBBY_MAP_NAME = "ll1_racing" |
18 | const VERSION = "0.0.6" | 18 | const VERSION = "0.0.7" |
19 | 19 | ||
20 | const LL1_AREAS = [ | 20 | const LL1_AREAS = [ |
21 | ["Starting Room", 0, 0, 0], | 21 | ["Starting Room", 0, 0, 0], |
diff --git a/racing/manager.gd b/racing/manager.gd index f8b7ef7..349b83e 100644 --- a/racing/manager.gd +++ b/racing/manager.gd | |||
@@ -6,6 +6,7 @@ var start_pos | |||
6 | var end_pos | 6 | var end_pos |
7 | var lobby_id | 7 | var lobby_id |
8 | var held_messages = [] | 8 | var held_messages = [] |
9 | var started_time | ||
9 | 10 | ||
10 | 11 | ||
11 | func everyone_ready(): | 12 | func everyone_ready(): |
@@ -29,3 +30,8 @@ func everyone_ready(): | |||
29 | yield(get_tree().create_timer(0.5), "timeout") | 30 | yield(get_tree().create_timer(0.5), "timeout") |
30 | 31 | ||
31 | get_node("/root/Spatial/Multiplayer").send_timeout() | 32 | get_node("/root/Spatial/Multiplayer").send_timeout() |
33 | |||
34 | |||
35 | func start_timer(): | ||
36 | started_time = Time.get_ticks_msec() | ||
37 | get_node("/root/Spatial/Timer").start() | ||
diff --git a/racing/multiplayer.gd b/racing/multiplayer.gd index 52d76bf..0dfebf2 100644 --- a/racing/multiplayer.gd +++ b/racing/multiplayer.gd | |||
@@ -143,8 +143,10 @@ func _on_lobby_joined(lobby_id: int, _permissions: int, _locked: bool, result: i | |||
143 | 143 | ||
144 | 144 | ||
145 | func _on_lobby_chat_update( | 145 | func _on_lobby_chat_update( |
146 | _lobby_id: int, _member_id: int, _making_change_id: int, _chat_state: int | 146 | _lobby_id: int, member_id: int, _making_change_id: int, chat_state: int |
147 | ) -> void: | 147 | ) -> void: |
148 | if chat_state == Steam.CHAT_MEMBER_STATE_CHANGE_LEFT: | ||
149 | messages.showMessage("%s has left the room" % Steam.getFriendPersonaName(member_id)) | ||
148 | _update_lobby_members() | 150 | _update_lobby_members() |
149 | 151 | ||
150 | 152 | ||
@@ -231,7 +233,8 @@ func _handle_packet(packet): | |||
231 | if "timeout" in data: | 233 | if "timeout" in data: |
232 | _update_lobby_members() | 234 | _update_lobby_members() |
233 | if "victory" in data: | 235 | if "victory" in data: |
234 | _someone_victory(Steam.getFriendPersonaName(remote_id)) | 236 | _someone_victory(Steam.getFriendPersonaName(remote_id), data["victory"]) |
237 | messages.showMessage("%s reached the goal" % Steam.getFriendPersonaName(remote_id)) | ||
235 | if "ack" in data: | 238 | if "ack" in data: |
236 | messages_needing_ack.erase(data["ack"]) | 239 | messages_needing_ack.erase(data["ack"]) |
237 | _update_lobby_members() | 240 | _update_lobby_members() |
@@ -294,6 +297,7 @@ func time_to_start(): | |||
294 | get_node("/root/Spatial/label").text = ( | 297 | get_node("/root/Spatial/label").text = ( |
295 | "Destination: %s" % global.get_node("RaceManager").end_pos[0] | 298 | "Destination: %s" % global.get_node("RaceManager").end_pos[0] |
296 | ) | 299 | ) |
300 | global.get_node("RaceManager").start_timer() | ||
297 | get_node("/root/Spatial").ingame_achieve("Go!") | 301 | get_node("/root/Spatial").ingame_achieve("Go!") |
298 | 302 | ||
299 | 303 | ||
@@ -302,15 +306,20 @@ func player_victory(): | |||
302 | global._print("(MP) Victory!") | 306 | global._print("(MP) Victory!") |
303 | is_victory = true | 307 | is_victory = true |
304 | _send_p2p_packet( | 308 | _send_p2p_packet( |
305 | {"victory": "true"}, RECIPIENT_BROADCAST_ALL, Steam.P2P_SEND_RELIABLE, true | 309 | {"victory": get_node("/root/Spatial/timer_label").text}, |
310 | RECIPIENT_BROADCAST_ALL, | ||
311 | Steam.P2P_SEND_RELIABLE, | ||
312 | true | ||
313 | ) | ||
314 | _someone_victory( | ||
315 | Steam.getFriendPersonaName(player_steam_id), get_node("/root/Spatial/timer_label").text | ||
306 | ) | 316 | ) |
307 | _someone_victory(Steam.getFriendPersonaName(player_steam_id)) | ||
308 | 317 | ||
309 | 318 | ||
310 | func _someone_victory(name): | 319 | func _someone_victory(name, time): |
311 | if !victorious_players.has(name): | 320 | if !victorious_players.has(name): |
312 | global._print("(MP) Someone's victory") | 321 | global._print("(MP) Someone's victory") |
313 | victorious_players.append(name) | 322 | victorious_players.append(name) |
314 | 323 | ||
315 | var label = get_node("/root/Spatial/label") | 324 | var label = get_node("/root/Spatial/label") |
316 | label.text = "%s\n%s is #%d" % [label.text, name, victorious_players.size()] | 325 | label.text = "%s\n#%d: %s (%s)" % [label.text, victorious_players.size(), name, time] |