From cc078503e342456f5a7166c1efe8ec41fabd868e Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 9 Jul 2019 23:39:03 +0200 Subject: [PATCH] tehtriz example uses when statement --- examples/cube3d-sprites.p8 | 2 +- examples/primes.p8 | 2 - examples/tehtriz.p8 | 199 +++++++++++++++++++------------------ 3 files changed, 106 insertions(+), 97 deletions(-) diff --git a/examples/cube3d-sprites.p8 b/examples/cube3d-sprites.p8 index 8d629596c..5555cf70d 100644 --- a/examples/cube3d-sprites.p8 +++ b/examples/cube3d-sprites.p8 @@ -161,7 +161,7 @@ else c64.SPRPTR[i] = $2000/64 ; small ball - c64.SPCOL[i] = spritecolors[zc>>13 as byte + 4] ; further away=darker color + c64.SPCOL[i] = spritecolors[zc>>13 as byte + 4] ; further away=darker color TODO doesn't work anymore? ">>" seems broken. } } } diff --git a/examples/primes.p8 b/examples/primes.p8 index b2b548c9a..42a3b7f56 100644 --- a/examples/primes.p8 +++ b/examples/primes.p8 @@ -43,8 +43,6 @@ while multiple < len(sieve) { sieve[lsb(multiple)] = true multiple += candidate_prime - ; c64scr.print_uw(multiple) ; TODO - ; c4.CHROUT('\n') ; TODO } return candidate_prime } diff --git a/examples/tehtriz.p8 b/examples/tehtriz.p8 index 696fac5fa..c5dc9a16f 100644 --- a/examples/tehtriz.p8 +++ b/examples/tehtriz.p8 @@ -75,105 +75,116 @@ waitkey: } + sub move_left() { + drawBlock(xpos, ypos, 32) + if blocklogic.noCollision(xpos-1, ypos) { + xpos-- + } + drawBlock(xpos, ypos, 160) + } + + sub move_right() { + drawBlock(xpos, ypos, 32) + if blocklogic.noCollision(xpos+1, ypos) { + xpos++ + } + drawBlock(xpos, ypos, 160) + } + + sub move_down_faster() { + drawBlock(xpos, ypos, 32) + if blocklogic.noCollision(xpos, ypos+1) { + ypos++ + } + drawBlock(xpos, ypos, 160) + } + + sub drop_down_immediately() { + drawBlock(xpos, ypos, 32) + ubyte dropypos + for dropypos in ypos+1 to boardOffsetY+boardHeight-1 { + if not blocklogic.noCollision(xpos, dropypos) { + dropypos-- ; the furthest down that still fits + break + } + } + if dropypos>ypos { + ypos = dropypos + sound.blockdrop() + drawBlock(xpos, ypos, 160) + checkForLines() + spawnNextBlock() + score++ + drawScore() + } + } + sub keypress(ubyte key) { - if key==157 or key==',' { - ; move left - drawBlock(xpos, ypos, 32) - if blocklogic.noCollision(xpos-1, ypos) { - xpos-- - } - drawBlock(xpos, ypos, 160) - } - else if key==29 or key=='/' { - ; move right - drawBlock(xpos, ypos, 32) - if blocklogic.noCollision(xpos+1, ypos) { - xpos++ - } - drawBlock(xpos, ypos, 160) - } - else if key==17 or key=='.' { - ; move down faster - drawBlock(xpos, ypos, 32) - if blocklogic.noCollision(xpos, ypos+1) { - ypos++ - } - drawBlock(xpos, ypos, 160) - } - else if key==145 or key==' ' { - ; drop down immediately - drawBlock(xpos, ypos, 32) - ubyte dropypos - for dropypos in ypos+1 to boardOffsetY+boardHeight-1 { - if not blocklogic.noCollision(xpos, dropypos) { - dropypos-- ; the furthest down that still fits - break + when key { + 157 -> move_left() + ',' -> move_left() + 29 -> move_right() + '/' -> move_right() + 17 -> move_down_faster() + '.' -> move_down_faster() + 145 -> drop_down_immediately() + ' ' -> drop_down_immediately() + 'z' -> { + ; no joystick equivalent (there is only 1 fire button) + ; rotate counter clockwise + drawBlock(xpos, ypos, 32) + if blocklogic.canRotateCCW(xpos, ypos) { + blocklogic.rotateCCW() + sound.blockrotate() + } + else if blocklogic.canRotateCCW(xpos-1, ypos) { + xpos-- + blocklogic.rotateCCW() + sound.blockrotate() + } + else if blocklogic.canRotateCCW(xpos+1, ypos) { + xpos++ + blocklogic.rotateCCW() + sound.blockrotate() } - } - if dropypos>ypos { - ypos = dropypos - sound.blockdrop() drawBlock(xpos, ypos, 160) - checkForLines() - spawnNextBlock() - score++ - drawScore() } - } - else if key=='z' { ; no joystick equivalent (there is only 1 fire button) - ; rotate counter clockwise - drawBlock(xpos, ypos, 32) - if blocklogic.canRotateCCW(xpos, ypos) { - blocklogic.rotateCCW() - sound.blockrotate() - } - else if blocklogic.canRotateCCW(xpos-1, ypos) { - xpos-- - blocklogic.rotateCCW() - sound.blockrotate() - } - else if blocklogic.canRotateCCW(xpos+1, ypos) { - xpos++ - blocklogic.rotateCCW() - sound.blockrotate() - } - drawBlock(xpos, ypos, 160) - } - else if key=='x' { - ; rotate clockwise - drawBlock(xpos, ypos, 32) - if blocklogic.canRotateCW(xpos, ypos) { - blocklogic.rotateCW() - sound.blockrotate() - } - else if blocklogic.canRotateCW(xpos-1, ypos) { - xpos-- - blocklogic.rotateCW() - sound.blockrotate() - } - else if blocklogic.canRotateCW(xpos+1, ypos) { - xpos++ - blocklogic.rotateCW() - sound.blockrotate() - } - drawBlock(xpos, ypos, 160) - } - else if key=='c' { - ; hold - if holdingAllowed { - sound.swapping() - if holding<7 { - drawBlock(xpos, ypos, 32) - ubyte newholding = blocklogic.currentBlockNum - swapBlock(holding) - holding = newholding - holdingAllowed = false - } else { - holding = blocklogic.currentBlockNum - drawBlock(xpos, ypos, 32) - spawnNextBlock() + 'x' -> { + ; rotate clockwise + drawBlock(xpos, ypos, 32) + if blocklogic.canRotateCW(xpos, ypos) { + blocklogic.rotateCW() + sound.blockrotate() + } + else if blocklogic.canRotateCW(xpos-1, ypos) { + xpos-- + blocklogic.rotateCW() + sound.blockrotate() + } + else if blocklogic.canRotateCW(xpos+1, ypos) { + xpos++ + blocklogic.rotateCW() + sound.blockrotate() + } + drawBlock(xpos, ypos, 160) + } + 'c' -> { + ; hold + if holdingAllowed { + sound.swapping() + if holding<7 { + drawBlock(xpos, ypos, 32) + ubyte newholding = blocklogic.currentBlockNum + swapBlock(holding) + holding = newholding + holdingAllowed = false + } else { + holding = blocklogic.currentBlockNum + drawBlock(xpos, ypos, 32) + spawnNextBlock() + } + drawHoldBlock() } - drawHoldBlock() } } }