-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmainloop.lua
2847 lines (2542 loc) · 99.5 KB
/
mainloop.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
----------------------
-- Main Loop
-- Contains all the functions responsible for the implementation of the game's main loop.
-- @module mainloop
require("constants")
local coroutine_wait = coroutine.yield
local coroutine_resume = coroutine.resume
local versionString = "023"
local currently_spectating = false
local connectionUptime = 0
local isLoggedIn = false
local connectedServerIp = nil
local playerUsername = nil
local leaderboard_report = nil
local replay_of_match_so_far = nil
local spectator_list = nil
local debug_mode_text = {[true]="On", [false]="Off"}
--- Loads the game's resources, such as config files, sound components and graphics
-- @tparam nil
-- @treturn nil
function load_game_resources()
local func, arg = main_select_mode, nil
replay = {}
gprint("Reading config file", X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
read_conf_file() -- @todo stop making new config files
gprint("Reading replay file", X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
read_replay_file()
gprint("Loading graphics...", X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
graphics_init() -- loads images and sets up graphical components
gprint("Loading sounds... (this takes a few seconds)", X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
sound_init() -- loads sound components
-- i literally have no idea why this loop is this way
while true do
leftover_time = 1 / 120
consuming_timesteps = false
func,arg = func(unpack(arg or {}))
collectgarbage("collect")
end
end
--- Wraps a function and runs it at 60hz
-- The rest of the stuff happens at whatever rate is convenient
-- @param func The function to be wrapped
function run_function_as_60hz(func)
local frequency = 1 / 60
assert(func, "function parameter is nil")
for i=1, 4 do
if leftover_time >= frequency then
func()
key_counts() -- increments the number of times a key was pressed
this_frame_keys = {}
leftover_time = leftover_time - frequency
else
-- Nothing to do.
end
end
end
--- Changes the behavior of menu_foo functions.
-- In a menu that doesn't specifically pertain to multiple players,
-- up, down, left, right should always work. But in a multiplayer
-- menu, those keys should definitely not move many cursors each.
-- @param func a function
-- @return
function multi_func(func)
local multi = false
assert(func, "multi_func is nil")
return function(...)
multi = true
local res = {func(...)}
multi = false
return unpack(res)
end
end
-- Loop containing the main menu's behaviour
do
local active_idx = 1
--- Responsible for displaying the game's main menu
-- @tparam nil
-- @treturn nil
function main_select_mode()
love.audio.stop()
close_socket()
local isLoggedIn = false
local connectionUptime = 0
local connectedServerIp = ""
local serverSupportsRanking = false
local matchType = ""
local matchTypeMessage = ""
-- contains all menu options
local menu_options = {
{
"1P endless",
select_speed_and_level_menu,
{main_endless}
},
{
"1P puzzle",
main_select_puzz
},
{
"1P time attack",
select_speed_and_level_menu,
{main_time_attack}
},
{
"1P vs yourself",
main_local_vs_yourself_setup
},
--{"2P vs online at burke.ro", main_net_vs_setup, {"burke.ro"}},
{
"2P vs online at Jon's server",
main_net_vs_setup,
{"18.188.43.50"}
},
--{"2P vs online at domi1819.xyz (Europe, beta for spectating and ranking)", main_net_vs_setup, {"domi1819.xyz"}},
--{"2P vs online at localhost (development-use only)", main_net_vs_setup, {"localhost"}},
{
"2P vs local game",
main_local_vs_setup
},
{
"Replay of 1P endless",
main_replay_endless
},
{
"Replay of 1P puzzle",
main_replay_puzzle
},
{
"Replay of 2P vs",
main_replay_vs
},
{
"Configure input",
main_config_input
},
{
"Set name",
main_set_name
},
{
"Options",
main_options
},
{
"Fullscreen (LAlt+Enter)",
fullscreen
},
{
"Quit",os.exit
}
}
local k = keyboard[1]
-- displays a indicator when you are about to select a menu option
while true do
local to_print = ""
local arrow = ""
for i=1, #menu_options do
if active_idx == i then
arrow = arrow .. ">"
else
arrow = arrow .. "\n"
end
to_print = to_print .. " " .. menu_options[i][1] .. "\n"
end
gprint(arrow, X_STRING_CENTER, Y_STRING_CENTER)
gprint(to_print, X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
assert(k, "No key was passed")
if MENU_KEY_UP(k) then
active_idx = wrap(1, active_idx - 1, #menu_options)
elseif MENU_KEY_DOWN(k) then
active_idx = wrap(1, active_idx + 1, #menu_options)
elseif MENU_KEY_ENTER(k) then
return menu_options[active_idx][2], menu_options[active_idx][3]
elseif MENU_KEY_ESCAPE(k) then
if active_idx == #menu_options then
return menu_options[active_idx][2], menu_options[active_idx][3]
else
active_idx = #menu_options
end
else
-- Nothing to do.
end
end
end
end
--- Fuction to select the speed and level of difficlties
-- @param next_fuction Fuction that gonna be executed next
-- @param ... Other fuctions
function select_speed_and_level_menu(next_func, ...)
assert(next_func, "Select speed and level menu param is nil")
local difficulties = {
"Easy",
"Normal",
"Hard"
}
local menu_options = {
{"Speed"},
{"Difficulty"},
{
"Go!",
next_func
},
{
"Back",
main_select_mode
}
}
local speed, difficulty, active_idx = 1, 1, 1
local k = keyboard[1]
while true do
local to_print, to_print2, arrow = "", "", ""
for i=1, #menu_options do
if active_idx == i then
arrow = arrow .. ">"
else
arrow = arrow .. "\n"
end
to_print = to_print .. " " .. menu_options[i][1] .. "\n"
end
to_print2 = " " .. speed .. "\n "
.. difficulties[difficulty]
gprint(arrow, X_STRING_CENTER, Y_STRING_CENTER)
gprint(to_print, X_STRING_CENTER, Y_STRING_CENTER)
gprint(to_print2, X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
assert(speed ~= 0, "Speed cannot be zero.")
assert(difficulty ~= 0, "Difficulty cannot be zero.")
if MENU_KEY_UP(k) then
active_idx = wrap(1, active_idx - 1, #menu_options)
elseif MENU_KEY_DOWN(k) then
active_idx = wrap(1, active_idx + 1, #menu_options)
elseif MENU_KEY_RIGHT(k) then
if active_idx == 1 then
speed = bound(1, speed + 1, 99)
elseif active_idx == 2 then
difficulty = bound(1, difficulty + 1, 3)
else
-- Nothing to do.
end
elseif MENU_KEY_LEFT(k) then
if active_idx == 1 then
speed = bound(1,speed-1,99)
elseif active_idx == 2 then
difficulty = bound(1, difficulty - 1, 3)
else
-- Nothing to do.
end
elseif MENU_KEY_ENTER(k) then
if active_idx == 3 then
return menu_options[active_idx][2], {speed, difficulty, ...}
elseif active_idx == 4 then
return menu_options[active_idx][2], menu_options[active_idx][3]
else
active_idx = wrap(1, active_idx + 1, #menu_options)
end
elseif MENU_KEY_ESCAPE(k) then
if active_idx == #menu_options then
return menu_options[active_idx][2], menu_options[active_idx][3]
else
active_idx = #menu_options
end
else
-- Nothing to do.
end
end
end
--- Runs Endless mode
-- @return transition function, table containing info about the end of the game
function main_endless(...)
consuming_timesteps = true
replay.endless = {}
local replay = replay.endless
replay.pan_buf = ""
replay.in_buf = ""
replay.gpan_buf = ""
replay.mode = "endless"
P1 = Stack(1, "endless", ...)
replay.speed = P1.speed
replay.difficulty = P1.difficulty
make_local_panels(P1, "000000")
make_local_gpanels(P1, "000000")
while true do
P1:render()
coroutine_wait()
if P1.game_over then
-- @todo proper game over.
write_replay_file()
return main_dumb_transition, {main_select_mode, "You scored " .. P1.score}
else
-- Nothing to do.
end
run_function_as_60hz(function() P1:local_run() end)
--groundhogday mode
--[[if P1.CLOCK == 1001 then
local prev_states = P1.prev_states
P1 = prev_states[600]
P1.prev_states = prev_states
end--]]
end
end
--- Runs Time Attack mode
-- @param ... players fuctions
-- @return next load screen function
function main_time_attack(...)
consuming_timesteps = true
P1 = Stack(1, "time", ...)
make_local_panels(P1, "000000")
local CLOCK_CONSTANT = 120 * 60
while true do
P1:render()
coroutine_wait()
if P1.game_over or P1.CLOCK == CLOCK_CONSTANT then
-- @todo proper game over.
return main_dumb_transition, {main_select_mode, "You scored " .. P1.score}
else
-- Nothing to do.
end
run_function_as_60hz(function()
if (not P1.game_over) and P1.CLOCK < CLOCK_CONSTANT then
P1:local_run()
else
-- Nothing to do.
end
end)
end
end
--- Changes select mode
-- @return fuction that runs selections to main character
function main_net_vs_room()
character_select_mode = "2p_net_vs"
return main_character_select()
end
--- This fuction does a lot of things, it sees if it can establish connection
-- if the connection is beeing maintained
-- the menu chooses the character to each player
-- the menu chooses the map
-- and more
-- @tparam nil
-- @treturn nil
function main_character_select()
love.audio.stop()
local map = {}
if character_select_mode == "2p_net_vs" then
local opponent_connected = false
local retries, retry_limit = 0, 500
while not global_initialize_room_msg and retries < retry_limit do
for _, message in ipairs(this_frame_messages) do
if message.create_room or message.character_select or message.spectate_request_granted then
global_initialize_room_msg = message
else
-- Nothing to do.
end
end
gprint("Waiting for room initialization...", X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
do_messages()
retries = retries + 1
end
if room_number_last_spectated and retries >= retry_limit and currently_spectating then
request_spectate(room_number_last_spectated)
retries = 0
-- runs if the player has lost connection
while not global_initialize_room_msg and retries < retry_limit do
for _, message in ipairs(this_frame_messages) do
if message.create_room or message.character_select or message.spectate_request_granted then
global_initialize_room_msg = message
end
end
gprint("Lost connection. Trying to rejoin...", X_STRING_CENTER, Y_STRING_CENTER)
coroutine_wait()
do_messages()
retries = retries + 1
end
else
-- Nothing to do.
end
-- runs if connection has failed
if not global_initialize_room_msg then
return main_dumb_transition, {main_select_mode, "Failed to connect.\n\nReturning to main menu", 60, 300}
else
-- Nothing to do.
end
message = global_initialize_room_msg
global_initialize_room_msg = nil
if message.ratings then
global_current_room_ratings = message.ratings
end
global_my_state = message.a_menu_state
global_op_state = message.b_menu_state
if message.your_player_number then
my_player_number = message.your_player_number
elseif currently_spectating then
my_player_number = 1
-- Thats right its checking if is nil and different of zero
elseif my_player_number and my_player_number ~= 0 then
print("We assumed our player number is still " .. my_player_number)
else
error("We never heard from the server as to what player number we are")
print("Error: The server never told us our player number. Assuming it is 1")
my_player_number = 1
end
if message.op_player_number then
op_player_number = message.op_player_number or op_player_number
elseif currently_spectating then
op_player_number = 2
-- Thats right its checking if is nil and different of zero
elseif op_player_number and op_player_number ~= 0 then
print("We assumed op player number is still " .. op_player_number)
else
error("We never heard from the server as to what player number we are")
print("Error: The server never told us our player number. Assuming it is 2")
op_player_number = 2
end
if message.win_counts then
update_win_counts(message.win_counts)
else
-- Nothing to do.
end
if message.replay_of_match_so_far then
replay_of_match_so_far = message.replay_of_match_so_far
else
-- Nothing to do.
end
if message.ranked then
matchType = "Ranked"
match_type_message = ""
else
matchType = "Casual"
end
if currently_spectating then
P1 = {panel_buffer="", gpanel_buffer=""}
print("we reset P1 buffers at start of main_character_select()")
else
-- Nothing to do.
end
P2 = {
panel_buffer="",
gpanel_buffer=""
}
print("we reset P2 buffers at start of main_character_select()")
print("serverSupportsRanking: "..tostring(serverSupportsRanking))
local cursor,op_cursor, coordinate_x, coordinate_y = nil, nil, nil
-- If serverSupportsRanking is true then update map, else update update map
if serverSupportsRanking then
map = MAP_RANKING
else
map = MAP_DEFAULT
end
end
if character_select_mode == "1p_vs_yourself" then
map = MAP_1P_VS_YOURSELF
else
-- Nothing to do.
end
local op_state = global_op_state or {character="lip", level=5, cursor="level", ready=false}
global_op_state = nil
cursor, op_cursor, coordinate_x, coordinate_y = {1, 1}, {1, 1}, 5, 7
local k = keyboard[1]
local up, down, left, right = {-1, 0}, {1, 0}, {0, -1}, {0, 1}
my_state = global_my_state or
{character=CONFIG_TABLE.character, level=CONFIG_TABLE.level, cursor="level", ready=false}
global_my_state = nil
my_win_count = my_win_count or 0
local prev_state = shallowcpy(my_state)
op_win_count = op_win_count or 0
if character_select_mode == "2p_net_vs" then
global_current_room_ratings = global_current_room_ratings or
{{new=0, old=0, difference=0}, {new=0, old=0, difference=0}}
-- Win ratio of the current player
my_expected_win_ratio = (global_current_room_ratings[op_player_number].new
-global_current_room_ratings[my_player_number].new)
/rating_spread_modifier
my_expected_win_ratio = 100 * round(1/1 + 10^my_expected_win_ratio, 2)
-- Win ratio of the oponent player
op_expected_win_ratio = (global_current_room_ratings[my_player_number].new
-global_current_room_ratings[op_player_number].new)
/rating_spread_modifier
op_expected_win_ratio = 100 * round(1/1 + 10^op_expected_win_ratio, 2)
else
-- Nothing to do.
end
if character_select_mode == "2p_net_vs" then
matchType = matchType or "Casual"
if matchType == "" then
matchType = "Casual"
else
-- Nothing to do.
end
else
-- Nothing to do.
end
match_type_message = match_type_message or ""
local selected = false
local active_str = "level"
local selectable = {level=true, ready=true}
local function move_cursor(direction)
assert(map, "move_cursor:map is nil")
assert(cursor, "move_cursor:cursor is nil")
assert(direction, "Move cursor param is nil")
local dx, dy = unpack(direction)
local can_x, can_y = wrap(1, cursor[1]+dx, coordinate_x), wrap(1, cursor[2]+dy, coordinate_y)
while can_x ~= cursor[1] or can_y ~= cursor[2] do
if map[can_x][can_y] and map[can_x][can_y] ~= map[cursor[1]][cursor[2]] then
break
else
-- Nothing to do.
end
can_x, can_y = wrap(1, can_x+dx, coordinate_x), wrap(1, can_y+dy, coordinate_y)
end
cursor[1], cursor[2] = can_x,can_y
end
--- Leaves the room
-- @tparam nil
-- @treturn nil
local function do_leave()
my_win_count = 0
op_win_count = 0
write_char_sel_settings_to_file()
json_send({leave_room=true})
end
local name_to_xy = {}
print("character_select_mode = " .. (character_select_mode or "nil"))
print("map[1][1] = "..(map[1][1] or "nil"))
for i=1, coordinate_x do
for j=1, coordinate_y do
if map[i][j] then
name_to_xy[map[i][j]] = {i,j}
else
-- Nothing to do.
end
end
end
--- Draws buttons and other strings on the screen
-- @param x coordinate x where render
-- @param y coordinate x where render
-- @param w screen width
-- @param h screen hight
-- @param str string
-- @return next screen
local function draw_button(x, y, w, h, str)
assert(x, "Draw buttos param x is nil")
assert(y, "Draw buttos param y is nil")
assert(w, "Draw buttos param w is nil")
assert(h, "Draw buttos param h is nil")
assert(str, "Draw buttos param str is nil")
local menu_width = coordinate_y * 100
local menu_height = coordinate_x * 80
local spacing = 8
local x_padding = math.floor((819-menu_width) / 2)
local y_padding = math.floor((612-menu_height) / 2)
set_color(unpack(colors.white))
render_x = x_padding + (y - 1) * 100 + spacing
render_y = y_padding + (x - 1) * 100 + spacing
button_width = w * 100 - 2 * spacing
button_height = h*100 - 2 * spacing
grectangle("line", render_x, render_y, button_width, button_height)
-- If character icon is a instance then get the dimensions and draw in screen
local icon = IMG_character_icons[character_display_names_to_original_names[str]]
if icon then
local orig_w, orig_h = icon:getDimensions()
menu_draw(IMG_character_icons[character_display_names_to_original_names[str]],
render_x, render_y, 0, button_width/orig_w, button_height/orig_h )
else
-- Nothing to do.
end
local y_add, x_add = 10, 30
local pstr = str
-- Formats pstr
if str == "level" then
if selected and active_str == "level" then
pstr = pstr .. "\n" .. my_name .. "'s level: < " .. my_state.level .. " >"
else
pstr = pstr .. "\n" .. my_name .. "'s level: " .. my_state.level
end
if character_select_mode == "2p_net_vs" then
pstr = pstr .. "\n" .. op_name .. "'s level: " .. op_state.level
else
-- Nothing to do.
end
y_add, x_add = 9, 180
else
-- Nothing to do.
end
-- Formats pstr
if str == "match type desired" then
local my_type_selection, op_type_selection = "[casual] ranked", "[casual] ranked"
if my_state.ranked then
my_type_selection = " casual [ranked]"
else
-- Nothing to do.
end
if op_state.ranked then
op_type_selection = " casual [ranked]"
else
-- Nothing to do.
end
pstr = pstr .. "\n" .. my_name .. ": " .. my_type_selection .. "\n" ..
op_name .. ": " .. op_type_selection
y_add, x_add = 9, 180
else
-- Nothing to do.
end
if my_state.cursor == str then
pstr = pstr.."\n" .. my_name
else
-- Nothing to do.
end
if op_state and op_name and op_state.cursor == str then
pstr = pstr .. "\n" .. op_name
else
-- Nothing to do.
end
local cur_blink_frequency = 4
local cur_pos_change_frequency = 8
local player_num
local draw_cur_this_frame = false
local cursor_frame = 1
-- Draw the player 2
if (character_select_mode == "2p_net_vs" or character_select_mode == "2p_local_vs")
and op_state and op_state.cursor and
(op_state.cursor == str or op_state.cursor == character_display_names_to_original_names[str]) then
player_num = 2
if op_state.ready then
if (math.floor(menu_clock/cur_blink_frequency)+player_num)% 2 + 1 == player_num then
draw_cur_this_frame = true
cursor_frame = 1
else
draw_cur_this_frame = false
end
else
draw_cur_this_frame = true
cursor_frame = (math.floor(menu_clock/cur_pos_change_frequency)+player_num) % 2 + 1
cur_img = IMG_char_sel_cursors[player_num][cursor_frame]
end
if draw_cur_this_frame then
cur_img = IMG_char_sel_cursors[player_num][cursor_frame]
cur_img_left = IMG_char_sel_cursor_halves.left[player_num][cursor_frame]
cur_img_right = IMG_char_sel_cursor_halves.right[player_num][cursor_frame]
local cur_img_w, cur_img_h = cur_img:getDimensions()
local cursor_scale = (button_height + (spacing * 2)) / cur_img_h
menu_drawq(cur_img, cur_img_left, render_x - spacing, render_y-spacing, 0, cursor_scale , cursor_scale)
menu_drawq(
cur_img,
cur_img_right,
render_x + button_width + spacing - cur_img_w * cursor_scale / 2,
render_y - spacing,
0,
cursor_scale,
cursor_scale
)
end
else
-- Nothing to do.
end
-- Draw player 1
if my_state and my_state.cursor and
(my_state.cursor == str or my_state.cursor == character_display_names_to_original_names[str]) then
player_num = 1
if my_state.ready then
if (math.floor(menu_clock / cur_blink_frequency) + player_num) % 2 + 1 == player_num then
draw_cur_this_frame = true
cursor_frame = 1
else
draw_cur_this_frame = false
end
else
draw_cur_this_frame = true
cursor_frame = (math.floor(menu_clock / cur_pos_change_frequency) + player_num) % 2 + 1
cur_img = IMG_char_sel_cursors[player_num][cursor_frame]
end
-- Draw image in the screen
if draw_cur_this_frame then
cur_img = IMG_char_sel_cursors[player_num][cursor_frame]
cur_img_left = IMG_char_sel_cursor_halves.left[player_num][cursor_frame]
cur_img_right = IMG_char_sel_cursor_halves.right[player_num][cursor_frame]
local cur_img_w, cur_img_h = cur_img:getDimensions()
local cursor_scale = (button_height + (spacing * 2)) / cur_img_h
menu_drawq(
cur_img,
cur_img_left,
render_x-spacing,
render_y-spacing,
0,
cursor_scale,
cursor_scale
)
menu_drawq(
cur_img,
cur_img_right,
render_x + button_width + spacing - cur_img_w * cursor_scale / 2,
render_y - spacing,
0,
cursor_scale,
cursor_scale
)
end
else
-- Nothing to do.
end
gprint(pstr, render_x + 6, render_y + y_add)
end
print("got to LOC before net_vs_room character select loop")
menu_clock = 0
while true do
menu_clock = menu_clock + 1
if character_select_mode == "2p_net_vs" then
for _, message in ipairs(this_frame_messages) do
if message.win_counts then
update_win_counts(message.win_counts)
end
if message.menu_state then
if currently_spectating then
if message.player_number == 2 then
op_state = message.menu_state
elseif message.player_number == 1 then
my_state = message.menu_state
else
-- Nothing to do.
end
else
op_state = message.menu_state
end
else
-- Nothing to do.
end
assert(message, "message is null")
if message.ranked_match_approved then
matchType = "Ranked"
match_type_message = ""
elseif message.ranked_match_denied then
matchType = "Casual"
match_type_message = "Not ranked. "
if message.reasons then
match_type_message = match_type_message .. (message.reasons[1] or "Reason unknown")
else
-- Nothing to do.
end
end
if message.leave_room then
my_win_count = 0
op_win_count = 0
write_char_sel_settings_to_file()
return main_net_vs_lobby
else
-- Nothing to do.
end
if message.match_start or replay_of_match_so_far then
local fake_P1 = P1
print("currently_spectating: " .. tostring(currently_spectating))
local fake_P2 = P2
P1 = Stack(1, "vs", message.player_settings.level,
message.player_settings.character, message.player_settings.player_number)
P2 = Stack(2, "vs", message.opponent_settings.level,
message.opponent_settings.character, message.opponent_settings.player_number)
if currently_spectating then
P1.panel_buffer = fake_P1.panel_buffer
P1.gpanel_buffer = fake_P1.gpanel_buffer
else
-- Nothing to do.
end
P2.panel_buffer = fake_P2.panel_buffer
P2.gpanel_buffer = fake_P2.gpanel_buffer
P1.garbage_target = P2
P2.garbage_target = P1
P2.pos_x = 172
P2.score_x = 410
replay.vs = {
P = "",
O = "",
I = "",
Q = "",
R = "",
in_buf = "",
P1_level = P1.level,
P2_level = P2.level,
P1_name = my_name,
P2_name = op_name,
P1_char = P1.character,
P2_char = P2.character,
ranked = message.ranked
}
if currently_spectating and replay_of_match_so_far then --we joined a match in progress
replay.vs = replay_of_match_so_far.vs
P1.input_buffer = replay_of_match_so_far.vs.in_buf
P1.panel_buffer = replay_of_match_so_far.vs.P
P1.gpanel_buffer = replay_of_match_so_far.vs.Q
P2.input_buffer = replay_of_match_so_far.vs.I
P2.panel_buffer = replay_of_match_so_far.vs.O
P2.gpanel_buffer = replay_of_match_so_far.vs.R
if replay.vs.ranked then
matchType = "Ranked"
match_type_message = ""
else
matchType = "Casual"
end
replay_of_match_so_far = nil
P1.play_to_end = true --this makes foreign_run run until caught up
P2.play_to_end = true
else
-- Nothing to do.
end
if not currently_spectating then
ask_for_gpanels("000000")
ask_for_panels("000000")
else
-- Nothing to do.
end
to_print = "Game is starting!\n".."Level: "..P1.level.."\nOpponent's level: "..P2.level
if P1.play_to_end or P2.play_to_end then
to_print = "Joined a match in progress.\nCatching up..."
else
-- Nothing to do.
end
for i=1, 30 do
gprint(to_print,X_STRING_CENTER, Y_STRING_CENTER)
do_messages()
coroutine_wait()
end
local game_start_timeout = 0
-- start's the game for 2p mode
while P1.panel_buffer == "" or P2.panel_buffer == ""
or P1.gpanel_buffer == "" or P2.gpanel_buffer == "" do
--testing getting stuck here at "Game is starting"
game_start_timeout = game_start_timeout + 1
print("game_start_timeout = " .. game_start_timeout)
print("P1.panel_buffer = " .. P1.panel_buffer)
print("P2.panel_buffer = " .. P2.panel_buffer)
print("P1.gpanel_buffer = " .. P1.gpanel_buffer)
print("P2.gpanel_buffer = " .. P2.gpanel_buffer)
gprint(to_print, X_STRING_CENTER, Y_STRING_CENTER)
do_messages()
coroutine_wait()
local LIMITTIMEOUT = 500
if game_start_timeout > LIMITTIMEOUT then
return main_dumb_transition, {main_select_mode,
"game-is-starting bug diagnostic version 2\n\ngame start timed out."
.. "\n Please screenshot this and\npost it in #panel-attack-bugs-features"
.."\n".."message.match_start = "..(tostring(message.match_start) or "nil")
.."\n".."replay_of_match_so_far = "..(tostring(replay_of_match_so_far) or "nil")
.."\n".."P1.panel_buffer = "..P1.panel_buffer
.."\n".."P2.panel_buffer = "..P2.panel_buffer
.."\n".."P1.gpanel_buffer = "..P1.gpanel_buffer
.."\n".."P2.gpanel_buffer = "..P2.gpanel_buffer,
600}
else
-- Nothing to do.
end
end
P1:starting_state()
P2:starting_state()
return main_net_vs
else
-- Nothing to do.
end
end
else
-- Nothing to do.
end
-- responsible for displaying the strings on the display
if serverSupportsRanking then
draw_button(1, 1, 4, 1, "match type desired")
draw_button(1, 5, 2, 1, "level")
else
draw_button(1, 1, 6, 1, "level")
end
draw_button(1, 7, 1, 1, "ready")
for i=2, coordinate_x do
for j=1, coordinate_y do
draw_button(i, j, 1, 1, character_display_names[map[i][j]] or map[i][j])
end
end
-- String to format the ranting of the player and oponnent
local myRatingDifference = ""
local opRatingDifference = ""
-- Format strings
if serverSupportsRanking then
if global_current_room_ratings[my_player_number].difference >= 0 then
myRatingDifference = "(+" .. global_current_room_ratings[my_player_number].difference .. ") "
else
myRatingDifference = "(" .. global_current_room_ratings[my_player_number].difference .. ") "
end