init repo
This commit is contained in:
commit
90e6151613
3260 files changed
+3745062
No files matched your search
@@ -0,0 +1,525 @@
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| |
|
||||
| Snake game |
|
||||
| |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
gcl0x
|
||||
|
||||
{
|
||||
Maybe:
|
||||
XXX Don't allow autoplayer to obtain a hi score
|
||||
XXX Use DOKE to plot fat pixels
|
||||
XXX More colors, less green
|
||||
XXX Smarter border drawing (spiral draw)
|
||||
XXX Use same drawing techique for clearing playfield
|
||||
XXX Increasing speed
|
||||
XXX Increase speed when pressing button
|
||||
}
|
||||
|
||||
{-
|
||||
First setup all subroutine definitions and variables, without making
|
||||
calls. This way allows use of vLR to hop from page to page during setup,
|
||||
with minimal overhead. At the end, run the main loop.
|
||||
-}
|
||||
|
||||
0 HighScore=
|
||||
|
||||
{ Print a 5x8 character on screen with the built-in font
|
||||
Char must be in the 32-127 range (this is not checked) }
|
||||
[def {PrintChar}
|
||||
{Map ASCII code to offset in font table}
|
||||
Char 82- [if<0 50+ i= \font32up
|
||||
else i= \font82up] fontData= {Select low or high page}
|
||||
i 2<< i+ {Multiply by 5}
|
||||
fontData+ fontData= {Add to page address to reach bitmap data for Char}
|
||||
|
||||
{Draw 5 vertical slices: 5 using font data}
|
||||
BgColor \sysArgs0.
|
||||
Color \sysArgs1.
|
||||
Pos \sysArgs4:
|
||||
6+ Pos=
|
||||
\SYS_VDrawBits_134 \sysFn:
|
||||
$fb i= [do
|
||||
fontData 0? fontData<++ \sysArgs2. 134!!
|
||||
\sysArgs4<++
|
||||
i<++ i if<>0loop]
|
||||
ret
|
||||
] PrintChar=
|
||||
|
||||
[def {PrintText}
|
||||
push
|
||||
Text=
|
||||
[do
|
||||
Text, Char= {Next character to be printed}
|
||||
if<>0 {Zero termination}
|
||||
Text<++ {Advance text pointer}
|
||||
Char 10^ [if=0 Pos<. $800 Pos+ Pos=
|
||||
else PrintChar!]
|
||||
loop]
|
||||
pop ret
|
||||
] PrintText=
|
||||
|
||||
[def
|
||||
$47# $69# $67# $61# $74# $72# $6f# $6e# 0# {Gigatron}
|
||||
] Title=
|
||||
|
||||
[def
|
||||
{-
|
||||
DrawLine -- Draw line
|
||||
-}
|
||||
Count i=
|
||||
[do if>0
|
||||
Color Pos.
|
||||
Pos Step+ Pos=
|
||||
i 1- i=
|
||||
loop]
|
||||
ret
|
||||
] DrawLine=
|
||||
|
||||
[def
|
||||
push
|
||||
\frameCount, TimeOut- 128& [if=0
|
||||
Timer [if>0 1- Timer=]
|
||||
DrawTimer!
|
||||
]
|
||||
pop ret
|
||||
] UpdateTimer=
|
||||
|
||||
[def
|
||||
push
|
||||
Head Pos= 63 {White} Color= DrawBlock!
|
||||
pop ret
|
||||
] DrawHead=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 3 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0300:
|
||||
|
||||
[def
|
||||
{-
|
||||
Game over
|
||||
-}
|
||||
push
|
||||
$4435 Pos=
|
||||
4 BgColor=
|
||||
[def
|
||||
$47# $41# $4d# $45# $20# $4f# $56# $45# $52# 0# {GAME OVER}
|
||||
] PrintText!
|
||||
|
||||
PlayGameOverSound!
|
||||
|
||||
Score HighScore- [if>0
|
||||
Score HighScore=
|
||||
30 Color= DrawHighScore!
|
||||
]
|
||||
pop ret
|
||||
] GameOver=
|
||||
|
||||
[def {Wait -- Wait Delay number of frames (range 1..255)}
|
||||
tmp= \frameCount, tmp+ 255& tmp=
|
||||
[do \frameCount, tmp- if<>0loop]
|
||||
ret
|
||||
] Wait=
|
||||
|
||||
[def
|
||||
{-
|
||||
Intro
|
||||
-}
|
||||
push
|
||||
|
||||
{Display welcome tekst}
|
||||
8 {Green} Color=
|
||||
0 BgColor=
|
||||
$800 ClearScreen!
|
||||
$838 Pos= Title PrintText!
|
||||
60 Wait!
|
||||
|
||||
pop ret
|
||||
] Intro=
|
||||
|
||||
[def {ClearScreen -- Clear screen from current position to bottom right}
|
||||
Pos= p=
|
||||
Pos 255| 255^ {Clear low byte}
|
||||
i= $8001 i+ i= {Offset to move to next stripe}
|
||||
[do
|
||||
{Clear one stripe}
|
||||
p [do BgColor p. $100 p+ p= if>=0loop]
|
||||
{Next stripe}
|
||||
i+ p=
|
||||
255& 160^ if<>0loop]
|
||||
ret
|
||||
] ClearScreen=
|
||||
|
||||
[def
|
||||
0 stepV- tmp=
|
||||
stepU stepV=
|
||||
tmp stepU=
|
||||
ret
|
||||
] TurnL=
|
||||
|
||||
[def
|
||||
0 stepU- tmp=
|
||||
stepV stepU=
|
||||
tmp stepV=
|
||||
ret
|
||||
] TurnR=
|
||||
|
||||
[def
|
||||
Pos p=
|
||||
Color Pos.
|
||||
Pos<++ Pos.
|
||||
Pos>++ Pos.
|
||||
p>++ p.
|
||||
ret
|
||||
] DrawBlock=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 4 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0400:
|
||||
|
||||
[def
|
||||
{-
|
||||
RunGame --
|
||||
-}
|
||||
push
|
||||
|
||||
[do
|
||||
{Control is one of LaunchControl, PlayerControl or AutoControl}
|
||||
Control!
|
||||
|
||||
{Leave a trace behind in the pixels two high bits}
|
||||
{Bit 15 and bit 0 of stepU identify the direction}
|
||||
stepU>, 128& tmp=
|
||||
stepU 1& [if<>0 64] tmp+
|
||||
|
||||
30+ {Cyan} Color= Head Pos= DrawBlock! {Tail color and trace}
|
||||
|
||||
{Make step}
|
||||
Head stepU+ stepU+ Head=
|
||||
|
||||
Head, $33& [if<>0 {Hit wall or poison} pop ret]
|
||||
Head, 8^ {Food?} [if=0
|
||||
{Eat food}
|
||||
$40 Timer+ SetTone!
|
||||
2 \soundTimer.
|
||||
Score Timer+ Score=
|
||||
DrawScore!
|
||||
5 AddTimer!
|
||||
Grow<++ Drops<++
|
||||
]
|
||||
DrawHead!
|
||||
|
||||
{Update tail}
|
||||
Grow [if>0
|
||||
1- Grow= {Do nothing while growing}
|
||||
AddFood!
|
||||
else
|
||||
{Tail is following the head}
|
||||
Tail, tmp=
|
||||
Drops [if>0 1- Drops= 11 {Orange} else 4] Color=
|
||||
Tail Pos= DrawBlock!
|
||||
|
||||
tmp 64& [if=0 $0100 else $0001] x=
|
||||
tmp 128& [if=0 x else 0 x-]
|
||||
1<< Tail+ Tail=
|
||||
]
|
||||
|
||||
UpdateTimer!
|
||||
|
||||
2 Wait! {Fixed game speed}
|
||||
loop]
|
||||
] RunGame=
|
||||
|
||||
[def
|
||||
push
|
||||
8 {Green} Color=
|
||||
[do
|
||||
\SYS_Random_34 \sysFn: 34!! Pos=
|
||||
Pos<, 128- [if<0 157+] 1+ {1..157} $fe& Pos<.
|
||||
Pos>, 127& 64- [if<0 109+] $11+ {$11..$fd} $fe& Pos>.
|
||||
Pos, 4^ if<>0loop]
|
||||
DrawBlock!
|
||||
pop ret
|
||||
] AddFood=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 5 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0500:
|
||||
|
||||
[def
|
||||
push
|
||||
{If a key is pressed, start restart the game}
|
||||
\serialRaw, $cf& {~buttonStart&~buttonSelect} $cf^ [if<>0 SetupGame! pop ret]
|
||||
|
||||
{Auto snake control}
|
||||
TurnL p=
|
||||
TurnR q=
|
||||
{Look ahead} Head stepU+ stepU+ peek 4^ tmp=
|
||||
{Look left} Head stepV- stepV- peek 4^ [if<>0 {8^4}12^ [if<>0 0 p= else 0 q= 1 tmp=]]
|
||||
{Look right} Head stepV+ stepV+ peek 4^ [if<>0 {8^4}12^ [if<>0 0 q= else 0 p= 1 tmp=]]
|
||||
tmp [if=0 \entropy, $7f& 6- [if<0 1 else 0]]
|
||||
[if<>0 {8^4}12^ if<>0
|
||||
{Wall or random direction change: must go left or right.
|
||||
Pick randomly, without bias, but don't crash into a wall when not needed}
|
||||
p [if=0 q else
|
||||
q [if=0 p else
|
||||
\entropy, 1& [if=0 p else q]
|
||||
]
|
||||
]
|
||||
[if<>0 call {TurnL or TurnR}]
|
||||
]
|
||||
pop ret
|
||||
] AutoControl=
|
||||
|
||||
[def
|
||||
stepU tmp= {Default keep running in same direction}
|
||||
\serialRaw, $fe^ {~buttonRight} [if=0 $0001 tmp=]
|
||||
\serialRaw, $fd^ {~buttonLeft} [if=0 $ffff tmp=]
|
||||
\serialRaw, $fb^ {~buttonDown} [if=0 $0100 tmp=]
|
||||
\serialRaw, $f7^ {~buttonUp} [if=0 $ff00 tmp=]
|
||||
{Only turn if not reversing 180 degrees}
|
||||
tmp stepU+ [if<>0 tmp stepU=]
|
||||
{Or if there is no tail yet in the beginning of the game}
|
||||
Tail Head- [if=0 tmp stepU=]
|
||||
{Note: `stepV' is not used once under player control}
|
||||
ret
|
||||
] PlayerControl=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 6 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0600:
|
||||
|
||||
[def {AddTimer}
|
||||
push
|
||||
Timer+ Timer=
|
||||
15- [if>0 15 Timer=]
|
||||
\frameCount, TimeOut=
|
||||
DrawTimer!
|
||||
pop ret
|
||||
] AddTimer=
|
||||
|
||||
[def {SetupGame}
|
||||
push
|
||||
|
||||
{Reset score}
|
||||
0 Score= Timer= DrawScore!
|
||||
15 Timer= DrawTimer!
|
||||
DrawHighScore!
|
||||
|
||||
{ClearScreen}
|
||||
4 BgColor=
|
||||
$1000 ClearScreen!
|
||||
|
||||
{Draw bounding box}
|
||||
26 Color=
|
||||
+1 Step= 159 Count= DrawLine!
|
||||
$100 Step= 111 Count= DrawLine!
|
||||
-1 Step= 159 Count= DrawLine!
|
||||
-$100 Step= 110 Count= DrawLine!
|
||||
+1 Step= 158 Count= DrawLine!
|
||||
$100 Step= 109 Count= DrawLine!
|
||||
-1 Step= 157 Count= DrawLine!
|
||||
-$100 Step= 109 Count= DrawLine!
|
||||
|
||||
{Get ready message}
|
||||
$4432 Pos= 3 {Red} Color=
|
||||
[def
|
||||
$47# $45# $54# $20# $52# $45# $41# $44# $59# $21# 0# {GET READY!}
|
||||
] PrintText!
|
||||
60 Wait!
|
||||
$4432 Pos=
|
||||
[def
|
||||
$20# $20# $20# $20# $20# $20# $20# $20# $20# $20# 0#
|
||||
] PrintText!
|
||||
|
||||
{Place snake}
|
||||
$4430 Head= Tail=
|
||||
DrawHead!
|
||||
|
||||
0 Grow= Drops=
|
||||
Timer= 15 AddTimer!
|
||||
$0001 stepU= $0100 stepV= {Start right}
|
||||
|
||||
{Place 25 foods}
|
||||
25 [do i= AddFood! i 1- if>0loop]
|
||||
|
||||
LaunchControl Control=
|
||||
|
||||
pop ret
|
||||
] SetupGame=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}$08a0 \vLR: ret{ RAM page 8 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$08a0:
|
||||
|
||||
[def {LaunchControl}
|
||||
{-
|
||||
XXX better strategy: run both PlayerControl and AutoControl.
|
||||
The first one to take control will take over the game...
|
||||
-}
|
||||
push
|
||||
$449c Head- [if=0
|
||||
{Switch to autopilot when reaching this position}
|
||||
30 {XXX} Color=
|
||||
$0802 Pos=
|
||||
[def $41# $55# $54# $4f# 0#{AUTO}] PrintText!
|
||||
AutoControl Control= call
|
||||
else
|
||||
{Disable launch control once a button is pressed}
|
||||
\serialRaw, $cf& {~buttonStart|~buttonSelect} $cf^ [if<>0 PlayerControl Control= call]
|
||||
]
|
||||
pop ret
|
||||
] LaunchControl=
|
||||
|
||||
[def { DrawNumber2 - Value Radix }
|
||||
push
|
||||
$20 Char=
|
||||
10 Radix= DrawNextDigit!
|
||||
$30 Char=
|
||||
1 Radix= DrawNextDigit!
|
||||
pop ret
|
||||
] DrawNumber2=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 9 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$09a0:
|
||||
|
||||
[def { DrawNextDigit -- Value Radix }
|
||||
push
|
||||
Value Radix- [if>=0
|
||||
Value=
|
||||
$31 Char=
|
||||
Value [do
|
||||
Radix-
|
||||
if>=0
|
||||
Value=
|
||||
Char<++
|
||||
loop
|
||||
]
|
||||
PrintChar!
|
||||
$30 Char=
|
||||
else
|
||||
PrintChar!
|
||||
]
|
||||
pop ret
|
||||
] DrawNextDigit=
|
||||
|
||||
[def { DrawNumber4 - Value Radix }
|
||||
push
|
||||
$20 Char=
|
||||
1000 Radix= DrawNextDigit!
|
||||
100 Radix= DrawNextDigit!
|
||||
10 Radix= DrawNextDigit!
|
||||
$30 Char=
|
||||
1 Radix= DrawNextDigit!
|
||||
pop ret
|
||||
] DrawNumber4=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 10 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0aa0:
|
||||
|
||||
[def
|
||||
push
|
||||
$802 Pos=
|
||||
Score HighScore- [if>0 30 else 8] Color=
|
||||
0 BgColor=
|
||||
Score Value= DrawNumber4!
|
||||
pop ret
|
||||
] DrawScore=
|
||||
|
||||
[def
|
||||
push
|
||||
$820 Pos=
|
||||
8 Color=
|
||||
0 BgColor=
|
||||
Timer Value= DrawNumber2!
|
||||
TimeOut 60+ 255& TimeOut=
|
||||
pop ret
|
||||
] DrawTimer=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 11 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0ba0:
|
||||
|
||||
[def
|
||||
push
|
||||
$874 Pos= 0 BgColor=
|
||||
[def $48# $49# $20# 0# {HI }] PrintText!
|
||||
HighScore Value= DrawNumber4!
|
||||
pop ret
|
||||
] DrawHighScore=
|
||||
|
||||
[def {SetupChannel}
|
||||
i= 255| 255^ $fa| p= {Pointer to channel struct}
|
||||
i<, i= {Extract note}
|
||||
0 p. p<++ {.wavA}
|
||||
1 p. p<++ {.wavX: 0 "Noise", 1 Triangle, 2 Pulse, 3 Sawtooth}
|
||||
\notesTable i+ 0? p. p<++ {.keyL}
|
||||
\notesTable i+ 1? p. p<++ {.keyH}
|
||||
ret
|
||||
] SetupChannel=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 12 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0ca0:
|
||||
|
||||
{ Setup a G-major chord with 4 channels but don't play it yet }
|
||||
[def {SetTone}
|
||||
push
|
||||
1<< tmp=
|
||||
$100 tmp| {Channel 1} SetupChannel!
|
||||
$200 tmp| {Channel 2} SetupChannel!
|
||||
$300 tmp| {Channel 3} SetupChannel!
|
||||
$400 tmp| {Channel 4} SetupChannel!
|
||||
pop ret
|
||||
] SetTone=
|
||||
|
||||
[def
|
||||
push
|
||||
$49 j= [do
|
||||
j SetTone!
|
||||
5 \soundTimer.
|
||||
[do \soundTimer, if<>0loop]
|
||||
j 1- j= $30^ if<>0loop]
|
||||
pop ret
|
||||
] PlayGameOverSound=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 13 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0da0:
|
||||
|
||||
{--- Run ---}
|
||||
|
||||
Intro!
|
||||
|
||||
$49 SetTone!
|
||||
|
||||
[do
|
||||
SetupGame!
|
||||
RunGame!
|
||||
|
||||
120 \soundTimer.
|
||||
3 {Bright Red} Color= Head Pos= DrawBlock!
|
||||
GameOver!
|
||||
240 Wait!
|
||||
|
||||
loop
|
||||
]
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| End |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,529 @@
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| |
|
||||
| Snake game |
|
||||
| |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
gcl0x
|
||||
|
||||
{
|
||||
Maybe:
|
||||
XXX Don't allow autoplayer to obtain a hi score
|
||||
XXX Use DOKE to plot fat pixels
|
||||
XXX More colors, less green
|
||||
XXX Smarter border drawing (spiral draw)
|
||||
XXX Use same drawing techique for clearing playfield
|
||||
XXX Increasing speed
|
||||
XXX Increase speed when pressing button
|
||||
}
|
||||
|
||||
{-
|
||||
First setup all subroutine definitions and variables, without making
|
||||
calls. This way allows use of vLR to hop from page to page during setup,
|
||||
with minimal overhead. At the end, run the main loop.
|
||||
-}
|
||||
|
||||
0 HighScore=
|
||||
|
||||
{ Print a 5x8 character on screen with the built-in font
|
||||
Char must be in the 32-127 range (this is not checked) }
|
||||
[def {PrintChar}
|
||||
{Map ASCII code to offset in font table}
|
||||
Char 82- [if<0 50+ i= \font32up
|
||||
else i= \font82up] fontData= {Select low or high page}
|
||||
i 2<< i+ {Multiply by 5}
|
||||
fontData+ fontData= {Add to page address to reach bitmap data for Char}
|
||||
|
||||
{Draw 5 vertical slices: 5 using font data}
|
||||
BgColor \sysArgs0.
|
||||
Color \sysArgs1.
|
||||
Pos \sysArgs4:
|
||||
6+ Pos=
|
||||
\SYS_VDrawBits_134 \sysFn:
|
||||
$fb i= [do
|
||||
fontData 0? fontData<++ \sysArgs2. 134!!
|
||||
\sysArgs4<++
|
||||
i<++ i if<>0loop]
|
||||
ret
|
||||
] PrintChar=
|
||||
|
||||
[def {PrintText}
|
||||
push
|
||||
Text=
|
||||
[do
|
||||
Text, Char= {Next character to be printed}
|
||||
if<>0 {Zero termination}
|
||||
Text<++ {Advance text pointer}
|
||||
Char 10^ [if=0 Pos<. $800 Pos+ Pos=
|
||||
else PrintChar!]
|
||||
loop]
|
||||
pop ret
|
||||
] PrintText=
|
||||
|
||||
[def
|
||||
$47# $69# $67# $61# $74# $72# $6f# $6e# 0# {Gigatron}
|
||||
] Title=
|
||||
|
||||
[def
|
||||
{-
|
||||
DrawLine -- Draw line
|
||||
-}
|
||||
Count i=
|
||||
[do if>0
|
||||
Color Pos.
|
||||
Pos Step+ Pos=
|
||||
i 1- i=
|
||||
loop]
|
||||
ret
|
||||
] DrawLine=
|
||||
|
||||
[def
|
||||
push
|
||||
\frameCount, TimeOut- 128& [if=0
|
||||
Timer [if>0 1- Timer=]
|
||||
DrawTimer!
|
||||
]
|
||||
pop ret
|
||||
] UpdateTimer=
|
||||
|
||||
[def
|
||||
push
|
||||
Head Pos= 63 {White} Color= DrawBlock!
|
||||
pop ret
|
||||
] DrawHead=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 3 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0300:
|
||||
|
||||
[def
|
||||
{-
|
||||
Game over
|
||||
-}
|
||||
push
|
||||
$4435 Pos=
|
||||
4 BgColor=
|
||||
[def
|
||||
$47# $41# $4d# $45# $20# $4f# $56# $45# $52# 0# {GAME OVER}
|
||||
] PrintText!
|
||||
|
||||
Score HighScore- [if>0
|
||||
Score HighScore=
|
||||
30 Color= DrawHighScore!
|
||||
]
|
||||
|
||||
PlayGameOverSound!
|
||||
|
||||
pop ret
|
||||
] GameOver=
|
||||
|
||||
[def {Wait -- Wait Delay number of frames (range 1..255)}
|
||||
tmp= \frameCount, tmp+ 255& tmp=
|
||||
[do \frameCount, tmp- if<>0loop]
|
||||
ret
|
||||
] Wait=
|
||||
|
||||
[def
|
||||
{-
|
||||
Intro
|
||||
-}
|
||||
push
|
||||
|
||||
{Display welcome tekst}
|
||||
8 {Green} Color=
|
||||
0 BgColor=
|
||||
$800 ClearScreen!
|
||||
$838 Pos= Title PrintText!
|
||||
|
||||
pop ret
|
||||
] Intro=
|
||||
|
||||
[def {ClearScreen -- Clear screen from current position to bottom right}
|
||||
Pos= p=
|
||||
Pos 255| 255^ {Clear low byte}
|
||||
i= $8001 i+ i= {Offset to move to next stripe}
|
||||
BgColor \sysArgs0. \sysArgs1.
|
||||
\SYS_VDrawBits_134 \sysFn:
|
||||
[do
|
||||
{Clear one stripe}
|
||||
p [do
|
||||
\sysArgs4: 134!! {Clears 8 pixels vertically}
|
||||
$800 p+ p= if>0loop]
|
||||
{Next stripe}
|
||||
i+ p=
|
||||
255& 160^ if<>0loop]
|
||||
ret
|
||||
] ClearScreen=
|
||||
|
||||
[def
|
||||
0 stepV- tmp=
|
||||
stepU stepV=
|
||||
tmp stepU=
|
||||
ret
|
||||
] TurnL=
|
||||
|
||||
[def
|
||||
0 stepU- tmp=
|
||||
stepV stepU=
|
||||
tmp stepV=
|
||||
ret
|
||||
] TurnR=
|
||||
|
||||
[def
|
||||
Pos p=
|
||||
Color Pos.
|
||||
Pos<++ Pos.
|
||||
Pos>++ Pos.
|
||||
p>++ p.
|
||||
ret
|
||||
] DrawBlock=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 4 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0400:
|
||||
|
||||
[def
|
||||
{-
|
||||
RunGame --
|
||||
-}
|
||||
push
|
||||
|
||||
[do
|
||||
{Control is one of LaunchControl, PlayerControl or AutoControl}
|
||||
Control!
|
||||
|
||||
{Leave a trace behind in the pixels two high bits}
|
||||
{Bit 15 and bit 0 of stepU identify the direction}
|
||||
stepU>, 128& tmp=
|
||||
stepU 1& [if<>0 64] tmp+
|
||||
|
||||
30+ {Cyan} Color= Head Pos= DrawBlock! {Tail color and trace}
|
||||
|
||||
{Make step}
|
||||
Head stepU+ stepU+ Head=
|
||||
|
||||
Head, $33& [if<>0 {Hit wall or poison} pop ret]
|
||||
Head, 8^ {Food?} [if=0
|
||||
{Eat food}
|
||||
$40 Timer+ SetTone!
|
||||
2 \soundTimer.
|
||||
Score Timer+ Score=
|
||||
DrawScore!
|
||||
5 AddTimer!
|
||||
Grow<++ Drops<++
|
||||
]
|
||||
DrawHead!
|
||||
|
||||
{Update tail}
|
||||
Grow [if>0
|
||||
1- Grow= {Do nothing while growing}
|
||||
AddFood!
|
||||
else
|
||||
{Tail is following the head}
|
||||
Tail, tmp=
|
||||
Drops [if>0 1- Drops= 63 {White} else 4] Color=
|
||||
Tail Pos= DrawBlock!
|
||||
|
||||
tmp 64& [if=0 $0100 else $0001] x=
|
||||
tmp 128& [if=0 x else 0 x-]
|
||||
1<< Tail+ Tail=
|
||||
]
|
||||
|
||||
UpdateTimer!
|
||||
|
||||
2 Wait! {Fixed game speed}
|
||||
loop]
|
||||
] RunGame=
|
||||
|
||||
[def
|
||||
push
|
||||
8 {Green} Color=
|
||||
[do
|
||||
\SYS_Random_34 \sysFn: 34!! Pos=
|
||||
Pos<, 128- [if<0 157+] 1+ {1..157} $fe& Pos<.
|
||||
Pos>, 127& 64- [if<0 109+] $11+ {$11..$fd} $fe& Pos>.
|
||||
Pos, 4^ if<>0loop]
|
||||
DrawBlock!
|
||||
pop ret
|
||||
] AddFood=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 5 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0500:
|
||||
|
||||
[def
|
||||
push
|
||||
{If a key is pressed, start restart the game}
|
||||
\serialRaw, $cf& {~buttonStart&~buttonSelect} $cf^ [if<>0 SetupGame! pop ret]
|
||||
|
||||
{Auto snake control}
|
||||
TurnL p=
|
||||
TurnR q=
|
||||
{Look ahead} Head stepU+ stepU+ peek 4^ tmp=
|
||||
{Look left} Head stepV- stepV- peek 4^ [if<>0 {8^4}12^ [if<>0 0 p= else 0 q= 1 tmp=]]
|
||||
{Look right} Head stepV+ stepV+ peek 4^ [if<>0 {8^4}12^ [if<>0 0 q= else 0 p= 1 tmp=]]
|
||||
tmp [if=0 \entropy, $7f& 6- [if<0 1 else 0]]
|
||||
[if<>0 {8^4}12^ if<>0
|
||||
{Wall or random direction change: must go left or right.
|
||||
Pick randomly, without bias, but don't crash into a wall when not needed}
|
||||
p [if=0 q else
|
||||
q [if=0 p else
|
||||
\entropy, 1& [if=0 p else q]
|
||||
]
|
||||
]
|
||||
[if<>0 call {TurnL or TurnR}]
|
||||
]
|
||||
pop ret
|
||||
] AutoControl=
|
||||
|
||||
[def
|
||||
stepU tmp= {Default keep running in same direction}
|
||||
\serialRaw, $fe^ {~buttonRight} [if=0 $0001 tmp=]
|
||||
\serialRaw, $fd^ {~buttonLeft} [if=0 $ffff tmp=]
|
||||
\serialRaw, $fb^ {~buttonDown} [if=0 $0100 tmp=]
|
||||
\serialRaw, $f7^ {~buttonUp} [if=0 $ff00 tmp=]
|
||||
{Only turn if not reversing 180 degrees}
|
||||
tmp stepU+ [if<>0 tmp stepU=]
|
||||
{Or if there is no tail yet in the beginning of the game}
|
||||
Tail Head- [if=0 tmp stepU=]
|
||||
{Note: `stepV' is not used once under player control}
|
||||
ret
|
||||
] PlayerControl=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 6 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0600:
|
||||
|
||||
[def {AddTimer}
|
||||
push
|
||||
Timer+ Timer=
|
||||
15- [if>0 15 Timer=]
|
||||
\frameCount, TimeOut=
|
||||
DrawTimer!
|
||||
pop ret
|
||||
] AddTimer=
|
||||
|
||||
[def {SetupGame}
|
||||
push
|
||||
|
||||
{Reset score}
|
||||
0 Score= Timer= DrawScore!
|
||||
15 Timer= DrawTimer!
|
||||
DrawHighScore!
|
||||
|
||||
{ClearScreen}
|
||||
4 BgColor=
|
||||
$1000 ClearScreen!
|
||||
|
||||
{Draw bounding box}
|
||||
26 Color=
|
||||
+1 Step= 159 Count= DrawLine!
|
||||
$100 Step= 111 Count= DrawLine!
|
||||
-1 Step= 159 Count= DrawLine!
|
||||
-$100 Step= 110 Count= DrawLine!
|
||||
+1 Step= 158 Count= DrawLine!
|
||||
$100 Step= 109 Count= DrawLine!
|
||||
-1 Step= 157 Count= DrawLine!
|
||||
-$100 Step= 109 Count= DrawLine!
|
||||
|
||||
{Get ready message}
|
||||
$4432 Pos= 3 {Red} Color=
|
||||
[def
|
||||
$47# $45# $54# $20# $52# $45# $41# $44# $59# $21# 0# {GET READY!}
|
||||
] PrintText!
|
||||
60 Wait!
|
||||
$4432 Pos=
|
||||
[def
|
||||
$20# $20# $20# $20# $20# $20# $20# $20# $20# $20# 0#
|
||||
] PrintText!
|
||||
|
||||
{Place snake}
|
||||
$4430 Head= Tail=
|
||||
DrawHead!
|
||||
|
||||
0 Grow= Drops=
|
||||
Timer= 15 AddTimer!
|
||||
$0001 stepU= $0100 stepV= {Start right}
|
||||
|
||||
{Place 25 foods}
|
||||
25 [do i= AddFood! i 1- if>0loop]
|
||||
|
||||
LaunchControl Control=
|
||||
|
||||
pop ret
|
||||
] SetupGame=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}$08a0 \vLR: ret{ RAM page 8 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$08a0:
|
||||
|
||||
[def {LaunchControl}
|
||||
{-
|
||||
XXX better strategy: run both PlayerControl and AutoControl.
|
||||
The first one to take control will take over the game...
|
||||
-}
|
||||
push
|
||||
$449c Head- [if=0
|
||||
{Switch to autopilot when reaching this position}
|
||||
30 {XXX} Color=
|
||||
$0802 Pos=
|
||||
[def $41# $55# $54# $4f# 0#{AUTO}] PrintText!
|
||||
AutoControl Control= call
|
||||
else
|
||||
{Disable launch control once a button is pressed}
|
||||
\serialRaw, $cf& {~buttonStart|~buttonSelect} $cf^ [if<>0 PlayerControl Control= call]
|
||||
]
|
||||
pop ret
|
||||
] LaunchControl=
|
||||
|
||||
[def { DrawNumber2 - Value Radix }
|
||||
push
|
||||
$20 Char=
|
||||
10 Radix= DrawNextDigit!
|
||||
$30 Char=
|
||||
1 Radix= DrawNextDigit!
|
||||
pop ret
|
||||
] DrawNumber2=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 9 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$09a0:
|
||||
|
||||
[def { DrawNextDigit -- Value Radix }
|
||||
push
|
||||
Value Radix- [if>=0
|
||||
Value=
|
||||
$31 Char=
|
||||
Value [do
|
||||
Radix-
|
||||
if>=0
|
||||
Value=
|
||||
Char<++
|
||||
loop
|
||||
]
|
||||
PrintChar!
|
||||
$30 Char=
|
||||
else
|
||||
PrintChar!
|
||||
]
|
||||
pop ret
|
||||
] DrawNextDigit=
|
||||
|
||||
[def { DrawNumber4 - Value Radix }
|
||||
push
|
||||
$20 Char=
|
||||
1000 Radix= DrawNextDigit!
|
||||
100 Radix= DrawNextDigit!
|
||||
10 Radix= DrawNextDigit!
|
||||
$30 Char=
|
||||
1 Radix= DrawNextDigit!
|
||||
pop ret
|
||||
] DrawNumber4=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 10 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0aa0:
|
||||
|
||||
[def
|
||||
push
|
||||
$802 Pos=
|
||||
Score HighScore- [if>0 30 else 8] Color=
|
||||
0 BgColor=
|
||||
Score Value= DrawNumber4!
|
||||
pop ret
|
||||
] DrawScore=
|
||||
|
||||
[def
|
||||
push
|
||||
$820 Pos=
|
||||
8 Color=
|
||||
0 BgColor=
|
||||
Timer Value= DrawNumber2!
|
||||
TimeOut 60+ 255& TimeOut=
|
||||
pop ret
|
||||
] DrawTimer=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 11 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0ba0:
|
||||
|
||||
[def
|
||||
push
|
||||
$874 Pos= 0 BgColor=
|
||||
[def $48# $49# $20# 0# {HI }] PrintText!
|
||||
HighScore Value= DrawNumber4!
|
||||
pop ret
|
||||
] DrawHighScore=
|
||||
|
||||
[def {SetupChannel}
|
||||
i= 255| 255^ $fa| p= {Pointer to channel struct}
|
||||
i<, i= {Extract note}
|
||||
0 p. p<++ {.wavA}
|
||||
1 p. p<++ {.wavX: 0 "Noise", 1 Triangle, 2 Pulse, 3 Sawtooth}
|
||||
\notesTable i+ 0? p. p<++ {.keyL}
|
||||
\notesTable i+ 1? p. p<++ {.keyH}
|
||||
ret
|
||||
] SetupChannel=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 12 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0ca0:
|
||||
|
||||
{ Setup a G-major chord with 4 channels but don't play it yet }
|
||||
[def {SetTone}
|
||||
push
|
||||
1<< tmp=
|
||||
$100 tmp| {Channel 1} SetupChannel!
|
||||
$200 tmp| {Channel 2} SetupChannel!
|
||||
$300 tmp| {Channel 3} SetupChannel!
|
||||
$400 tmp| {Channel 4} SetupChannel!
|
||||
pop ret
|
||||
] SetTone=
|
||||
|
||||
[def
|
||||
push
|
||||
$49 j= [do
|
||||
j SetTone!
|
||||
5 \soundTimer.
|
||||
[do \soundTimer, if<>0loop]
|
||||
j 1- j= $30^ if<>0loop]
|
||||
pop ret
|
||||
] PlayGameOverSound=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}\vLR>++ ret{ RAM page 13 |
|
||||
+-----------------------------------------------------------------------}
|
||||
$0da0:
|
||||
|
||||
{--- Run ---}
|
||||
|
||||
Intro!
|
||||
|
||||
$49 SetTone!
|
||||
|
||||
[do
|
||||
SetupGame!
|
||||
RunGame!
|
||||
|
||||
120 \soundTimer.
|
||||
3 {Bright Red} Color= Head Pos= DrawBlock!
|
||||
GameOver!
|
||||
60 Wait!
|
||||
|
||||
loop
|
||||
]
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| End |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,605 @@
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| |
|
||||
| Snake game |
|
||||
| |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
gcl0x
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| ROM type check >= v2 |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
\romType, \romTypeValue_ROMv2-
|
||||
[if<0 do _frameCount _vPCH: loop]
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| Setup |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
{
|
||||
First setup all subroutine definitions and variables, without making
|
||||
calls. This way allows use of vLR to hop from page to page during setup,
|
||||
with minimal overhead. At the end, run the main loop.
|
||||
}
|
||||
|
||||
0 HighScore=
|
||||
|
||||
{
|
||||
Print a 5x8 character on screen with the built-in font
|
||||
Char must be in the 32-127 range (this is not checked)
|
||||
}
|
||||
[def {PrintChar}
|
||||
{Map ASCII code to offset in font table}
|
||||
Char 82- [if<0 50+ i= \font32up
|
||||
else i= \font82up] fontData= {Select low or high page}
|
||||
i 2<< i+ {Multiply by 5}
|
||||
fontData+ fontData= {Add to page address to reach bitmap data for Char}
|
||||
|
||||
{Draw 5 vertical slices: 5 using font data}
|
||||
BgColor \sysArgs0.
|
||||
Color \sysArgs1.
|
||||
Pos \sysArgs4:
|
||||
6+ Pos=
|
||||
\SYS_VDrawBits_134 \sysFn:
|
||||
$fb i= [do
|
||||
fontData 0? <fontData++ \sysArgs2. 134!!
|
||||
<\sysArgs4++
|
||||
<i++ i if<>0loop]
|
||||
ret
|
||||
] PrintChar=
|
||||
|
||||
{ PrintText }
|
||||
[def
|
||||
push
|
||||
Text=
|
||||
[do
|
||||
Text, Char= {Next character to be printed}
|
||||
<Text++ {Advance text pointer}
|
||||
if<>0 {Zero termination}
|
||||
PrintChar!
|
||||
loop]
|
||||
pop ret
|
||||
] PrintText=
|
||||
|
||||
{ DrawLine }
|
||||
[def
|
||||
[do if>0
|
||||
i=
|
||||
Color Pos.
|
||||
Pos Step+ Pos=
|
||||
i 1-
|
||||
loop]
|
||||
ret
|
||||
] DrawLine=
|
||||
|
||||
{ Delay until next game cycle }
|
||||
[def
|
||||
push
|
||||
|
||||
{Update count down timer}
|
||||
\frameCount, TimeOut- 128& [if=0
|
||||
Timer [if>0 1- Timer=]
|
||||
DrawTimer!
|
||||
]
|
||||
|
||||
{Game delay, but accelerate with [A] button or any ASCII key from keyboard}
|
||||
\buttonState, \buttonA& [if=0 1- else 0] Delay+ Wait!
|
||||
|
||||
pop ret
|
||||
] TimeStep=
|
||||
|
||||
{ Draw count down timer }
|
||||
[def
|
||||
push
|
||||
$820 Pos=
|
||||
8 Color=
|
||||
0 BgColor=
|
||||
Timer Value= DrawNumber2!
|
||||
TimeOut 60+ 255& TimeOut=
|
||||
pop ret
|
||||
] DrawTimer=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 3 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$300
|
||||
|
||||
{ Draw snake head }
|
||||
[def
|
||||
push
|
||||
15 {Yellow head} Color= Head DrawBlock!
|
||||
pop ret
|
||||
] DrawHead=
|
||||
|
||||
{ Game over }
|
||||
[def
|
||||
push
|
||||
$4435 Pos=
|
||||
4 BgColor=
|
||||
[def `GAME`OVER #0] PrintText!
|
||||
|
||||
Score HighScore- [if>0 {Improved high score?}
|
||||
Control PlayerControl^ if=0 {Only accept human scores}
|
||||
Score HighScore= {Update high score}
|
||||
30 Color= DrawHighScore! {Highlight it}
|
||||
]
|
||||
|
||||
PlayGameOverSound!
|
||||
|
||||
pop ret
|
||||
] GameOver=
|
||||
|
||||
{Wait number of frames (range 1..255)}
|
||||
[def
|
||||
tmp= \frameCount, tmp+ 255& tmp=
|
||||
[do \frameCount, tmp- if<>0loop]
|
||||
ret
|
||||
] Wait=
|
||||
|
||||
{ Intro }
|
||||
[def
|
||||
push
|
||||
|
||||
{Display welcome tekst}
|
||||
8 {Green} Color=
|
||||
0 BgColor=
|
||||
$800 ClearScreen!
|
||||
$838 Pos=
|
||||
[def `Gigatron #0] PrintText!
|
||||
|
||||
pop ret
|
||||
] Intro=
|
||||
|
||||
{ Clear screen from current position to bottom right }
|
||||
[def
|
||||
p=
|
||||
\SYS_SetMemory_v2_54 \sysFn: {Not in ROM v1}
|
||||
BgColor \sysArgs1. {Color}
|
||||
p [do
|
||||
\sysArgs2: {Destination}
|
||||
160 \sysArgs0. {Byte count}
|
||||
54!! {Make SYS call}
|
||||
$100 p+ p= if>0loop] {To next line}
|
||||
ret
|
||||
] ClearScreen=
|
||||
|
||||
{ Turn left }
|
||||
[def
|
||||
0 stepV- tmp=
|
||||
stepU stepV=
|
||||
tmp stepU=
|
||||
Bias [if<0 0] 60+ Bias= {Increase bias against left}
|
||||
ret
|
||||
] TurnL=
|
||||
|
||||
{ Turn right }
|
||||
[def
|
||||
0 stepU- tmp=
|
||||
stepV stepU=
|
||||
tmp stepV=
|
||||
Bias [if>0 0] 60- Bias= {Increase bias against right}
|
||||
ret
|
||||
] TurnR=
|
||||
|
||||
{ Draw 2x2 pixel block in single color }
|
||||
[def
|
||||
Pos=
|
||||
Color \vACH. {Duplicate Color low byte to high byte}
|
||||
Pos: >Pos++ Pos: {Draws 2x2 pixels with DOKE}
|
||||
ret
|
||||
] DrawBlock=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 4 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$400
|
||||
|
||||
{ RunGame }
|
||||
[def
|
||||
push
|
||||
|
||||
[do
|
||||
{Control is one of LaunchControl, PlayerControl or AutoControl}
|
||||
Control!
|
||||
|
||||
{Leave a trace behind in the pixels two high bits}
|
||||
{Bit 15 and bit 1 of stepU identify the direction}
|
||||
>stepU, 128& tmp=
|
||||
stepU 2& [if<>0 64] tmp+
|
||||
|
||||
27+ {Orange tail} Color= {Tail color}
|
||||
>Head, Head^ 2& {Striped tail effect}
|
||||
[if<>0 1] Color^ Color= {Apply effect}
|
||||
Head DrawBlock! {Draws head in tail color}
|
||||
|
||||
Head stepU+ Head= {Make step with head first}
|
||||
|
||||
{ Colors: R G B
|
||||
------- -- -- --
|
||||
Field = 8 = 8
|
||||
Wall = 26 = 2+ 8+16
|
||||
Head = 15 = 3 12
|
||||
Tail1 = 27 = 3+ 8+16
|
||||
Tail2 = 26 = 2+ 8+16
|
||||
Food = 24 = + 8+16
|
||||
Poison = 62 = 2+12+48
|
||||
^
|
||||
Use red channel to detect unsafe steps
|
||||
}
|
||||
Head, 3& [if<>0 pop ret] {Hit wall, tail or poison}
|
||||
Head, 24^ {Food} [if=0 {Eating the food}
|
||||
$40 Timer+ SetNote!
|
||||
2 \soundTimer.
|
||||
Score Timer+ Score= {Add remaining seconds to score}
|
||||
DrawScore!
|
||||
5 AddTimer! {5 seconds bonus}
|
||||
<Grow++ <Drops++
|
||||
]
|
||||
DrawHead!
|
||||
|
||||
{Update tail}
|
||||
Grow [if>0
|
||||
1- Grow= {Do nothing while growing}
|
||||
AddFood!
|
||||
else
|
||||
{Tail is following the head}
|
||||
Tail, tmp=
|
||||
Drops [if>0 1- Drops= 62 {Poison}
|
||||
else 4] {Field}
|
||||
Color= Tail DrawBlock!
|
||||
|
||||
tmp 64& [if=0 $0100 else $0001] x=
|
||||
tmp 128& [if=0 x else 0 x-]
|
||||
1<< Tail+ Tail=
|
||||
]
|
||||
|
||||
TimeStep! {Delay for next game step}
|
||||
|
||||
loop]
|
||||
] RunGame=
|
||||
|
||||
{ Place random food in field }
|
||||
[def
|
||||
push
|
||||
24 {Greenish food} Color=
|
||||
[do
|
||||
\SYS_Random_34 \sysFn:
|
||||
34!! Pos= {Get random 16-bit number}
|
||||
{
|
||||
The ranges are such that 1. no food will touch the wall,
|
||||
and 2. the probability of landing one step away from
|
||||
the wall is half (due to truncation with 254&), and 3.
|
||||
the probability in the center is double (due to partial
|
||||
overlap of the low and high ranges).
|
||||
}
|
||||
<Pos, 128- [if<0 150+] 5+ {X in range 5..154} 254& <Pos.
|
||||
>Pos, 127& 64- [if<0 102+] 21+ {Y in range 21..122} 254& >Pos.
|
||||
|
||||
Pos, 4^ if<>0loop] {Repeat if not free}
|
||||
Pos DrawBlock!
|
||||
pop ret
|
||||
] AddFood=
|
||||
|
||||
0 Bias= {Short-term memory for auto control}
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 5 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$500
|
||||
|
||||
{ AutoControl }
|
||||
[def
|
||||
push
|
||||
|
||||
\buttonState, $cf& $cf^ {Ignore buttonStart and buttonSelect}
|
||||
[if<>0 SetupGame! pop ret] {If other button pressed, restart game}
|
||||
|
||||
TurnL p= {p stays set as long as left turn is ok}
|
||||
TurnR q= {q stays set as long as right turn is ok}
|
||||
|
||||
Head stepU+ peek {Look ahead}
|
||||
4^ tmp= {tmp<>0 for turning, tmp=0 for straight}
|
||||
[if<>0
|
||||
{24^4} 28^ [if=0 tmp=] {Go straight if food ahead}
|
||||
else
|
||||
Head stepU+ stepU+ peek {If clear also look two steps ahead}
|
||||
62^ if=0 >tmp++ {Turn early when heading towards poison}
|
||||
]
|
||||
|
||||
Head stepV- peek 4^ {Look left}
|
||||
[if<>0 {24^4} 28^ {Something is there}
|
||||
[if=0 q= >tmp++ {Food! Must turn but not right}
|
||||
else 0 p=] {Not safe, don't go there}
|
||||
else {Left is clear}
|
||||
Head stepV- stepV- peek 4^ {Look two steps left}
|
||||
if<>0 {24^4} 28^
|
||||
[if=0 q= >tmp++ {Also turn for food two steps away}
|
||||
else Bias 15+ Bias] {Build up some extra bias for right}
|
||||
]
|
||||
|
||||
Head stepV+ peek 4^ {Look right}
|
||||
[if<>0 {24^4} 28^ {Something is there}
|
||||
[if=0 p= >tmp++ {Food! Must turn but not right}
|
||||
else 0 q=] {Not safe, don't go there}
|
||||
else {Right is clear}
|
||||
Head stepV+ stepV+ peek 4^ {Look two steps right}
|
||||
if<>0 {24^4} 28^
|
||||
[if=0 p= >tmp++ {Also turn for food two steps away}
|
||||
else Bias 15- Bias] {Build up some extra bias for left}
|
||||
]
|
||||
|
||||
tmp [if=0 {If not already turning}
|
||||
\entropy, 13- {Turn randomly 13 out of 128, or 5%}
|
||||
[if<0 1 else 0]]
|
||||
|
||||
[if<>0 {Algorithm wants to turn}
|
||||
p [if=0 q else {Not left means right}
|
||||
q [if=0 p else {Not right means left}
|
||||
\entropy, 128- {Pick direction randomly otherwise}
|
||||
Bias+ {With progressive bias against last turns}
|
||||
[if<0 p else q]
|
||||
]
|
||||
]
|
||||
|
||||
if<>0 call {TurnL or TurnR and update Bias}
|
||||
]
|
||||
pop ret
|
||||
] AutoControl=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 6 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$600
|
||||
|
||||
[def {AddTimer}
|
||||
push
|
||||
Timer+ Timer=
|
||||
15- [if>0 15 Timer=]
|
||||
\frameCount, TimeOut=
|
||||
DrawTimer!
|
||||
pop ret
|
||||
] AddTimer=
|
||||
|
||||
[def {SetupGame}
|
||||
push
|
||||
|
||||
{Reset score}
|
||||
0 Score= Timer= DrawScore!
|
||||
15 Timer= DrawTimer!
|
||||
DrawHighScore!
|
||||
|
||||
{Clear playing field}
|
||||
4 {Dark green field} BgColor=
|
||||
$1000 Pos= ClearScreen!
|
||||
|
||||
{Draw bounding box}
|
||||
26 {Orange wall} Color=
|
||||
+1 Step= 159 DrawLine!
|
||||
$100 Step= 111 DrawLine!
|
||||
-1 Step= 159 DrawLine!
|
||||
-$100 Step= 110 DrawLine!
|
||||
+1 Step= 158 DrawLine!
|
||||
$100 Step= 109 DrawLine!
|
||||
-1 Step= 157 DrawLine!
|
||||
-$100 Step= 109 DrawLine!
|
||||
|
||||
{Play messages}
|
||||
GetReady!
|
||||
|
||||
{Place snake}
|
||||
$4430 Head= Tail=
|
||||
DrawHead!
|
||||
|
||||
0 Grow= Drops=
|
||||
Timer= 15 AddTimer!
|
||||
$0002 stepU= $0200 stepV= {Start right}
|
||||
|
||||
{Place 25 foods}
|
||||
25 [do i= AddFood! i 1- if>0loop]
|
||||
|
||||
LaunchControl Control=
|
||||
|
||||
pop ret
|
||||
] SetupGame=
|
||||
|
||||
[def
|
||||
push
|
||||
$802 Pos=
|
||||
Score HighScore- [if>0 30 else 8] Color=
|
||||
0 BgColor=
|
||||
Score Value= DrawNumber4!
|
||||
|
||||
{Progressive game speed}
|
||||
Score 100- [if<0 4 else
|
||||
200- [if<0 3 else 2]] Delay=
|
||||
|
||||
pop ret
|
||||
] DrawScore=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}$08a0 \vLR: ret{ RAM page 8 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$8a0
|
||||
|
||||
[def {LaunchControl}
|
||||
{
|
||||
XXX better strategy: run both PlayerControl and AutoControl.
|
||||
The first one to take control will take over the game...
|
||||
}
|
||||
push
|
||||
$449c Head- [if=0
|
||||
{Switch to autopilot when reaching this position}
|
||||
30 {XXX} Color=
|
||||
$0802 Pos=
|
||||
[def `AUTO #0] PrintText!
|
||||
AutoControl Control= call
|
||||
else
|
||||
{Disable launch control once a button is pressed}
|
||||
\buttonState, $cf& {~buttonStart|~buttonSelect} $cf^ [if<>0 PlayerControl Control= call]
|
||||
]
|
||||
pop ret
|
||||
] LaunchControl=
|
||||
|
||||
[def { DrawNumber2 - Value Radix }
|
||||
push
|
||||
$20 Char=
|
||||
10 Radix= DrawNextDigit!
|
||||
$30 Char=
|
||||
1 Radix= DrawNextDigit!
|
||||
pop ret
|
||||
] DrawNumber2=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 9 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$9a0
|
||||
|
||||
[def { DrawNextDigit -- Value Radix }
|
||||
push
|
||||
Value Radix- [if>=0
|
||||
Value=
|
||||
$31 Char=
|
||||
Value [do
|
||||
Radix-
|
||||
if>=0
|
||||
Value=
|
||||
<Char++
|
||||
loop
|
||||
]
|
||||
PrintChar!
|
||||
$30 Char=
|
||||
else
|
||||
PrintChar!
|
||||
]
|
||||
pop ret
|
||||
] DrawNextDigit=
|
||||
|
||||
[def { DrawNumber4 - Value Radix }
|
||||
push
|
||||
$20 Char=
|
||||
1000 Radix= DrawNextDigit!
|
||||
100 Radix= DrawNextDigit!
|
||||
10 Radix= DrawNextDigit!
|
||||
$30 Char=
|
||||
1 Radix= DrawNextDigit!
|
||||
pop ret
|
||||
] DrawNumber4=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 10 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$aa0
|
||||
|
||||
[def
|
||||
push
|
||||
$874 Pos= 0 BgColor=
|
||||
[def `HI` #0] PrintText!
|
||||
HighScore Value= DrawNumber4!
|
||||
pop ret
|
||||
] DrawHighScore=
|
||||
|
||||
[def {SetupChannel}
|
||||
i= 255| 255^ $fa| p= {Pointer to channel struct}
|
||||
<i, i= {Extract note}
|
||||
0 p. <p++ {.wavA}
|
||||
1 p. <p++ {.wavX: 0 "Noise", 1 Triangle, 2 Pulse, 3 Sawtooth}
|
||||
\notesTable i+ 0? p. <p++ {.keyL}
|
||||
\notesTable i+ 1? p. <p++ {.keyH}
|
||||
ret
|
||||
] SetupChannel=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 11 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$ba0
|
||||
|
||||
{ Setup note in all channels, but don't play it yet }
|
||||
[def
|
||||
push
|
||||
1<< tmp=
|
||||
$100 tmp| {Channel 1} SetupChannel!
|
||||
$200 tmp| {Channel 2} SetupChannel!
|
||||
$300 tmp| {Channel 3} SetupChannel!
|
||||
$400 tmp| {Channel 4} SetupChannel!
|
||||
pop ret
|
||||
] SetNote=
|
||||
|
||||
[def
|
||||
push
|
||||
$49 j= [do
|
||||
j SetNote!
|
||||
5 \soundTimer.
|
||||
[do \soundTimer, if<>0loop]
|
||||
j 1- j= $30^ if<>0loop]
|
||||
pop ret
|
||||
] PlayGameOverSound=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 12 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$ca0
|
||||
|
||||
{ Display the get ready messages }
|
||||
[def
|
||||
push
|
||||
$4533
|
||||
p= Pos= 24 Color= Messages PrintText! 45 Wait! {Eat food}
|
||||
p Pos= 62 Color= Text PrintText! 45 Wait! {Not poison}
|
||||
p Pos= 15 Color= Text PrintText! 45 Wait! {Get ready}
|
||||
p Pos= Text PrintText!
|
||||
pop ret
|
||||
] GetReady=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 13 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$da0
|
||||
|
||||
[def
|
||||
stepU tmp= {Default keep running in same direction}
|
||||
\buttonState, $fe^ {~buttonRight} [if=0 $0002 tmp=]
|
||||
\buttonState, $fd^ {~buttonLeft} [if=0 $fffe tmp=]
|
||||
\buttonState, $fb^ {~buttonDown} [if=0 $0200 tmp=]
|
||||
\buttonState, $f7^ {~buttonUp} [if=0 $fe00 tmp=]
|
||||
{Only turn if not reversing 180 degrees}
|
||||
tmp stepU+ [if<>0 tmp stepU=]
|
||||
{Note: `stepV' is not used once under player control}
|
||||
ret
|
||||
] PlayerControl=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
|}>_vLR++ ret{ RAM page 14 |
|
||||
+-----------------------------------------------------------------------}
|
||||
*=$ea0
|
||||
|
||||
[def ``EAT`FOOD #0
|
||||
`NOT`POISON #0
|
||||
`GET`READY! #0
|
||||
``````````` #0] Messages=
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| Run |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
Intro!
|
||||
|
||||
$49 SetNote!
|
||||
|
||||
[do
|
||||
SetupGame!
|
||||
RunGame!
|
||||
|
||||
120 \soundTimer.
|
||||
7 {Orange} Color= Head DrawBlock!
|
||||
GameOver!
|
||||
60 Wait!
|
||||
|
||||
loop
|
||||
]
|
||||
|
||||
{-----------------------------------------------------------------------+
|
||||
| End |
|
||||
+-----------------------------------------------------------------------}
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user