-
Notifications
You must be signed in to change notification settings - Fork 9
/
world_space.p8
2036 lines (1838 loc) · 68.8 KB
/
world_space.p8
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
pico-8 cartridge // http://www.pico-8.com
version 8
__lua__
-- [co]sine tables
cal = {}
sal = {}
function compute_tables()
for theta=0,359 do
local angle=theta/360
local ca = cos(angle)
local sa = sin(angle)
cal[theta] = {}
sal[theta] = {}
for x=-8,8 do
cal[theta][x] = ca * x
sal[theta][x] = sa * x
end
end
end
-- function tprint(str)
-- local tcurrent = time()
-- print(str..": "..tcurrent-tlast)
-- tlast = tcurrent
-- end
function print_label(str, off_y)
off_y = off_y or 0
print(str, -(#str)*2, 12+off_y, 8)
end
-- warp gate colors
ep_c = {5,1,12}
function make_warp_gate(x,y,target_system)
return {
x=x,
y=y,
space=sp_world,
tspawn=g_tick,
target_system=target_system,
sats=make_satellites(30,3),
radius=3,
minimap_obj_color=12,
update=function(t)
if collides_circles(t, g_p1) then
make_system(t.target_system)
g_p1.x, g_p1.y, g_p1.velocity = 0,0,makev(0)
end
end,
draw=function(t)
for i,n in pairs({5,4,3,2}) do
rectfill(
-n,
-n*2,
n,
n*2,
ep_c[(-elapsed(t.tspawn)+i)/2%5+1]
)
end
for _, s in pairs(t.sats) do
local sat_theta = flr((((s.spd*elapsed(t.tspawn)+s.phase)%64)/64)*360)
local x0 = s.a*cal[sat_theta][1]
local y0 = s.b*sal[sat_theta][1]
-- derivatives
if (x0 < 0 and -y0 < 0) or (x0 > 0 and -y0 > 0) then
local cr = cal[s.rot][1]
local sr = sal[s.rot][1]
local xr = x0*cr-y0*sr
local yr = y0*cr+x0*sr
line(xr,yr, xr,yr, 12)
end
end
print_label(t.target_system)
end
}
end
function vecatan(v)
return flr(atan2(v.x, v.y)*360)
end
function compute_planet_noise(kind, seed)
srand(seed)
-- tlast = time()
sprites_wide = 2
-- radius=(sprites_wide/2)*8
radius=sprites_wide*4
local xmin=0
local xmax=sprites_wide*8
local xcenter=(xmax-xmin)/2 + xmin
local ymin=4*8
local ymax=(4+sprites_wide)*8
local ycenter=(ymax-ymin)/2 + ymin
copies_x = 3
copies_y = 3
copies_xy = copies_x*copies_y
-- using the algorithm from star control 2, noted in the gdc retro game post
-- mortem - generate a bunch of lines and raise/lower the height map between
-- those regions, then quantize and map the colors
-- base height
-- cls()
function rnd_point()
return {
rnd(xmax-xmin)+xmin,
rnd(ymax-ymin)+ymin
}
end
local img = {}
local cmin = 0
local cmax = 50
local coff = 0
if kind == "gasgiant" then
coff = cmax/4
end
for x=xmin,xmax do
img[x] = {}
for y=ymin,ymax do
img[x][y] = flr(cmax/2 + coff)
end
end
-- tprint("setup")
function rnd_line(sp, ep)
sp=sp or (rnd_point())
ep=ep or (rnd_point())
-- print("sp: "..sp[1]..", "..sp[2])
-- print("ep: "..ep[1]..", "..ep[2])
local xd = ep[1] - sp[1]
local yd = ep[2] - sp[2]
local fac = sp[2]*xd-sp[1]*yd
return {
startp=sp,
endp=ep,
xd=xd,
yd=yd,
fac=fac,
s_dist=function(t, x, y)
return (x*t.yd - y*t.xd + t.fac)
end
}
end
function line_gas_giant()
local sp = rnd_point()
sp[1] = xmin
local ep = rnd_point()
ep[1] = xmax
while abs(ep[2]-sp[2]) > 3 do
ep =rnd_point()
end
return rnd_line(sp,ep)
end
-- generate lines and raise stuff where we are on opposite side of the lines
-- lower where we're on the same side
for i=0,cmax do
local l1, l2 = nil, nil
if kind == "gasgiant" then
-- ep[2] = sp[2]
l1 = line_gas_giant()
l2 = line_gas_giant()
elseif kind == "normal" then
l1 = rnd_line()
l2 = rnd_line()
end
for x=xmin,xmax do
local ln=img[x]
for y=ymin,ymax do
if (l1:s_dist(x,y) < 0) != (l2:s_dist(x,y) < 0) then
ln[y] = ln[y]+1
else
ln[y] = ln[y]-1
end
end
end
end
-- tprint("noise")
-- local hist = {}
-- hist[1] = 0
-- hist[2] = 0
-- hist[3] = 0
-- hist[4] = 0
-- quantize
for x=xmin,xmax do
local ln=img[x]
for y=ymin,ymax do
local val = ln[y]
-- local c=val
local c=4
if val < 0.45*cmax then
c=1
elseif val < 0.6*cmax then
c=2
elseif val < 0.7*cmax then
c=3
end
-- hist[c] +=1
ln[y] = c
end
end
-- for i=1,4 do
-- print(i..": ".. hist[i])
-- end
-- tprint("quantize")
-- rotation
local ycenter = radius+ymin
local r2 = radius*radius
for y=ymin,ymax do
local b = abs(y-ycenter)
local a = sqrt(r2-b*b)
local v = makev(a,b)
local rotation_scale = 2*cal[vecatan(v)][1]
for x=xmin,xmax do
local c = img[x][y]
for off_y=0,(copies_y-1) do
local new_y = y+off_y*sprites_wide*8
for off_x=0,copies_x-1 do
local rotation_offset = (
x+rotation_scale*((off_x-copies_xy/2)+off_y*copies_x)
)%xmax
local new_x = rotation_offset+off_x*(sprites_wide*8)
sset(new_x,new_y,c)
end
end
end
end
-- tprint("rotation")
-- add poles and make round
for x=xmin,xmax do
local xd=x-xcenter
local xd2=xd*xd
for y=ymin,ymax do
local yd=y-ycenter
local c=1
-- crop out corners to make look round
if xd2+yd*yd < r2 then
-- poles
if (ymax-y < 2 or y-ymin < 2) and kind != "gasgiant" then
c=7
end
else
c=0
end
for off_x=0,(copies_x-1) do
local new_x = x+off_x*sprites_wide*8
for off_y=0,(copies_y-1) do
if c == 0 or c==7 then
local new_y = y+off_y*sprites_wide*8
sset(new_x,new_y,c)
end
end
end
end
end
-- tprint("poles")
-- if true then
-- spr(64,0,55,16,16)
-- -- tprint("final")
-- stop()
-- return
-- end
end
-- mouse support
poke(0x5F2D, 1)
function _init()
stdinit()
compute_tables()
add(
g_objs,
make_menu(
{
'go',
},
function (t, i, s)
add (
s,
make_trans(
function()
game_start()
end
)
)
end
)
)
g_st = gst_menu
end
gst_menu = 0
gst_playing = 1
g_sleep = 0
function _update()
if g_sleep > 0 then
g_sleep -= 1
return
end
stdupdate()
updateobjs(g_sys_objs)
for i, o in pairs(g_sys_objs) do
for j=i,#g_sys_objs do
local t = g_sys_objs[j]
if t then
local source, target = t, o
local tag = o.tag
local collision_effect_map = t.collision_effect_map
if not tag or not collision_effect_map or not collision_effect_map[tag] then
tag = t.tag
collision_effect_map = o.collision_effect_map
source, target = o, t
end
if tag and collision_effect_map then
if collision_effect_map[tag] then
if collides_circles(source, target) then
collision_effect_map[tag](source, target)
end
end
end
end
end
end
end
function _draw()
if g_sleep > 0 then
return
end
stddraw()
end
-- coordinate systems
sp_world = 0
sp_local = 1
sp_screen_native = 2
sp_screen_center = 3
function am_playing()
return g_st == gst_playing
end
function makev(xf, yf)
return {x=xf, y=(yf or xf)}
end
-- @TODO: Collect all the rotation code into one place
function vecfromrot(theta, mag)
theta = (359-theta)
return vecscale(makev(cal[theta][1], sal[theta][1]), mag or 1)
end
function look_at(this, p, turning_speed)
local dir_vec = vecnorm(vecsub(p, this))
local tgt_angle = flr((1-atan2(dir_vec.x, dir_vec.y)) * 360)
local delta = tgt_angle - this.theta
-- already at the correct angle
if abs(delta) < turning_speed then
this.theta = tgt_angle
return 0
end
if delta >= 180 then
delta -= 360
elseif delta <= -180 then
delta += 360
end
if delta > 0 then
this.theta += turning_speed
else
this.theta -= turning_speed
end
this.theta = wrap_angle(this.theta)
return delta
end
-- rotate a sprite
function rotate_sprite(angle,tcolor,sspx,sspy)
local cala = cal[angle]
local sala = sal[angle]
for x=-7,6,1 do
-- @TOKEN: dropping these look ups can save a few tokens (4)?
-- @{
local cal_x = cala[x]
local sal_x = sala[x]
local x_out = x+sspx+16
-- @}
for y=-7,6,1 do
-- 2d rotation about the origin
local xp = cal_x-sala[y]
local yp = sal_x+cala[y]
-- if the pixel is over range,
-- use the transparent color
-- otherwise fetch the color from
-- the sprite sheet
local c = abs(xp) < 7 and abs(yp) < 7 and sget(xp+sspx,yp+sspy) or tcolor
-- set a color in the sprite
-- sheet next to the currnet sprite
sset(x_out,y+sspy,c)
end
end
return angle
end
function wrap_angle(angle)
if angle > 359 then
angle -= 360
elseif angle < 0 then
angle += 360
end
return angle
end
-- function make_pushable(x,y)
-- return make_physobj(
-- {
-- x=x,
-- y=y,
-- name="pushable_["..x..","..y.."]",
-- space=sp_world,
-- vis_r=5,
-- draw=function(t)
-- circfill(0,0,5,6)
-- circfill(0,0,2,2)
-- circ(0,0,t.vis_r, 8)
-- circ(0,0,t.radius, 9)
-- end
-- },
-- 100
-- )
-- end
-- @{ built in diagnostic stuff
function make_player(pnum)
return make_physobj(
{
x=0,
y=0,
pnum=pnum,
name="player"..pnum,
space=sp_world,
vis_r=7,
sprite=36,
theta = 0,
rendered_rot=nil,
update=function(t)
-- @TODO: factor this into a player "brain"
if not am_playing() then
return
end
local thrust = false
if btn(0, t.pnum) then
t.theta -= 10
end
if btn(1, t.pnum) then
t.theta += 10
end
if btn(2, t.pnum) then
thrust = true
end
if g_mouse_ptr.button_down[1] then
thrust = true
t.theta = 360-vecatan(vecsub(vecxform(g_mouse_ptr, sp_world),g_p1))
end
t.theta = wrap_angle(t.theta)
if btn(3, t.pnum) then
t.velocity = vecscale(t.velocity, 0.8)
end
if thrust then
accel_forward(t, 3, 5)
end
-- @TODO: shift this to an inventory system
if btnn(4, t.pnum) then
add_g_sys_objs(make_projectile(t, t.theta, t.velocity))
-- recoil
accel_forward(t, -10, 3)
-- camera shake
vecset(g_cam, vecadd(g_cam,vecrand(4, true)))
end
end,
draw=function(t)
print_label("world: " .. t.x .. ", " .. t.y)
print_label("theta: " .. t.theta, 6)
print_label("v: " .. vecmag(t.velocity), 12)
print_label("vfact: " .. vecmag(t.velocity)/5, 18)
-- local col_list = {}
-- for _, o in pairs(g_objs) do
-- if t ~= o and o.is_phys and not collided and collides_circles(t, o) then
-- col=col+1
-- add(col_list, o)
-- end
-- end
--
-- if #col_list > 0 then
-- local col_str = "colliding:"
-- for _, o in pairs(col_list) do
-- col_str = col_str .. " " .. o.name
-- end
-- print_label(col_str, 10)
-- end
pusht({{3, true},{0,false}})
rotate_sprite_if_changed(t, 3, 23, 23)
spr(t.sprite, -7, -7,2,2)
popt()
circ(0,0,t.radius,11)
-- local v_loc = vecfromrot(t.theta, 10)
-- circfill(v_loc.x, v_loc.y, 3, 11)
end
},
5
)
end
g_friction=0.2
function update_phys(o)
-- in case we want to play
-- with time, even though pico
-- gives us a constant clock
local dt = 1
o.x, o.velocity.x=compute_force_1d(
o.x,
o.force.x,
o.mass,
o.velocity.x,
dt
)
o.y, o.velocity.y=compute_force_1d(
o.y,
o.force.y,
o.mass,
o.velocity.y,
dt
)
-- zero out the force & apply drag
vecset(o.force, vecsub(makev(0), vecscale(o.velocity, g_friction)))
end
function vecstr(v)
return ""..v.x..", "..v.y
end
-- function vecdot(a, b)
-- return a.x * b.x + a.y * b.y
-- end
function vecadd(a, b)
return {x=a.x+b.x, y=a.y+b.y}
end
function vecsub(a, b)
return {x=a.x-b.x, y=a.y-b.y}
end
-- function vecmult(a, b)
-- return {x=a.x*b.x, y=a.y*b.y}
-- end
function vecscale(v, m)
return {x=v.x*m, y=v.y*m}
end
function vecmagsq(v)
return v.x*v.x+v.y*v.y
end
function vecmag(v, sf)
if sf then
v = vecscale(v, sf)
end
local result=sqrt(vecmagsq(v))
if sf then
result=result/sf
end
return result
end
-- function vecrot(v, a)
-- local s = sin(a/360)
-- local c = cos(a/360)
-- return {
-- x=v.x * c - v.y * s,
-- y=v.x * s + v.y * c,
-- }
-- end
function vecdistsq(a, b, sf)
if sf then
a = vecscale(a, sf)
b = vecscale(b, sf)
end
local distsq = (b.x-a.x)^2 + (b.y-a.y)^2
if sf then
distsq = distsq/sf
end
return distsq
end
-- global null vector
null_v = makev(0)
function vecnorm(v)
return vecscale(v, 1/sqrt(vecdistsq(null_v,v)) )
end
function update_collision(o, o_num)
-- (checking o, pos is new pos
-- check boundaries first
-- pos.x, o.velocity.x = collide_walls_1d(
-- g_edges[1],pos.x,o.velocity.x,o.radius)
-- pos.y, o.velocity.y = collide_walls_1d(
-- g_edges[2],pos.y,o.velocity.y,o.radius)
for i=o_num,#g_objs do
local t = g_objs[i]
if t.is_phys and t ~= o then
if collides_circles(t, o) then
if not t.is_static then
-- push the objects back
local r = o.radius + t.radius
local v = vecsub(o,t)
local v_n = vecnorm(v)
-- result
vecset(o, vecadd(vecscale(v_n, r),t))
-- a.v = (a.u * (a.m - b.m) + (2 * b.m * b.u)) / (a.m + b.m)
-- b.v = (b.u * (b.m - a.m) + (2 * a.m * a.u)) / (a.m + b.m)
local o_v = o.velocity
local t_v = t.velocity
local o_m = o.mass
local t_m = t.mass
o.velocity = vecscale(
vecadd(vecscale(o_v, (o_m-t_m)), vecscale(t_v,2*t_m)),
1/(o_m+t_m)
)
t.velocity = vecscale(vecadd(vecscale(t_v, (t_m-o_m)),(vecscale(o_v,2*o_m))),(1/(o_m+t_m)))
end
end
end
end
end
function collides_circles(o1, o2)
local d = vecsub(o1, o2)
local r_2 = o1.radius + o2.radius
-- cheat to avoid huge squares
if abs(d.x) > r_2 or abs(d.y) > r_2 then
return false
end
return vecmagsq(d) < r_2 * r_2
end
-- creates a physics object out
-- of the parent object with a
-- given mass
function make_physobj(p,mass)
phys = {
p=p,
mass=mass,
force=makev(0),
velocity=makev(0),
radius=p.vis_r or 5,
is_phys=true,
is_static=false,
}
for k,v in pairs(phys) do
p[k] = v
end
return p
end
g_tstack={}
-- takes a list of tuples color, tval
function pusht(tlist)
-- todo make push/pop work better
add(g_tstack, tlist)
for i, ttuple in pairs(tlist) do
palt(ttuple[1], ttuple[2])
end
end
function popt(tlist)
local len = #g_tstack
local last = g_tstack[len]
for i, ttuple in pairs(last) do
palt(ttuple[1], not ttuple[2])
end
g_tstack[len] = nil
end
g_spacing = 64
function make_infinite_grid()
return {
space=sp_screen_native,
draw=function(t)
local g_o_x = 128 - g_cam.x % 128
local g_o_y = 128 - g_cam.y % 128
for x=0,3 do
for y=0,3 do
-- screen coordinates
local xc = (x-1.5)*g_spacing + g_o_x
local yc = (y-1.5)*g_spacing + g_o_y
rect(xc-1, yc-1,xc+1, yc+1, 5)
circ(xc, yc, 7, 5)
-- label
local smin = vecsub(g_cam, makev(64))
local str = "w: " .. xc + smin.x .. ", ".. yc + smin.y
print(str, xc-#str*2, yc+9, 5)
end
end
end
}
end
-- assumed to be in world space
function make_camera()
return {
x=0,
y=0,
is_visible=function(t, o)
-- uses a circle based visibility check
if not o.vis_r or
(
(
t.x - 64 - o.vis_r < o.x
and t.x + 64 + o.vis_r > o.x
)
and
(
t.y - 64 - o.vis_r < o.y
and t.y + 64 + o.vis_r > o.y
)
)
then
return true
end
return false
end,
update=function(t)
-- t.x=g_p1.x
-- t.y=g_p1.y
-- @TODO: make the target point lead the player
vecset(t,veclerp(t,g_p1,0.5,0.3))
end,
draw=function(t)
end
}
end
-- @}
function make_debugmsg()
return {
space=sp_screen_native,
draw=function(t)
color(14)
print("",0,0)
print("cpu: ".. stat(1))
print("mem: ".. stat(2))
if g_mouse_ptr then
print(vecstr(g_mouse_ptr))
for _, o in pairs(g_mouse_ptr.button_down) do
print(print(o))
end
print(vecstr(vecxform(g_mouse_ptr, sp_world)))
print(360-vecatan(vecnorm(vecsub(vecxform(g_mouse_ptr, sp_world),g_p1))))
end
-- local vis="false"
-- if g_p2 and g_cam:is_visible(g_p2) then
-- vis = "true"
-- end
-- if g_p2 then
-- print("p2 vis: ".. vis)
-- print(g_cam.x-64-g_p2.vis_r .. ", " ..g_cam.y-64-g_p2.vis_r)
-- print("vel: ".. vecmag(g_p1.velocity))
-- print("p_vel: ".. vecmag(g_pushable.velocity))
-- end
end
}
end
function make_satellites(nsats,maxspd)
local sats = {}
for i=1,nsats do
local a=15
local b=15
local reduced = rnd(15)
if rnd(1) < 0.5 then
a=reduced
else
b=reduced
end
local spd =rnd(maxspd)
if rnd(1) < 0.4 then
spd *= -1
end
add(
sats,
{
a=a,
b=b,
rot=flr(rnd(360)),
phase=rnd(64),
spd=spd,
size=rnd(2)
-- spd=rnd(3)
}
)
end
return sats
end
function reset_palette()
for i=0,15 do
pal(i,i)
end
end
function set_palette(palmap)
for i, c in pairs(palmap) do
pal(i, c)
end
end
function make_planet(name,x,y,sats,kind,palette, seed)
compute_planet_noise(kind, seed)
return {
x=x,
y=y,
minimap_obj_color=3,
name=name,
space=sp_world,
frame=0,
sats=make_satellites(sats,0.4),
palette=palette,
kind=kind,
update=function(t)
t.frame +=1
end,
draw=function(t)
local f = flr(t.frame/64) % copies_xy
local fx = f % copies_x
-- local fx = flr(f / 3)
local fy = flr(f / copies_x)
-- local fy = f % 4
-- for i=1,9 do
-- pal(i,12)
-- end
-- for i=10,12 do
-- pal(i, 3)
-- end
-- for i=13,15 do
-- pal(i, 4)
-- end
-- pal(7,7)
set_palette(t.palette)
local sprite_index = 64+(16*fy+fx)*sprites_wide
-- @TODO: switch this to sspr and make planets bigger. They're cool!
spr(sprite_index,-radius,-radius,sprites_wide,sprites_wide)
reset_palette()
-- print(fx..", "..fy.." ["..sprite_index.."]", -10, 20, 7)
-- satellite
for _, s in pairs(t.sats) do
local sat_theta = flr((((s.spd*t.frame+s.phase)%64)/64)*360)
local x0 = s.a*cal[sat_theta][1]
local y0 = s.b*sal[sat_theta][1]
local cr = cal[s.rot][1]
local sr = sal[s.rot][1]
local xr = x0*cr-y0*sr
local yr = y0*cr+x0*sr
rectfill(xr,yr, xr+s.size,yr+s.size, 6)
end
print_label(t.name)
-- for i=1,14 do
-- palt(i,true)
-- end
-- pal(15,6)
-- spr(64+4*(flr((t.frame+8)/4)%4),-2*8,-2*8,4,4)
-- pal(15,15)
-- for i=1,14 do
-- palt(i,false)
-- end
end
}
end
function add_gobjs(thing)
add(g_objs, thing)
return thing
end
function add_g_sys_objs(thing)
add(g_sys_objs, thing)
return thing
end
-- @TODO: Rings & mmoons
g_sys_size = 500
one_over_g_sys_size_2 = 1/(2*g_sys_size)
g_systems = {
mercury = {
gates = {
{50, 0, "venus"}
},
-- name x y sats ptype palette
planet = { "mercury", 40,40, 1, "normal", {5,6,7,15}, 2},
others = {}
},
venus = {
gates = {
{-50, 0, "mercury"},
{50, 0, "earth"}
},
-- name x y sats ptype palette
planet = { "venus", 40,40, 3, "normal", {7,9,10,15}, 8},
others = {}
},
earth = {
gates = {
{-250, 0, "venus"},
{150, 0, "mars"}
},
-- name x y sats ptype palette
planet = { "earth", 140,140, 40, "normal", {12, 4, 3, 7}, 2},
others = {}
},
mars = {
gates = {
{-50, 0, "earth"},
{50, 0, "jupiter"}
},
planet = { "mars", -40,-40, 10, "normal", {2, 4, 9, 7}, 1},
},
jupiter = {
gates = {
{-50, 0, "mars"},