-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhexagon.spin
2240 lines (1813 loc) · 140 KB
/
hexagon.spin
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
CON
{{
############# ############### ############### #############
############# ############### ############### #############
############### ############### ############### ###############
############### ############### ############### ###############
#### #### #### ### #### ####
#### #### #### ### #### ####
############### #### #### ### #### ####
############### ############### ### #### ####
############### ############### ### #### ####
#### ############# ### #### ####
#### ############# ### #### ####
############### #### ############### #### ####
############### #### ############### #### ####
############# #### ############### #### ####
############# #### ############### #### ####
## ## ######## ## ## ####### ######## ####### #######
## ## ######## ## ## ######## ######## ######## ########
## ## ## ## ## ## ## ## ## ## ## ##
######## ######## ###### ## ## ## ## ## ## ## ##
######## ######## ###### ######## ## ## ## ## ## ##
## ## ## ## ## ######## ## ## ## ## ## ##
## ## ######## ## ## ## ## ######## ######## ## ##
## ## ####### ## ## ## ## ####### ####### ## ##
Release Candidate 4
2020 IRQsome Software
Distributed under permission from Terry Cavanagh
Original by Terry Cavanagh
Music by Chipzel
Voice by Jenn Frank
}}
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
_stack = 200
CHEATZ = 0 ' 0 for no cheats, 1 for minor cheats, 2 for noclip
SCANLINE_BUFFER = gfx#SCANLINE_BUFFER
NUM_LINES = gfx#NUM_LINES
border_color = gfx#border_color ' border color
displaylist_adr = gfx#displaylist_adr 'pointer to display list
displaylist_in_use = gfx#displaylist_in_use 'display list adress feedback
END_OF_DRIVER_RESERVED = gfx#MEMORY_END
DLIST_SIZE = 640 ' longs
_free = ($8000-END_OF_DRIVER_RESERVED+3)/4
OBJ
gfx : "VJET_v00_composite_wrapper_xasm.spin"
kb : "Keyboard_xasm.spin"
pst: "DummyPST"'}"Parallax Serial Terminal"
gl : "VJET_v00_displaylist.spin"
font: "hexfont.spin"
sdda: "hexagon_sdda.spin"
plat: "platform.spin"
DAT '' pretend this is a VAR (non-zero-initialized variables and some byte/word wide ones go here to help make fastspin happy)
org
random long 42
color1 word $0202
color2 word $0202
color3 word $0202
sector_angles word 0*(8192/SECTORS),1*(8192/SECTORS),2*(8192/SECTORS),3*(8192/SECTORS),4*(8192/SECTORS),5*(8192/SECTORS)
stage byte 0
state byte TITLE
safe_colors byte false ' change to true when using S-Video (disables $x8 colors)
firstplay_flag byte 0
current_music byte -1
strbuf_hi byte 0[8] ' current stage hiscore string buffer
strbuf_frames byte 0[4] ' current timer string buffers
strbuf_secs byte 0[4]
strbuf2_frames byte 0[4]
strbuf2_secs byte 0[4] ' misc.
DAT '' some lookup tables and strings
leveltimetbl word
word 0*60 ' Point
word 10*60 ' Line
word 20*60 ' Triangle
word 30*60 ' Square
word 45*60 ' Pentagon
word 60*60 ' Hexagon
word 0 ' convenient zero
levelstringtbl word
word @point_str
word @line_str
word @triangle_str
word @square_str
word @pentagon_str
word @hexagon_str
stagestringtbl word
word @hexagon_str
word @hexagoner_str
word @hexagonest_str
word @hexagon_str
word @hexagoner_str
word @hexagonest_str
word @blackwhite_str
stagedifficultytbl word
word @hard_str
word @harder_str
word @hardest_str
word @hardester_str
word @hardestest_str
word @hardestestest_str
word @hexagon_str
stage2effstage_tbl byte
byte EFF_HEXAGON1,EFF_HEXAGONER1,EFF_HEXAGONEST1,EFF_HEXAGON2,EFF_HEXAGONER2,EFF_HEXAGONEST2,EFF_BLACKWHITE
new_record_str byte "NEW "
record_str byte "RECORD!",0
hyper_str byte "HYPER",0
DAT
long
org
save_space
stage_records long 0[STAGE_COUNT]
long 0[sdda#SAVE_SIZE-STAGE_COUNT] 'reserve some data
org
dlist_space '' Display lists overwrite cog PASM
render_asm file "VJET_v00_rendering.dat"
tv_asm file "VJET_v00_composite.dat"
sdda_asm file "tinySDDA.dat"
keyboard_asm file "Keyboard.dat"
long $00[DLIST_SIZE*2-$]
VAR
long state_timer, game_timer
word script_timer ' the wait times are limited to 15 bits, anyways
long view_scale_y,center_x,center_y
word player_angle
long playfield_speed
word playfield_rotation
byte effectivestage
byte hitflag
byte playfield_colorswap
byte player_sector
byte colorswap_timer
long wall_phase
byte wall_spawnpos
word wall_speed,player_speed
long speed_target ' for playfield_speed
word fontptr,subcodeptr
long next_pattern
word patternlist
word script_pc
byte overflow_flag,commit_record_flag,gameover_newrecord_flag
long framecount
long snes_prev
long polybuf[SECTORS*2*4]
long sector_vx[SECTORS],sector_vy[SECTORS]
'long sector_walls[SECTORS*WALLBUFFER_SIZE]
'long walls_low[SECTORS],walls_high[SECTORS]
byte _dummy,wallbitmap[WALLBUFFER_SIZE]
word dlist1ptr,dlist2ptr
'long dlist1[DLIST_SIZE],dlist2[DLIST_SIZE]
CON '' Enumerations
#0,HEXAGON,HEXAGONER,HEXAGONEST,HYPER_HEXAGON,HYPER_HEXAGONER,HYPER_HEXAGONEST,BLACKWHITE,STAGE_COUNT
#0,EFF_TITLE,EFF_HEXAGON1,EFF_HEXAGON2,EFF_HEXAGON3,EFF_HEXAGONER1,EFF_HEXAGONER2,EFF_HEXAGONER3,EFF_HEXAGONEST1,EFF_HEXAGONEST2,EFF_BLACKWHITE
#0,TITLE,LEVELSELECT,PLAY,GAMEOVER
PUB main
init
repeat
do_frame
PRI do_frame | tmp
gfx.Wait_Vsync
if overflow_flag~
tmp:=$CC
else
tmp:=$2D
word[border_color]:=tmp
ifnot framecount&1
word[displaylist_adr] := dlist1ptr
gl.start(dlist2ptr,constant(DLIST_SIZE*4))
else
word[displaylist_adr] := dlist2ptr
gl.start(dlist1ptr,constant(DLIST_SIZE*4))
framecount++
'framecount &= $1f
'longmove(current_dlist,@testdlist,128)
update
if tmp := \draw
pst.str(string("ABORT "))
pst.dec(tmp)
pst.newline
if tmp:=gl.done
overflow_flag~~
pst.str(string("DLIST OVRFLOW: "))
pst.dec(tmp)
pst.newline
'pst.str(string("onek "))
'pst.hex(framecount,8)
'pst.newline
word[border_color]:=$04
'word[@testdlist][1] := 50+(sin(framecount*63)/2048)
'word[@testdlist][2] := word[@testdlist][1]+20
PRI init
pst.start(115_200)
if sdda.unstash
subcodeptr:= sdda.sdda_start(@sdda_asm)
else
subcodeptr:= $8080
' try loading the saved records - remains zero-initialized otherwise
sdda.readsavedata(@save_space)
kb.startx(plat#PS2_DATA,plat#PS2_CLOCK,%0_111_001, %11_11111,@keyboard_asm)
word[displaylist_adr] := $8080
''set up graphics driver
gfx.start(plat#TV_PINGROUP,4,@render_asm,@tv_asm) 'start graphics driver
dlist1ptr := @dlist_space
dlist2ptr := @dlist_space+constant(DLIST_SIZE*4)
longfill(@dlist_space,0,constant(DLIST_SIZE*2)) ' this is neccessary to make sure the graphics cogs don't go off the deep end
gl.set_clip(0,gfx#HEIGHT<<16,0,gfx#WIDTH<<16)
fontptr := font.get
clearwalls
CON
PRESCALE_SHL = 6
PRESCALE = |<PRESCALE_SHL
PIXEL_ASPECT = 35.5/28.0 '' Aspect ratio of a pixel - empircal measurement
VIRTUAL_WIDTH = float(gfx#WIDTH)*PIXEL_ASPECT
VIRTUAL_HEIGHT = float(gfx#HEIGHT)
PIXEL_ASPECT_FIX = round(float(posx)/PIXEL_ASPECT)
SECTORS = 6
WALLBUFFER_SIZE = 48
WALL_PARKED = negx/2
PLAYFIELD_RADIUS = 1024
PATTERN_UNIT = 16
PATTERN_PTR_MASK = $F_FFFF ' P2 ready!
PATTERN_CW = 0
PATTERN_CCW = |<31
PATTERN_OFFSET_SHIFT = 28
PATTERN_OFFSET_MASK = $7
PATTERN_WEIGHT_SHIFT = 20
PATTERN_WEIGHT_MASK = $FF
OFFSET_RANDOMIZE = 6
OFFSET_RANDOMIZE2 = 7 'also randomize direction
SPEED_SMOOTHING = 6
HEXAGON1_RADIUS_UNSCALED = 22 ' measured
HEXAGON1_RADIUS = HEXAGON1_RADIUS_UNSCALED * PRESCALE
PLAYER_RADIUS_UNSCALED = 28 ' measured
PLAYER_RADIUS = PLAYER_RADIUS_UNSCALED * PRESCALE
PLAYER_RADIUS_WALLSPACE = $10000*(PLAYER_RADIUS_UNSCALED-HEXAGON1_RADIUS_UNSCALED)/WALL_UNIT_UNSCALED
WALL_UNIT_UNSCALED = 16
WALL_UNIT = WALL_UNIT_UNSCALED * PRESCALE
TEST1_RADIUS = 64 * PRESCALE
PLAYER_RADIUS_INNER = float(PLAYER_RADIUS_UNSCALED)*((^^3.0)/2.0)
WALLDRAW_RADIUS = trunc(^^((VIRTUAL_WIDTH*VIRTUAL_WIDTH+VIRTUAL_HEIGHT*VIRTUAL_HEIGHT)/4.0)-PLAYER_RADIUS_INNER+float(PLAYER_RADIUS_UNSCALED))'200
WALLDRAW_MAX = WALLDRAW_RADIUS/WALL_UNIT_UNSCALED+2
WALLSPAWN_MAX = 15 ' should be larger than WALLDRAW_MAX to avoid pop-in
PRI clearwalls
'longfill(@sector_walls,WALL_PARKED,SECTORS*WALLBUFFER_SIZE)
'wall_phase := $D0000
'longfill(@walls_low,0,constant(SECTORS*2)) ' fill both walls_low and walls_high
bytefill(@wallbitmap,0,WALLBUFFER_SIZE)
wall_phase := 0
wall_spawnpos := WALLSPAWN_MAX
{PRI testwalls | i
clearwalls
repeat i from 0 to constant(WALLBUFFER_SIZE-1)
'wallbitmap[i] |= ($99 << (i&1))&$1F
wallbitmap[i] := $49249249 >> i
}
PRI try_spawn_pattern |i,tmp,wptr,offset,ccw,size
'pst.str(string(13,"Attempting spawn... "))
'pst.dec(wall_spawnpos)
'pst.char(" ")
'pst.hex(next_pattern,4)
'pst.char(" ")
if wall_spawnpos => WALLSPAWN_MAX ' don't spawn too far ahead
return
wptr := next_pattern'&PATTERN_PTR_MASK
'pst.str(string("okay... "))
if (size:=byte[wptr++]) + wall_spawnpos => WALLBUFFER_SIZE ' check if there are enough free slots
return
'pst.str(string("WE'RE IN! "))
' prepare
offset := (next_pattern>>PATTERN_OFFSET_SHIFT)&PATTERN_OFFSET_MASK
ccw:=next_pattern & PATTERN_CCW
if offset => OFFSET_RANDOMIZE
if offset => OFFSET_RANDOMIZE2
if (random?)&4
NOT ccw
offset := (random?&posx)//SECTORS
pst.dec(offset)
if ccw ' Adjust offset for CCW so sector 0 stays sector 0
if (offset+=1) => SECTORS
offset:=0
'' actually perform spawning
repeat i from wall_spawnpos to wall_spawnpos+size-1
tmp := byte[wptr++]
if ccw
tmp ><= SECTORS
wallbitmap[i] := (tmp<<offset + tmp>>(SECTORS-offset))&constant((|<SECTORS)-1)
wall_spawnpos += byte[wptr] ' spacing
{pst.str(string("spacing: "))
pst.dec(byte[wptr])
pst.newline }
next_pattern~
PRI select_pattern(pattern_list) : pat | i,weight
'' sum total weight
i~
weight~
repeat while pat:=long[pattern_list][i++]
weight+= (pat>>PATTERN_WEIGHT_SHIFT)&PATTERN_WEIGHT_MASK
weight := (random?&posx) // weight
i~
repeat
pat:=long[pattern_list][i++]
if (weight -= (pat>>PATTERN_WEIGHT_SHIFT)&PATTERN_WEIGHT_MASK)<0
quit
CON
HUECALC_LEFTSAR = 16+3-4
HUECALC_RIGHTSAR = HUECALC_LEFTSAR - 8 -1
PRI huecalc(angl,swing,center) | tmp
tmp := sin(angl)
tmp += tmp~>14
'result := ((tmp~+constant(14-4))&$F0) + (((tmp+$10000)~>constant(14-(4+8)))&$F000)
result := ((((tmp+$0000)*swing)~>HUECALC_LEFTSAR) & $F0) + ((((((tmp+$0000)*swing)~>HUECALC_RIGHTSAR)+$800)~>1) & $F000)
result += center
result &= $F0F0
PRI update | i,j,tmp,tmp2,snes,sectorchange_flag,oldsector,clip_angle,huetmp,lkey,rkey,snes_trigger
'pst.str(string("update!",13))
if plat#SNES_PLAYER1 =>0
snes := SNES_Read_Gamepad
else
snes~
snes_trigger:=snes&!snes_prev
lkey := kb.keystate($C0) OR snes&constant(SNES_LEFT|SNES_L)
rkey := kb.keystate($C1) OR snes&constant(SNES_RIGHT|SNES_R)
random? ' RNG dummy tick
{ '' Old code - ressurect this if you want to add pentagon/square playfield
sector_angles[0]:=0 ' first sector is always zero to make life easier
repeat i from 1 to constant(SECTORS-1)
sector_angles[i] := i*constant(8192/SECTORS)
}
center_x := constant(128<<16)
center_y := constant(119<<16)
view_scale_y:= constant( negx >> ((PRESCALE_SHL-1)) )
{
pst.str(string("Time: "))
pst.dec(game_timer/60)
pst.char(":")
pst.dec(game_timer//60)
pst.newline}
time2dualstr(game_timer,@strbuf_frames)
case state
PLAY:
if state_timer == 1 ' safe to update strbuf_hi
update_strbuf_hi
sdda.play_sfx(sdda#SFX_BEGIN)
if state_timer<15
view_scale_y:=(view_scale_y ** (((15+1)-game_timer)*trunc(float(posx)/10.0*5.0/128.0))) << 8
else
view_scale_y+=byte[subcodeptr]<<17
ifnot game_timer
player_angle:=constant((8192/(SECTORS*2))/3)
'' stage script interpreter
'' see explanation further down
repeat
case tmp2:=word[script_pc]
$0000..$1FFF: '' SCRIPT_SPIN
speed_target := (tmp2<<19)~>19
$2000..$3FFF: '' SCRIPT_POS
playfield_rotation := tmp2&8191
$4000..$FFEF: '' SCRIPT_WAIT
if script_timer < tmp2-$4000
quit
$FFF0..$FFFF: '' special commands
tmp := word[script_pc+=2]
case tmp2&$F
$0: '' SCRIPT_CMD_JMP
script_pc:=@@tmp-2
script_timer~
$1: '' SCRIPT_CMD_EFFSTAGE
effectivestage := tmp
$2: '' SCRIPT_CMD_PATTERNS
patternlist := @@tmp
$3: '' SCRIPT_CMD_WALLSPEED
wall_speed := tmp
$4: '' SCRIPT_CMD_PLAYERSPEED
player_speed := tmp
$5: '' SCRIPT_CMD_MUSIC
'' TODO: evaluate firstplay_flag
if tmp <> current_music
sdda.play_music(current_music:=tmp)
script_pc+=2
script_timer++
'' find player's sector
player_sector~
repeat i from 0 to constant(SECTORS-1)
if sector_angles[i] =< player_angle
player_sector := i
'' move player
if lkey
player_angle -= player_speed
if rkey
player_angle += player_speed
player_angle&=8191
{
pst.str(string("before: "))
pst.dec(player_sector)
pst.newline
}
'' check for sector change
sectorchange_flag~
oldsector := player_sector
if player_sector == 0 AND player_angle => sector_angles[constant(SECTORS-1)] ' special case
player_sector := constant(SECTORS-1)
clip_angle := 0
sectorchange_flag~~
elseif player_sector == constant(SECTORS-1) AND player_angle < sector_angles[1] ' special case
player_sector := 0
clip_angle := 8191
sectorchange_flag~~
elseif player_sector <> 0 AND player_angle < sector_angles[player_sector]
clip_angle:=sector_angles[player_sector]
player_sector--
sectorchange_flag~~
elseif player_sector <> constant(SECTORS-1) AND player_angle => sector_angles[player_sector+1]
player_sector++
clip_angle := sector_angles[player_sector]-1
sectorchange_flag~~
{
pst.str(string("after: "))
pst.dec(player_sector)
pst.newline
pst.str(string("flag: "))
pst.dec(sectorchange_flag)
pst.newline
}
'' check for walls in new sector (to clip when moving sideways into a wall)
if sectorchange_flag
if wallbitmap[1] & |<player_sector
player_sector := oldsector
player_angle := clip_angle
'' Move walls closer and kill player
wall_phase -= wall_speed
if wall_phase < 0
tmp:= ((-wall_phase)>>16) <# constant(WALLBUFFER_SIZE-1)
bytemove(@wallbitmap,@wallbitmap+tmp,WALLBUFFER_SIZE-tmp)
bytefill(@wallbitmap+WALLBUFFER_SIZE-tmp,0,tmp)
wall_phase += tmp<<16
wall_spawnpos -= tmp
if CHEATZ < 2
hitflag OR= wallbitmap[1] & |<player_sector
{
pst.str(string("phase: "))
pst.hex(wall_phase,8)
pst.newline
pst.str(string("next: "))
pst.hex(next_pattern,8)
pst.str(string("list: "))
pst.hex(patternlist,4)
pst.newline
}
'patternlist := @whirlpool2_only''DEBUG!
'' select next pattern
if (NOT next_pattern) AND patternlist
next_pattern := @@0+select_pattern(patternlist)
'' try spawning next pattern
if next_pattern
try_spawn_pattern
'' Handle timer-related SFX
if game_timer==stage_records[stage]+1 and game_timer<>1
sdda.play_sfx(sdda#SFX_EXCELLENT)
elseif tmp := time2level(game_timer)
if leveltimetbl.word[tmp] == game_timer
sdda.play_sfx(constant(sdda#SFX_LINE-1)+tmp)
game_timer++
GAMEOVER:
ifnot state_timer
time2dualstr(stage_records[stage],@strbuf2_frames) ' write best time string
sdda.play_music(current_music:=-1)
sdda.play_sfx(sdda#SFX_GAMEOVER)
if state_timer => 60
view_scale_y:=(view_scale_y ** (((state_timer<#constant(60+10))-56)*trunc(float(posx)/10.0*3.0/128.0))) << 8
if state_timer < constant(60+10)
wall_phase+=$8000
speed_target:= -GAMEOVER_SPIN
if state_timer == 69 'nice
try_commit_record
LEVELSELECT:
firstplay_flag~~
center_y := constant(188<<16)
player_angle := -playfield_rotation+4096
view_scale_y<<=1
tmp:=constant(-8192/SECTORS)*stage + constant(8192/(SECTORS*2)*3)
ifnot state_timer
playfield_rotation:=tmp
speed_target:=((tmp-playfield_rotation)<<19)~>19
if ||speed_target < 64
if lkey
if stage-- == 0 ' Do this because stage is a byte
stage:=HYPER_HEXAGONEST
if rkey
if ++stage > HYPER_HEXAGONEST
stage:=0
if lkey or rkey
sdda.play_sfx(sdda#SFX_CHOOSE)
if ||speed_target < 11
speed_target:=playfield_speed:=0
playfield_rotation:=tmp
elseif speed_target < 0
speed_target:=-71
else
speed_target:=71
tmp := stage2effstage_tbl.byte[stage]
if is_current_locked
tmp := EFF_TITLE
effectivestage:=tmp
TITLE:
center_y := constant(238<<16)
view_scale_y<<=2
player_angle := -playfield_rotation ' moves player out of frame
speed_target := -20 '' TODO
effectivestage := EFF_TITLE
if state_timer==60
sdda.play_sfx(sdda#SFX_TITLE)
'' select colors
'effectivestage := EFF_HEXAGONER3 ''DEBUG!
tmp:=@effstage_color_tbl+effectivestage<<3 ' calc table base address
huetmp := word[tmp][3] ' get huecalc_center
if huetmp&$0100 ' colorswap flag?
if ++colorswap_timer => 45 ' measured
colorswap_timer~
NOT playfield_colorswap
else
playfield_colorswap:=colorswap_timer:=0
if tmp2:=(huetmp&$F)
huetmp:= huecalc(framecount*huecalc_tbl.byte[tmp2<<1],huecalc_tbl.byte[tmp2<<1+1],huetmp&$F0F0)
else
huetmp:= (framecount&$F0)+((framecount+$8)&$F0)<<8 '' Taste the rainbow
color1:=word[tmp][0]+huetmp
color2:=word[tmp][1]+huetmp
if NOT safe_colors AND effectivestage==EFF_HEXAGONER2
color3:=$8888^huetmp
else
color3:=word[tmp][2]+huetmp
'pst.hex(huetmp,8)
'pst.newline
if speed_target==SPINSPEED_BW_SPECIAL ' special case
playfield_speed := (((constant(-1*8192/2/SECTORS)-playfield_rotation)&8191)+31)>>5
else 'smooth out speed
tmp:=speed_target-playfield_speed
if tmp<0
playfield_speed += (tmp-constant(SPEED_SMOOTHING-1))/SPEED_SMOOTHING
elseif tmp>0
playfield_speed += (tmp+constant(SPEED_SMOOTHING-1))/SPEED_SMOOTHING
playfield_rotation += playfield_speed
state_timer++
repeat while kb.gotkey OR snes_trigger
if snes_trigger
tmp~
case i:=(|<((>|snes_trigger)-1))
SNES_A: tmp:=" "
SNES_X: tmp:="n"
SNES_Y: tmp:="b"
SNES_SELECT: tmp:=$DC
SNES_START: tmp:= $CB
snes_trigger &= !i
else
tmp := kb.key
pst.dec(tmp)
pst.newline
case tmp
$CB: ' Esc
if state==PLAY
hitflag~~
elseif state==GAMEOVER
try_commit_record
clearwalls
state_timer~
state:=LEVELSELECT
sdda.play_sfx(sdda#SFX_BACK)
elseif state==LEVELSELECT
state_timer~
state:=TITLE
sdda.play_sfx(sdda#SFX_BACK)
"t":
if CHEATZ
game_timer+= 60
script_timer += 60
" ": ' Space
if state==TITLE
state_timer~
state:=LEVELSELECT
sdda.play_sfx(sdda#SFX_SELECT)
elseif (state==GAMEOVER AND state_timer => 60) OR (state==LEVELSELECT and NOT is_current_locked)
try_commit_record
if stage == HEXAGON AND NOT is_locked(BLACKWHITE) AND lkey AND rkey
stage:=BLACKWHITE
clearwalls
game_timer~
state_timer~
script_timer~
script_pc := @@script_init_tbl.word[stage]
next_pattern~
state:=PLAY
$DC: ' printscreen
gfx.toggle_mode
$6C9: 'Ctrl-Alt-Del : Quit gracefully!
if state == GAMEOVER
try_commit_record
reboot
other: 'ignore
if hitflag~
state := GAMEOVER
state_timer~
commit_record_flag~~
gameover_newrecord_flag:= stage_records[stage] < game_timer
snes_prev:=snes
PRI is_current_locked
return is_locked(stage)
PRI is_locked(which)
ifnot CHEATZ
case which
HYPER_HEXAGON..HYPER_HEXAGONEST:result:= stage_records[which-3] < constant(60*60)
BLACKWHITE: result:= stage_records[HYPER_HEXAGONEST] < constant(60*60)
DAT
org
effstage_color_tbl word
'' color1 color2 color3 huecalc_center+colorswap flag
word $0303, $0404, $0505, $0000 ' EFF_TITLE
word $0A0A, $0B0B, $0D0D, $9091 ' EFF_HEXAGON1
word $0A0A, $0B0B, $0D0D, $1021 ' EFF_HEXAGON2
word $0A0A, $0B0B, $0D0D, $C0D1 ' EFF_HEXAGON3
word $0202, $0B0B, $0E0E, $5162 ' EFF_HEXAGONER1
word $0707, $0E0E, $0C0C, $D1D2 ' EFF_HEXAGONER2 (see special case color3 for NOT safe_colors)
word $0B0B, $0D0D, $0707, $D1D2 ' EFF_HEXAGONER3
word $0B0B, $0C0C, $0E0E, $0100 ' EFF_HEXAGONEST1
word $0404, $0505, $0707, $0100 ' EFF_HEXAGONEST2
word $0202, $0202, $0707, $0000 ' EFF_BLACKWHITE
huecalc_tbl byte '' indexed by bottom bits of huecalc_center
'' speed,range
byte 0, 0
byte 35,10
byte 20,20
PRI try_commit_record
if commit_record_flag~
stage_records[stage] #>= game_timer
ifnot CHEATZ
sdda.writesavedata(@save_space)
PRI draw
if state_timer < 5 ' Flash?
gl.triangle(constant((gfx#WIDTH/2)<<16),constant(-gfx#HEIGHT<<16),constant(-gfx#WIDTH<<16),constant(gfx#HEIGHT<<16),constant(2*gfx#WIDTH<<16),constant(gfx#HEIGHT<<16),$0707)
else
draw_game
if state == PLAY OR (state == GAMEOVER AND state_timer < 60)
draw_hud
elseif state == GAMEOVER AND state_timer=>70
draw_gameover
elseif state == LEVELSELECT
draw_levelselect
elseif state == TITLE
draw_title
return 0 ' dont trigger ABORT handler
PRI draw_game : view_scale_x |i,i2,j,tmp,rad,ibuf,wallactive,adjflag,tmp2,rscl1x,rscl1y,rscl2x,rscl2y',polybuf[SECTORS*2]
view_scale_x := (view_scale_y ** PIXEL_ASPECT_FIX)<<1
'' update/draw playfield
repeat i from 0 to constant(SECTORS-1)
tmp:= sector_angles[i]+playfield_rotation
sector_vx[i] := ((-sin(tmp))<<PRESCALE_SHL)**view_scale_x
sector_vy[i] := (sin(tmp+2048)<<PRESCALE_SHL)**view_scale_y
'' background
repeat i from 0 to constant(SECTORS-1)
if 0'i==player_sector
tmp2:=$7D7D
elseif (playfield_colorswap^i)&1
tmp2 := color1
else
tmp2 := color2
if (i2 := i+1) => SECTORS
i2 -= SECTORS
gl.triangle(center_x,center_y,{
}center_x+sector_vx[i]*PLAYFIELD_RADIUS,center_y+sector_vy[i]*PLAYFIELD_RADIUS,{
}center_x+sector_vx[i2]*PLAYFIELD_RADIUS,center_y+sector_vy[i2]*PLAYFIELD_RADIUS,tmp2)
'' central hexagon
repeat i from 0 to constant(SECTORS-1)
polybuf[i<<1] := center_x + sector_vx[i]*HEXAGON1_RADIUS_UNSCALED
polybuf[i<<1+1] := center_y + sector_vy[i]*HEXAGON1_RADIUS_UNSCALED
gl.polygon(@polybuf,SECTORS,color1)
gl.line_polygon(@polybuf,SECTORS,color3)
'' walls
wallactive~
repeat j from WALLDRAW_MAX to -1
tmp2:=wallbitmap[j]
if (tmp := ((j)<<16)+wall_phase+PLAYER_RADIUS_WALLSPACE) < -$0_0000
tmp2~
ifnot (tmp2)^wallactive
next
rad:=HEXAGON1_RADIUS_UNSCALED + (tmp*WALL_UNIT_UNSCALED) ~>constant(16)
adjflag~
repeat i from 0 to constant(SECTORS-1)
if (i2 := i+1) => SECTORS
i2 -= SECTORS
ibuf := @polybuf+i<<5
if tmp2 & |<i AND NOT (wallactive & |<i) ' wall starts, generate outer vertices
' outer 1
if adjflag
longmove(ibuf,adjflag,2)
else
long[ibuf][0] := center_x + sector_vx[i]*rad
long[ibuf][1] := center_y + sector_vy[i]*rad
' outer 2
long[ibuf][2] := center_x + sector_vx[i2]*rad
long[ibuf][3] := center_y + sector_vy[i2]*rad
adjflag:=ibuf+constant(2*4)
elseif !tmp2 & |<i AND (wallactive & |<i) 'wall ends, generate inner vertices and submit
' inner vertices' X
if adjflag
longmove(ibuf+constant(6*4),adjflag,2)
else
long[ibuf][6] := center_x + sector_vx[i]* (rad#>HEXAGON1_RADIUS_UNSCALED)
long[ibuf][4] := center_x + sector_vx[i2]*(rad#>HEXAGON1_RADIUS_UNSCALED)
if (long[ibuf][6]#>long[ibuf][4]) < 0
'pst.str(string("skip 1",13))
adjflag~
next ' perform X clipping because the GL doesn't, lol
if (long[ibuf][6]<#long[ibuf][4]) => constant(gfx#WIDTH<<16)
'pst.str(string("skip 2",13))
adjflag~
next ' perform X clipping because the GL doesn't, lol
' inner vertices' Y
ifnot adjflag
long[ibuf][7] := center_y + sector_vy[i]* (rad#>HEXAGON1_RADIUS_UNSCALED)
long[ibuf][5] := center_y + sector_vy[i2]*(rad#>HEXAGON1_RADIUS_UNSCALED)
{pst.str(string("submitting poly... "))
pst.dec(j)
pst.char(" ")
pst.dec(i)
pst.char(" ")
pst.dec(ibuf - @polybuf)
pst.newline}
gl.polygon(ibuf,4,color3)
adjflag:= ibuf+constant(4*4)
else
adjflag~
wallactive:=tmp2
''player
tmp := (-sin(player_angle+playfield_rotation) << PRESCALE_SHL)**view_scale_x
tmp2 := (sin(player_angle+playfield_rotation+2048) << PRESCALE_SHL)**view_scale_y
rscl1x := tmp*constant(PLAYER_RADIUS_UNSCALED-4)
rscl1y := tmp2*constant(PLAYER_RADIUS_UNSCALED-4)
rscl2x := tmp2*3
rscl2y := tmp*3
gl.triangle(center_x + (tmp*PLAYER_RADIUS_UNSCALED),center_y + (tmp2*PLAYER_RADIUS_UNSCALED),{
}center_x + rscl1x + rscl2x ,{
}center_y + rscl1y - rscl2y ,{
}center_x + rscl1x - rscl2x ,{
}center_y + rscl1y + rscl2y ,color3)
PRI draw_hud : lev | tmp,tmp2,ttx,barleft,barright,blink
'' HUD
if game_timer=>constant(100*60)
tmp:=constant(4*8)
ttx:=constant(142-18)
else
tmp:=0
ttx:=142
gl.polygon(@hud_topright_poly1+tmp,4,$0202)
gl.polygon(@hud_topright_poly2+tmp,4,$0202)
gl.polygon(@hud_topleft_poly,4,$0202)
gl.text_inline(224,constant(4+8),0,0,@strbuf_frames,fontptr,$0707)
gl.text_inline(174,4,1,1,@strbuf_secs,fontptr,$0707)
tmp := string(" TIME")
if stage => HYPER_HEXAGON
tmp := @hyper_str
gl.text(ttx,4,0,0,tmp,fontptr,$0707)
blink~
if (barright:=stage_records[stage]) => {1'}constant(60*60)
barleft:=0
tmp:=@strbuf_hi
if (blink:=barright - game_timer) < 0
tmp:=@record_str
else
lev := time2level(game_timer)
barleft:=leveltimetbl.word[lev]
barright:=leveltimetbl.word[lev+1]
if lev
blink:=barleft-game_timer
else
blink:=1
tmp:=@@levelstringtbl.word[lev]
'gl.text(10,4,0,0,tmp,fontptr,$0707)
if state_timer&8 AND (blink > -45 AND blink =< 0)
tmp2:=$0505
else
tmp2:=$0707
gl.text_centered(46,4,0,0,tmp,fontptr,tmp2)
if barright
tmp := constant(10<<16)+(((game_timer-barleft)<<16)/(barright-barleft) <# $1_0000)*71
gl.line(constant(10<<16),constant(14<<16),tmp,constant(14<<16),color3)
gl.line(tmp,constant(14<<16),constant(81<<16),constant(14<<16),color2)
else
gl.line(constant(10<<16),constant(14<<16),constant(81<<16),constant(14<<16),color3)
DAT
org
hud_topright_poly1
long 133<<16, -1<<16
long 260<<16, -1<<16
long 260<<16, 15<<16
long 141<<16, 15<<16
hud_topright_poly1_big
long 115<<16, -1<<16
long 260<<16, -1<<16
long 260<<16, 15<<16
long 123<<16, 15<<16