From 3e2082dddfccf3ee578d98fbc53202023d186b27 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 24 Mar 2024 11:31:28 -0700 Subject: [PATCH] (snake) Fixed death bug --- projects/examples/demos/snake.tal | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/projects/examples/demos/snake.tal b/projects/examples/demos/snake.tal index e1e3558..e3e383e 100644 --- a/projects/examples/demos/snake.tal +++ b/projects/examples/demos/snake.tal @@ -64,8 +64,7 @@ @ ( -- ) ( | copy tail ) - [ LITr -snake/pos ] LDZ2r - .snake/length LDZ #00 + [ LITr -snake/pos ] LDZ2r .snake/length LDZ #00 &>loop ( -- ) DUPk ADD .snake/tail ADD LDZ2k STH2 SWP2r STH2r ROT STZ2 @@ -74,13 +73,13 @@ ( ) .snake/dead LDZ ?&end .snake/direction LDZ ( ) DUP #01 NEQ ?{ - .snake/y LDZ #01 SUB .arena/h LDZ [ LTHk JMP SWP POP ] .snake/y STZ } + .snake/y LDZk #01 SUB .arena/h set-pos } DUP #02 NEQ ?{ - .snake/y LDZ INC .arena/h LDZ DIVk MUL SUB .snake/y STZ } + .snake/y LDZk INC .arena/h set-pos } DUP #04 NEQ ?{ - .snake/x LDZ #01 SUB .arena/w LDZ [ LTHk JMP SWP POP ] .snake/x STZ } + .snake/x LDZk #01 SUB .arena/w set-pos } DUP #08 NEQ ?{ - .snake/x LDZ INC .arena/w LDZ DIVk MUL SUB .snake/x STZ } + .snake/x LDZk INC .arena/w set-pos } POP ( | detect collision with apple ) .snake/pos LDZ2 .apple/pos LDZ2 NEQ2 ?{ @@ -97,6 +96,12 @@ INC GTHk ?&>loop-body POP2 &end JMP2r +@set-pos ( z mod -- ) + LDZ OVR INC ?{ ROT STZ + POP JMP2r } + DIVk MUL SUB SWP STZ + JMP2r + @ ( -- ) .DateTime/hour DEI2 .DateTime/minute DEI2 MUL2 ( ) DUP2 #1234 MUL2 ADD .arena/w LDZ DIVk MUL SUB .apple/x STZ