-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lua
1306 lines (1057 loc) · 30.2 KB
/
menu.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
-- luacheck:globals term colours textutils keys blittle shell sleep fs http peripheral
-- Zombease - a top-down zombie survival shooter by viluon
-- Environment set up
if not term.isColour or not term.isColour() then
error( "Zombease requires an advanced computer!", 0 )
end
local root = "/" .. fs.getDir( shell.getRunningProgram() ) .. "/"
if not fs.exists( root .. "blittle" ) then
shell.run( "pastebin get ujchRSnU " .. root .. "blittle" )
end
os.loadAPI( root .. "blittle" )
local blittle = blittle
if not require then shell.run( root .. "desktox/init.lua" ) end
_G.require = require
local args = { ... }
-- Dependencies
local base64 = require "utils.base64"
local buffer = require "desktox.buffer"
local round = require( "desktox.utils" ).round
-- Constants
--- How many seconds between wind howls
local WIND_HOWL_PERIOD = 20
--- How long should one howl last
local WIND_HOWL_DURATION = 5
--- How long should the wind be speeding up/slowing down
local WIND_HOWL_TRANSITION = 2
local WIND_MAX_SPEED = -35
local WIND_MIN_SPEED = -8
local SNOWFLAKE_SPAWN_RATE = 0.05
local SETTINGS_SAVE_PERIOD = 5
local MENU_ANIM_DURATION = 0.5
local START_MENU_POS_Y = 5
local REQUIRED_MIN_SCREEN_WIDTH = 30
local REQUIRED_MIN_SCREEN_HEIGHT = 15
-- Function declarations
local redraw, shade, update, ease_in_quad,
ease_out_quad, change_menu, parse_model,
draw_model, save_settings, align_number,
get_paste, populate_resolution_menu,
move_player
local empty_func = function() end
local version = "0.2.2-beta"
-- Localisation
local colours = colours
local string = string
local shell = shell
local table = table
local term = term
local math = math
local remove = table.remove
local insert = table.insert
local random = math.random
local yield = coroutine.yield
local queue = os.queueEvent
local clock = os.clock
local sleep = sleep
local floor = math.floor
local gsub = string.gsub
local sub = string.sub
local min = math.min
local max = math.max
local sin = math.sin
-- Data
local now
local running = true
local launch = false
local perform_update = false
--- Held keys and buttons
local held = { mouse = {} }
if not fs.exists( root .. "tmp/logo_dec" ) then
-- Decode the logo
local logo_enc = io.open( root .. "assets/little_images/logo_mix.b64", "r" )
local logo_data = logo_enc:read( "*a" )
logo_enc:close()
local logo_dec = io.open( root .. "tmp/logo_dec", "wb" )
local data = base64.decode( logo_data )
local x, y = term.getCursorPos()
for i = 1, #data do
logo_dec:write( data:sub( i, i ):byte() )
term.setCursorPos( x, y )
term.write( round( 100 * i / #data ) .. "%" )
if i % 16 == 0 then
sleep( 0 )
end
end
logo_dec:close()
end
local logo = blittle.load( root .. "tmp/logo_dec" )
--- Terminal set up
local main_win = term.current()
local w, h = main_win.getSize()
if w < REQUIRED_MIN_SCREEN_WIDTH or h < REQUIRED_MIN_SCREEN_HEIGHT then
print(
"We're sorry, Zombease requires a resolution of at least " .. REQUIRED_MIN_SCREEN_WIDTH .. "x" .. REQUIRED_MIN_SCREEN_HEIGHT
)
return
end
local main_buf = buffer.new( 0, 0, w, h, nil, colours.black )
local overlay_buf = buffer.new( 0, 0, w, h, main_buf, -1, -2, "\0" )
local armoury_buf = buffer.new( 0, logo.height, w, h - logo.height, main_buf )
local wave_win = main_buf:get_window_interface( main_win )
wave_win.setVisible( true )
local stuff = ""
local wind_howling = false
local last_wind_howl_start = clock()
local wind_speed = WIND_MIN_SPEED
local particles = {}
local symbols = {
"\127", "*",
}
-- The terminal the game should use
local terminal = main_win
local terminal_scale = 1
local settings = {
show_version = true;
snowflakes = 0;
limit_FPS = true;
difficulty = 2;
report_performance = true;
keybindings = {
up = keys.w;
down = keys.s;
left = keys.a;
right = keys.d;
}
}
local settings_file = io.open( root .. "saves/settings.tbl", "r" )
if settings_file then
local contents = settings_file:read( "*a" )
-- Import from save
for k, v in pairs( textutils.unserialise( contents ) or settings ) do
settings[ k ] = v
end
settings_file:close()
end
local player = {
x = round( ( 9 / 12 ) * w );
y = round( ( 8 / 12 ) * h );
type = "player";
text = "^";
bg = colours.brown;
fg = colours.black;
health = 100;
last_moved = -1;
movement_speed = 0.1;
reload_time_multiplier = 1;
-- New save inventory (what you begin with)
inventory = {
ammunition = {
generic = 4;
};
weapons = {
--weapons.fists,
};
attachments = {
};
};
}
local menu
menu = {
main = {
[ 1 ] = {
label = "Play";
fn = function( _ )
change_menu( "play" )
end;
};
[ 2 ] = {
label = "Armoury";
fn = function( _ )
change_menu( "armoury" )
end;
};
[ 3 ] = {
label = "Settings";
fn = function( _ )
change_menu( "settings" )
end;
};
[ 4 ] = {};
[ 5 ] = {
label = "Quit";
fn = function( _ )
running = false
end;
};
};
play = {
[ 1 ] = {
label = "Endless";
fn = function( _ )
launch = true
running = false
end;
};
[ 2 ] = {};
[ 3 ] = {
label = "Back";
fn = function( _ )
change_menu( "main" )
end;
};
};
armoury = {};
settings = {
[ 1 ] = {
label = "Difficulty";
fn = function( _ )
change_menu( "settings_difficulty" )
end;
};
[ 2 ] = {
label = "Display";
fn = function( _ )
change_menu( "settings_display" )
end;
};
[ 3 ] = {
label = settings.report_performance and "Tech stats: on" or "Tech stats: off";
fn = function( self )
settings.report_performance = not settings.report_performance
self.label = settings.report_performance and "Tech stats: on" or "Tech stats: off";
save_settings()
end;
};
[ 4 ] = {
label = settings.show_version and "Version: shown" or "Version: hidden";
fn = function( self )
settings.show_version = not settings.show_version
self.label = settings.show_version and "Version: shown" or "Version: hidden"
save_settings()
end;
};
[ 5 ] = {
label = "Debug menu";
fn = function( _ )
change_menu( "debug" )
end;
};
[ 6 ] = {};
[ 7 ] = {
label = "Back";
fn = function( _ )
change_menu( "main" )
end;
};
};
settings_difficulty = {
[ 1 ] = {
label = ( settings.difficulty == 1 and ">" or " " ) .. " Easy";
unselected = " Easy";
fn = function( self )
settings.difficulty = 1
for i = 1, #menu.settings_difficulty - 2 do
menu.settings_difficulty[ i ].label = menu.settings_difficulty[ i ].unselected
end
self.label = "> Easy"
end;
};
[ 2 ] = {
label = ( settings.difficulty == 2 and ">" or " " ) .. " Normal";
unselected = " Normal";
fn = function( self )
settings.difficulty = 2
for i = 1, #menu.settings_difficulty - 2 do
menu.settings_difficulty[ i ].label = menu.settings_difficulty[ i ].unselected
end
self.label = "> Normal"
end;
};
[ 3 ] = {
label = ( settings.difficulty == 3 and ">" or " " ) .. " Hard";
unselected = " Hard";
fn = function( self )
settings.difficulty = 3
for i = 1, #menu.settings_difficulty - 2 do
menu.settings_difficulty[ i ].label = menu.settings_difficulty[ i ].unselected
end
self.label = "> Hard"
end;
};
[ 4 ] = {};
[ 5 ] = {
label = "Back";
fn = function( _ )
change_menu( "settings" )
end;
};
};
settings_display = {
[ 1 ] = {
label = "Resolution";
fn = function( _ )
change_menu( "resolution" )
end;
};
[ 2 ] = {
label = settings.limit_FPS and "FPS limit: on" or "FPS limit: off";
fn = function( self )
settings.limit_FPS = not settings.limit_FPS
self.label = settings.limit_FPS and "FPS limit: on" or "FPS limit: off";
save_settings()
end;
};
[ 3 ] = {};
[ 4 ] = {
label = "Back";
fn = function( _ )
change_menu( "settings" )
end;
};
};
resolution = {
[ 1 ] = {};
[ 2 ] = {
label = "Back";
fn = function( _ )
change_menu( "settings_display" )
end;
};
};
debug = {
{ label = "foo 01"; fun = empty_func; };
{ label = "foo 02"; fun = empty_func; };
{ label = "foo 03"; fun = empty_func; };
{ label = "foo 04"; fun = empty_func; };
{ label = "foo 05"; fun = empty_func; };
{ label = "foo 06"; fun = empty_func; };
{ label = "foo 07"; fun = empty_func; };
{ label = "foo 08"; fun = empty_func; };
{ label = "foo 09"; fun = empty_func; };
{ label = "foo 10"; fun = empty_func; };
{ label = "foo 11"; fun = empty_func; };
{ label = "foo 12"; fun = empty_func; };
{ label = "foo 13"; fun = empty_func; };
{ label = "foo 14"; fun = empty_func; };
{ label = "foo 15"; fun = empty_func; };
{ label = "foo 16"; fun = empty_func; };
{ label = "foo 17"; fun = empty_func; };
{ label = "foo 18"; fun = empty_func; };
{ label = "foo 19"; fun = empty_func; };
{ label = "foo 20"; fun = empty_func; };
{ label = "foo 21"; fun = empty_func; };
{ label = "foo 22"; fun = empty_func; };
{ label = "foo 23"; fun = empty_func; };
{ label = "foo 24"; fun = empty_func; };
{};
{
label = "Back";
fn = function( _ )
change_menu( "settings" )
end;
};
};
}
local previous_menu_width = 0
local menu_width = 0
local menu_pos_x = 7
local menu_pos_y = START_MENU_POS_Y
local model_offset_x = 0
local model_offset_y = 0
local selected_weapon = 1
local armoury_position = logo.height
local armoury_back_button = {
label = "< Back";
}
local menu_state = "main"
local new_state = menu_state
local menu_changed = -1
local menu_label_start = 1
local menu_label_end = math.huge
local inventory
local models = {}
local weapons = {}
local weapon_kinds = {}
local bullet_kinds = {}
local attachment_kinds = {}
local last_spawn = -1
local fade_level = 2
local fade_shader = {
[ colours.grey ] = colours.black;
[ colours.lightGrey ] = colours.grey;
[ colours.white ] = colours.lightGrey;
[ colours.yellow ] = colours.white;
[ colours.green ] = colours.grey;
[ colours.red ] = colours.pink;
[ colours.pink ] = colours.lightGrey;
}
local shader = fade_shader
-- Adapted from
-- Tweener's easing functions (Penner's Easing Equations)
-- and http://code.google.com/p/tweener/ (jstweener javascript version)
function ease_in_quad( time, begin, change, duration )
if time > duration then
return begin + change
end
time = time / duration
return -change * time * ( time - 2 ) + begin
end
function ease_out_quad( time, begin, change, duration )
if time > duration then
return begin + change
end
time = time / duration
return change * time ^ 1.5 + begin
end
--- Get the contents of a Pastebin paste.
-- @param code description
-- @return The paste contents or nil plus an error message
function get_paste( code )
local response, err = http.get(
"http://pastebin.com/raw/" .. textutils.urlEncode( code )
)
if response then
local contents = response.readAll()
response.close()
return contents
end
return nil, err
end
--- Load a model from its textual description.
-- @param text The textual definition of the model
-- @param name (Optional) The name of the model, useful for debugging
-- @return The loaded model
function parse_model( text, name )
local fn, err = loadstring( text, name or "model" )
if not fn then
error( "Failed to parse model " .. tostring( name ) .. ": " .. err, 2 )
end
local ok, model = pcall( fn )
if not ok then
error( "Failed to load model " .. tostring( name ) .. ": " .. model, 2 )
end
-- Process "unknown" colours (and also white background)
for i, str in ipairs( model.background ) do
model.background[ i ] = gsub( str, " ", "g" ):gsub( "0", "g" )
end
for i, str in ipairs( model.foreground ) do
model.foreground[ i ] = gsub( str, " ", "h" )
end
---[[
-- For proper transparency, we need to check char by char
for i, str in ipairs( model.characters ) do
local res = ""
for ii = 1, #str do
local char = sub( str, ii, ii )
if char:find( "%s" ) and sub( model.background[ i ], ii, ii ) == "g" then
res = res .. "\0"
else
res = res .. char
end
end
model.characters[ i ] = res
end
--]]
model.width = #model.background[ 1 ]
model.height = #model.background
return model
end
--- Align a nuber on a line to a specified column
-- @param str description
-- @param column description
-- @param number description
-- @return The string for the resultant row
function align_number( str, column, number )
return str .. string.rep( " ", column - #str ) .. number
end
--- Draw a model to the screen.
-- @param model The model to draw duh
-- @return nil
function draw_model( model, x, y, buf )
y = y - 1
local characters = model.characters
local background = model.background
local foreground = model.foreground
-- Go through all the lines, blitting the model's texture
for i = 1, model.height do
-- A -1 for i is included in the y definition above
buf:blit( x, y + i, characters[ i ], background[ i ], foreground[ i ] )
end
end
--- Save the current settings.
-- @return nil
function save_settings()
local file = io.open( root .. "saves/settings.tbl", "w" )
file:write( textutils.serialise( settings ) )
file:close()
end
--- Change the menu state.
-- @param state The state to be applied
-- @return nil
function change_menu( state )
previous_menu_width = menu_width
menu_changed = now
new_state = state
local longest = -1
for _, menu_item in ipairs( menu[ state ] ) do
if menu_item.label then
if longest < #menu_item.label then
longest = #menu_item.label
end
end
end
menu_width = longest + 1
end
--- Generate options for the resolution submenu
-- @return nil
function populate_resolution_menu()
local monitors = {}
local native = term.native()
peripheral.find( "monitor", function( name, object )
if object.isColour and object.isColour() then
monitors[ #monitors + 1 ] = {
name = name;
handle = object;
}
monitors[ name ] = object
end
end )
monitors[ main_win ] = main_win
monitors[ native ] = native
--- The function called on a menu item select
-- @return nil
local function mon_func( self )
for i = 1, #menu.resolution - 2 do
local item = menu.resolution[ i ]
item.label = " " .. item.label:sub( 2, -1 )
end
terminal = monitors[ self.name ]
terminal_scale = self.scale
self.label = ">" .. self.label:sub( 2, -1 )
end
for i = 1, #monitors do
local mon = monitors[ i ]
for scale = 0.5, 5, 0.5 do
mon.handle.setTextScale( scale )
local width, height = mon.handle.getSize()
if width >= REQUIRED_MIN_SCREEN_WIDTH and height >= REQUIRED_MIN_SCREEN_HEIGHT then
insert( menu.resolution, 1,
{
label = ' Monitor "' .. mon.name .. '" ' .. width .. "x" .. height .. " (native)";
scale = scale;
name = mon.name;
fn = mon_func;
}
)
end
end
end
insert( menu.resolution, 1,
{
label = "> This window " .. w .. "x" .. h;
scale = 1;
name = main_win;
fn = mon_func;
}
)
local width, height = native.getSize()
insert( menu.resolution, 1,
{
label = " This computer " .. width .. "x" .. height .. " (native)";
scale = 1;
name = native;
fn = mon_func;
}
)
end
--- Apply the current shader on a buffer.
-- @see desktox.buffer:map
function shade( _, _, _, pixel )
return {
shader[ pixel[ 1 ] ] or colours.black,
shader[ pixel[ 2 ] ] or colours.black,
pixel[ 3 ],
}
end
--- Redraw the GUI.
-- @return nil
function redraw()
main_buf:clear( colours.white, colours.white )
overlay_buf:clear( -1, -2, "\0" )
-- Draw the menu items
for i, item in pairs( menu[ menu_state ] ) do
if item.label then
local label = item.label
local start = round( menu_label_start )
local str = label:sub( start, min( #label, menu_label_end ) )
main_buf:write( menu_pos_x + start, menu_pos_y + i, str )
end
end
if settings.show_version and menu_state ~= "armoury" and new_state ~= "armoury" then
-- Print the version information
main_buf:write( w - #version, h - 1, version, nil, colours.lightGrey )
end
-- Wish a merry Christmas
local wish = "Happy New Year!"
main_buf:write( logo.width - #wish + 1, logo.height, wish, nil, colours.green )
-- Overlay
--- Particles
for i = 1, #particles do
local particle = particles[ i ]
-- Offset from the sin effect (max: 1.7)
local offset = -1.7 / 2 + sin( now * 6 + particle.sin_offset ) * 1.7
overlay_buf:write(
round( particle.x + offset ),
round( particle.y ),
particle.symbol,
particle.bg or -1,
particle.fg or -2
)
end
overlay_buf:render()
-- Draw the game logo
blittle.draw( logo, 2, 1, wave_win )
-- Draw the player
main_buf:write( player.x, player.y, player.text, player.bg, player.fg )
if menu_state == "armoury" or new_state == "armoury" then
armoury_buf:clear( -1, -2, "\0" )
if inventory then
local infobox_x = round( ( 2 / 3 ) * w ) - 1
local weapon = inventory.weapons[ selected_weapon ]
if infobox_x <= player.x and armoury_position <= player.y then
-- Infobox over the player
main_buf:write( player.x, player.y, player.text, player.fg, player.bg )
end
-- Draw the selected model
local model = models[ weapon.kind.name ]
local armoury_width = floor( ( 1 / 3 ) * w ) - 2
local armoury_height = ( h - logo.height ) / 2
draw_model(
model,
round( max( armoury_width - model.width / 2, 1 ) + model_offset_x ),
round( max( armoury_height - model.height / 2, 1 ) + model_offset_y ),
armoury_buf
)
for index, weap in ipairs( inventory.weapons ) do
if index == selected_weapon then
armoury_buf:write( ( index - 1 ) * 3, h - logo.height - 1, "[ ]", colours.white, colours.black )
end
armoury_buf:write( ( index - 1 ) * 3 + 1, h - logo.height - 1, weap.kind.text, colours.white, colours.grey )
end
-- Print weapon info
local damage = bullet_kinds[ weapon.kind.bullet_kind ].damage
local col = w - infobox_x - 5
armoury_buf
:draw_filled_rectangle_from_points(
infobox_x, 0, w - 1, h - logo.height - 1, -2
)
:write( infobox_x + 1, 1, weapon.kind.display_name or weapon.kind.name, -2, colours.black )
:write( infobox_x + 1, 2, weapon.kind.melee and "Melee weapon" or "Ranged weapon", -2, colours.grey )
:write( infobox_x + 1, 4, align_number( "Damage", col, damage ), -2, colours.grey )
:write( infobox_x + 1, 5, align_number( "Cooldown", col, weapon.kind.cooldown ), -2, colours.grey )
:write( infobox_x + 1, 6, align_number( "DPS", col, damage / weapon.kind.cooldown ), -2, colours.grey )
:write(
infobox_x + 1, 7,
align_number( "Accuracy", col, round( weapon.kind.accuracy * 100 ) .. "%" ),
-2, colours.grey
)
:write(
infobox_x + 1, 8,
align_number( "Knockback", col, floor( bullet_kinds[ weapon.kind.bullet_kind ].knockback ) ),
-2, colours.grey
)
:write(
infobox_x + 2, 9,
"(" .. ( bullet_kinds[ weapon.kind.bullet_kind ].knockback % 1 ) * 100 .. "% chance)",
-2, colours.grey
)
:write(
infobox_x + 1, 10,
align_number( "Clip size", col, weapon.kind.clip_size or "none" ),
-2, colours.grey
)
:write(
infobox_x + 1, 11,
align_number( "Bullets", col, inventory.ammunition[ weapon.kind.bullet_kind ] ),
-2, colours.grey
)
else
local text = "Get some items in-game first!"
armoury_buf:write( w / 2 - #text / 2, 4, text )
end
armoury_buf:write( 0, 0, armoury_back_button.label )
armoury_buf:render( main_buf, 0, round( armoury_position ) )
end
-- Apply the proper fade effect
for _ = 1, fade_level do
main_buf:map( shade )
end
main_buf:write( 0, h - 1, stuff )
main_buf:render_to_window( main_win )
end
--- Update particle effects and whatnot.
-- @param dt Time since last update
-- @return nil
function update( dt )
-- Calculate wind speed
local diff = now - last_wind_howl_start
--stuff = "" .. diff
if diff > WIND_HOWL_PERIOD then
last_wind_howl_start = now
wind_howling = true
diff = 0
end
if wind_howling then
if diff < WIND_HOWL_DURATION then
wind_speed = ease_out_quad( diff, WIND_MIN_SPEED, WIND_MAX_SPEED - WIND_MIN_SPEED, WIND_HOWL_TRANSITION )
elseif diff < WIND_HOWL_DURATION + WIND_HOWL_TRANSITION then
wind_speed = ease_in_quad ( diff - WIND_HOWL_DURATION, WIND_MAX_SPEED, WIND_MIN_SPEED - WIND_MAX_SPEED, WIND_HOWL_TRANSITION )
else
wind_howling = false
end
end
-- Spawn new particles
if now - last_spawn > SNOWFLAKE_SPAWN_RATE then
for _ = 1, 2 do
local position = random( 3 + WIND_MIN_SPEED / 2 - wind_speed / 2, h + w - 1 )
particles[ #particles + 1 ] = {
--x = random( 2 - wind_speed / 2, w - wind_speed + WIND_MIN_SPEED + 2 );
--y = -1;
x = min( position, w );
y = position > w and position % w or -1;
--x_speed = random() > 0.1 and -12 or -8;
y_speed = 18 + ( random() > 0.5 and 10 or 0 );
sin_offset = random() * 6;
symbol = symbols[ random( 1, #symbols ) ];
fg = random() > 0.10 and colours.lightGrey or colours.grey;
bg = colours.white;
}
end
last_spawn = now
end
local to_destroy = {}
-- Update particles
for i = 1, #particles do
local particle = particles[ i ]
particle.x = particle.x + wind_speed * dt
particle.y = particle.y + particle.y_speed * dt
if particle.x < 0 or particle.x >= ( 4 / 3 ) * w or particle.y < -1 or particle.y >= h then
to_destroy[ #to_destroy + 1 ] = particle
settings.snowflakes = settings.snowflakes + 1
end
end
-- Remove particles that went off-screen
for i = 1, #to_destroy do
local p = to_destroy[ i ]
for ii = 1, #particles do
if particles[ ii ] == p then
remove( particles, ii )
break
end
end
end
-- Animate menu changes
if new_state ~= menu_state then
menu_label_start = ease_in_quad( now - menu_changed, 1, previous_menu_width - 1, MENU_ANIM_DURATION )
menu_label_end = math.huge
if menu_label_start == previous_menu_width then
-- This is the actual menu switch!
menu_state = new_state
menu_label_end = 0
menu_pos_y = START_MENU_POS_Y
end
if new_state == "armoury" then
-- Armoury should fly in
armoury_position = ease_in_quad ( now - menu_changed, h, -h + logo.height, MENU_ANIM_DURATION )
elseif menu_state == "armoury" then
-- Armoury should fly out
armoury_position = ease_out_quad( now - menu_changed, logo.height, h - logo.height, MENU_ANIM_DURATION )
end
else
menu_label_start = 1
menu_label_end = ease_in_quad( now - menu_changed - MENU_ANIM_DURATION, 1, menu_width - 1, MENU_ANIM_DURATION )
end
end
--- Move the player character (while respecting collisions).
-- @param x description
-- @param y description
-- @return nil
function move_player( x, y )
player.x = x
player.y = y
end
-- Execution code
--- Process commandline arguments
local last_setter
local arguments = {}
for i = 1, #args do
local arg = args[ i ]
if type( arg ) == "string" then
if arg:find( "^%-" ) then
last_setter = arg:gsub( "^%-%-?", "" )
arguments[ last_setter ] = true
else
if last_setter then
if type( arguments[ last_setter ] ) ~= "table" then
arguments[ last_setter ] = {}
end
arguments[ last_setter ][ #arguments[ last_setter ] + 1 ] = arg
end
end
end
end
if not arguments[ "no-intro" ] then
--- Display the Yellowave signature
-- (either variation #7, #1, or, if specified, the one set by the command line arg -yw)
term.redirect( wave_win )
local variation
if type( arguments.yw ) == "table" and arguments.yw[ 1 ] then
variation = arguments.yw[ 1 ]
else
variation = random() > 0.25 and 7 or 1
end
shell.run( "yellowave.lua", variation )
sleep( 1 )
for _ = 1, 3 do
main_buf:map( shade )
main_buf:render_to_window( main_win, 1, 1, true )
sleep( 0 )
sleep( 0 )
end
term.redirect( main_win )
end
wave_win.setVisible( false )