I haven't been doing much this morning, and the creative juices were flowing... I got to thinking, how had would it be to write a kix script/game of tetris?

Please see other post for more information

11-3-00
another update. this now requires kixlib32 to be installed for it to work. http://www.neosoft.com/~brycel/kix/kix_tools/

code:

break on cls
$nul = setascii("on")

$debug = "off"

$fill = chr(178)
$cr = chr(13)+chr(10)
$grid = "1,10,30,27"
$deadspace = "|"

$kixlib=olecreateobject("kixlib32.library")
if @error <> 0
? "You must have kixlib32 installed"
? "get it here HTTP://www.neosoft.com/~brycel/kix/"
exit
endif

;---------------------------------------------------------------------------

gosub set_grid

? "Press any key start. Press Q to quit"
? "A = pick a random block | D = debug on and off"
? "8 = Up 4 = left 6 = right"
? "7 = rotate counterclockwise 8 = rotate clockwise"
? "5 = Drop piece in place"
get $nul

gosub get_piece
gosub check_area

$nul = execute('$writeblock')

while 1
at(0,0)@time "|" $piecenum
if olecallfunc($kixlib,"kbhit") = 1
get $key
select
case $key = "4"
$nul = execute('$clearblock')
$y=$y-1
gosub check_area
case $key = "6"
$nul = execute('$clearblock')
$y=$y+1
gosub check_area
case $key = "7"
$rotate = -1
$nul = execute('$clearblock')
gosub rotate
gosub check_area
case $key = "9"
$rotate = 1
$nul = execute('$clearblock')
gosub rotate
gosub check_area
case $key = "2"
$nul = execute('$clearblock')
$x = $x+1
gosub check_area
case $key = "8"
$nul = execute('$clearblock')
$x = $x-1
gosub check_area
case $key = "5"
gosub check_area
gosub get_piece
case $key = "a"
$nul = execute('$clearblock')
$seed = $seed + 100
srnd($seed)
gosub get_piece
gosub check_area
case $key = "d"
if $debug = "off"
$debug = "on"
else
$debug = "off"
endif
case $key = "q"
at($maxx+5,0)
exit
endselect
if $debug = "on"
at(4,$maxy+1) "$x,$y"
at(5,$maxy+1) " "
at(5,$maxy+1) "$$b0x="$x+$b0x" $$b0y="$y+$b0y
at(6,$maxy+1) " "
at(6,$maxy+1) "$$b1x="$x+$b1x" $$b1y="$y+$b1y
at(7,$maxy+1) " "
at(7,$maxy+1) "$$b2x="$x+$b2x" $$b2y="$y+$b2y
at(8,$maxy+1) " "
at(8,$maxy+1) "$$b3x="$x+$b3x" $$b3y="$y+$b3y
endif
$nul = execute('$writeblock')
endif

$nul=olecallfunc($kixlib,"sleep","s","100")
loop

exit


:get_piece
dim $count
$nul = rnd(15)
$x = $startx
$y = $starty

$piecenum = rnd(14)
:rotate
select
case $piecenum = 0 ;0 1
$piece = "10111213"
if $rotate <> 0
$rotate = 0
$piecenum = 1
goto rotate
endif
case $piecenum = 1
$piece = "01112131"
if $rotate <> 0
$rotate = 0
$piecenum = 0
goto rotate
endif
case $piecenum = 2 ;2 3 4 5
$piece = "10111222"
if $rotate = -1
$rotate = 0
$piecenum = 5
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 3
goto rotate
endif
case $piecenum = 3
$piece = "01112120"
if $rotate = -1
$rotate = 0
$piecenum = 2
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 4
goto rotate
endif
case $piecenum = 4
$piece = "00101112"
if $rotate = -1
$rotate = 0
$piecenum = 3
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 5
goto rotate
endif
case $piecenum = 5
$piece = "00011020"
if $rotate = -1
$rotate = 0
$piecenum = 4
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 2
goto rotate
endif
case $piecenum = 6 ;6 7 8 9
$piece = "10111220"
if $rotate = -1
$rotate = 0
$piecenum = 9
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 7
goto rotate
endif
case $piecenum = 7
$piece = "00011121"
if $rotate = -1
$rotate = 0
$piecenum = 6
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 8
goto rotate
endif
case $piecenum = 8
$piece = "02101112"
if $rotate = -1
$rotate = 0
$piecenum = 7
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 9
goto rotate
endif
case $piecenum = 9
$piece = "01112122"
if $rotate = -1
$rotate = 0
$piecenum = 8
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 6
goto rotate
endif
case $piecenum = 10 ;10 11 12 13
$piece = "10111221"
if $rotate = -1
$rotate = 0
$piecenum = 13
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 11
goto rotate
endif
case $piecenum = 11
$piece = "01101121"
if $rotate = -1
$rotate = 0
$piecenum = 10
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 12
goto rotate
endif
case $piecenum = 12
$piece = "10111201"
if $rotate = -1
$rotate = 0
$piecenum = 11
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 13
goto rotate
endif
case $piecenum = 13
$piece = "01112112"
if $rotate = -1
$rotate = 0
$piecenum = 12
goto rotate
endif
if $rotate = 1
$rotate = 0
$piecenum = 10
goto rotate
endif
case $piecenum = 14
$piece = "00011011"
if $rotate <> 0 $rotate = 0 endif
endselect
$count = 1
do
Select
case $count = 1
$b0x = val(substr(substr($piece,$count,2),1,1))
$b0y = val(substr(substr($piece,$count,2),2,1))
case $count = 3
$b1x = val(substr(substr($piece,$count,2),1,1))
$b1y = val(substr(substr($piece,$count,2),2,1))
case $count = 5
$b2x = val(substr(substr($piece,$count,2),1,1))
$b2y = val(substr(substr($piece,$count,2),2,1))
case $count = 7
$b3x = val(substr(substr($piece,$count,2),1,1))
$b3y = val(substr(substr($piece,$count,2),2,1))
endselect
$count = $count + 2
until $count = 9

$writeblock = "at($$x+$$b0x,$$y+$$b0y) $$fill
at($$x+$$b1x,$$y+$$b1y) $$fill
at($$x+$$b2x,$$y+$$b2y) $$fill
at($$x+$$b3x,$$y+$$b3y) $$fill"

$clearblock = "at($$x+$$b0x,$$y+$$b0y) ' '
at($$x+$$b1x,$$y+$$b1y) ' '
at($$x+$$b2x,$$y+$$b2y) ' '
at($$x+$$b3x,$$y+$$b3y) ' '"
return


:check_area
$tx0 = $x + $b0x
$ty0 = $y + $b0y
$tx1 = $x + $b1x
$ty1 = $y + $b1y
$tx2 = $x + $b2x
$ty2 = $y + $b2y
$tx3 = $x + $b3x
$ty3 = $y + $b3y

if $debug = "on"
at(10,$maxy+1) " "
at(10,$maxy+1) "$tx0,$ty0|$tx1,$ty1|$tx2,$ty2|$tx3,$ty3"
at(11,$maxy+1) "$x,$y"
endif

select
case $key = 5
;add to deadspace
$deadspace = $deadspace + "$tx0,$ty0|$tx1,$ty1|$tx2,$ty2|$tx3,$ty3|"
if $debug = "on"
at(12,$maxy+1) $deadspace
endif
case 1
if $x+$b0x <= $minX or $x+$b1x <= $minx or $x+$b2x <= $minx or $x+$b3x <= $minx
play "1d 400f"
$x = $x+1
goto check_area
endif
if $y+$b0y <= $miny or $y+$b1y <= $miny or $y+$b2y <= $miny or $y+$b3y <= $miny
play "1d 400f"
$y = $y+1
goto check_area
endif
if $x+$b0x >= $maxX or $x+$b1x >= $maxx or $x+$b2x >= $maxx or $x+$b3x >= $maxx
play "1d 400f"
$x = $x-1
goto check_area
endif
if $y+$b0y >= $maxy or $y+$b1y >= $maxy or $y+$b2y >= $maxy or $y+$b3y >= $maxy
play "1d 400f"
$y = $y-1
goto check_area
endif
;checking deadspace
if instr("$deadspace","|$tx0,$ty0|") <> 0
play "1d 400f"
$goback = 1
endif
if instr("$deadspace","|$tx1,$ty1|") <> 0
play "1d 400f"
$goback = 1
endif
if instr("$deadspace","|$tx2,$ty2|") <> 0
play "1d 400f"
$goback = 1
endif
if instr("$deadspace","|$tx3,$ty3|") <> 0
play "1d 400f"
$goback = 1
endif

if $goback <> 0
$goback = 0
Select
case $key = "4"
$y = $y + 1
case $key = "8"
$x = $x + 1
case $key = "6"
$y = $y - 1
case $key = "2"
$x = $x - 1
endselect
endif
endselect
return

:set_grid
$minX = val(substr("$grid",1,instr("$grid",",")-1))
$grid = substr("$grid",len("$minx")+2,len("$grid"))
$miny = val(substr("$grid",1,instr("$grid",",")-1))
$grid = substr("$grid",len("$miny")+2,len("$grid"))
$MaxX = val(substr("$grid",1,instr("$grid",",")-1))
$maxy = val(substr("$grid",len("$maxX")+2,len("$grid")))

$startx = $minx+2
$starty = (($maxy-$miny)/2)+$miny

$key = ""
$seed = (val(substr(@time,7,2))*2)*184
srnd($seed)
$tl = chr(218)
$Tln = chr(196)
$tr = chr(191)
$Rln = chr(179)
$br = chr(217)
$bln = chr(196)
$bl = chr(192)
$Lln = chr(179)
$boxfill = " "

box($minx,$miny,$maxX,$maxY, "$tl$Tln$tr$rln$br$bln$bl$lln$boxfill")
return


Bryce


[This message has been edited by Bryce (edited 02 November 2000).]

[This message has been edited by Bryce (edited 02 November 2000).]

[This message has been edited by Bryce (edited 03 November 2000).]