Page 1 of 2 12>
Topic Options
#52036 - 2000-11-01 06:19 PM an extreamly slow day.......
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
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).]

Top
#52037 - 2000-11-02 01:39 AM Re: an extreamly slow day.......
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
ok I updated the above script. added user control L R and rotate. I will update again when I add collision detection.

It looks like a lack of INKEY will stop me from making a really functional Kix_Tetris program. Unless anyone can figure out a way to pull the last pressed key from the keyboard buffer.

Bryce


Top
#52038 - 2000-11-02 03:31 AM Re: an extreamly slow day.......
Paul_Berquam Offline
Hey THIS is FUN

Registered: 2000-08-02
Posts: 310
Loc: Sacramento, CA USA
What if instead you put all keypresses to an array and pop from that into the command sequence?
_________________________
He was a good little monkey and always very curious...

Top
#52039 - 2000-11-03 12:34 AM Re: an extreamly slow day.......
Anonymous
Unregistered


Bryce

I tried to copy/paste the whole lot. But the result is that it will show up as one long sentence in my editor. (Not only in my editor, also in Notepad). Do you use some special editor that uses a different EOL.
I asume that I'm not the only one with this problem. Or is everyone retyping the code.

Marck

Top
#52040 - 2000-11-02 01:50 PM Re: an extreamly slow day.......
Anonymous
Unregistered


Hya Marck..,

You should first c/p it to Wordpad and than c/p from Wordpad to your editor.

------------------
Hope to be of service..,

Fabian.

-----------------Paranoia is reality on a finer scale-----------------

Top
#52041 - 2000-11-02 02:49 PM Re: an extreamly slow day.......
Rogier Pelzer Offline
Fresh Scripter

Registered: 2000-02-04
Posts: 41
Loc: The Netherlands
Bryce..... you are !@#$#$ crazy
Top
#52042 - 2000-11-02 10:23 PM Re: an extreamly slow day.......
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Ok, i got collision detection working on everything except rotate.

I am really convinced that if i had a way to capture the keyboard buffer I could get this to work , as it stands this has just been an extremely good/fun scripting project .

About the only thing that you can do with this now is place the blocks anywhere on the screen, and then add another one next to it.

Bryce

PS. this thing has turned into a monster!

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

Top
#52043 - 2000-11-03 02:18 PM Re: an extreamly slow day.......
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Bryce,

I have written a 10 byte program for you to get the key from the keyboard buffer and return it to KiX in @error. I have also written a program that does the same as sleep, but accepts milliseconds...

Unfortunately I cannot get to my software page to update it so... I have emailed them to you. If anyone else wants a copy, just email me: chrismat@ozemail.com.au

Usage:

getkey.com - just run it and if there is a key in the buffer, it will return it in %errorlevel% (or @error in Kix)

ddelay.exe - ddelay n where n is the number of milliseconds to wait.

how to use these in KiX:

this is my getkey test program

code:

break on

;
; GETKEY gets the next key from the keyb buffer
;

:label1

flushkb

shell "cmd /c getkey"


?
"@error"

if @error=113
quit
endif

goto label1



The flushKB was my testing

to use ddelay:

code:

shell "%comspec% /c ddelay 500"

half second delay

While ddelay is running, you can put a key in the buffer...

hope this helps somewhere...

cj


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

Top
#52044 - 2000-11-03 03:15 PM Re: an extreamly slow day.......
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
CJ! you are so cool!

I will take a look at these.

THANKS!

Bryce

Top
#52045 - 2000-11-03 11:33 PM Re: an extreamly slow day.......
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
CJ thanks for the tools!

Shawn also come up with similar tools but in a dll format (some really slick stuff!)

I updated the first post with the latest version. I will be out of town until next WED (11-8-2000) i will pick this up again then

You need to have kixlib32 installed for the above script to work. get it from here http://www.neosoft.com/~brycel/kix/kix_tools/

Bryce

Top
#52046 - 2000-11-06 02:36 PM Re: an extreamly slow day.......
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gang:

Since Bryce isn't around to point this out - I've noticed that when one copies his program into write.exe - write.exe drops the last quote off his comment about where his web site is - have to replace it manually !

Shawn.

Top
#52047 - 2000-11-06 09:34 PM Re: an extreamly slow day.......
Anonymous
Unregistered


Hi,

I see all of you are cut-n-pasting scripts into wordpad. This because when you paste it right into notepad everything will be on one line?
I have found another (easier) way to accomplish this.
Just click on the 'edit this message' button. When you cut-n-paste from the screen you get, it will work without putting all code on just one line (is it called a oneliner? ;-)

Cya.
Wam

Top
#52048 - 2000-11-06 09:42 PM Re: an extreamly slow day.......
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Wam:

Works like a charm my brother !

It even perserves the tab formatting ... excellent !

Shawn.

Top
#52049 - 2000-11-06 11:47 PM Re: an extreamly slow day.......
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia

Howdy,

Tetris is a cool idea... here is my implementation - it's a bit buggy when you get multiple lines at once, but otherwise mostly works.

You will need the DDELAY.EXE and GETKEY.COM programs that I mentioned earlier. I will try to get them onto my software page again, but no guarantees. Just email me at chrismat@ozemail.com.au for them.

Maybe I will use the facilities of kixlib32...


a bit about the code. This is a vector systems. Each block has a base point or staring point, and the rest of the block is drawn with respect to that point. eg: the T shape is base, base-1 on the X axis, base+1 on the X axis and base+1 on the Y axis.

There is a grid database that is a flat 1D array that is accessed as though it were a 2D array.

When a line is found, the screen is re-drawn from the database, otherwise the database is calculated from the screen.

this is only one nights work (I started work at 0:00 and it's now 08:50) so it's not perfect, but I hope someone likes it...


cj


code:

cls
break on

$=setascii("on")

; normal sized DOS box perimeter
box(0, 0, 25, 79, single)


; Define shapes
;
; There are four kinds: I, L, T and B
; each has four pieces: 0, 1, 2 and 3
; and each has four rotations: 1, 2, 3 and 4
;
; I= XXXX
;
; X
; X
; L= XX
;
; 7= XX
; X
; X
; X
; T= XX
; X
;
; B= XX
; XX
;
; These are created from a base point and then an array of the
; other relative points
;
; ie for the T that is XXX
; X
; the base is the top center and the
; other points are numbered: 102
; 3
; so, to generate a T we draw a X at base (0, 0)
; then one at (-1, 0) then (+1, 0) and then (0, +1)
;
dim $ix1[4] dim $ix2[4] dim $ix3[4] dim $ix4[4]
dim $iy1[4] dim $iy2[4] dim $iy3[4] dim $iy4[4] ; I
dim $lx1[4] dim $lx2[4] dim $lx3[4] dim $lx4[4]
dim $ly1[4] dim $ly2[4] dim $ly3[4] dim $ly4[4] ; L
dim $7x1[4] dim $7x2[4] dim $7x3[4] dim $7x4[4]
dim $7y1[4] dim $7y2[4] dim $7y3[4] dim $7y4[4] ; 7
dim $tx1[4] dim $tx2[4] dim $tx3[4] dim $tx4[4]
dim $ty1[4] dim $ty2[4] dim $ty3[4] dim $ty4[4] ; T
dim $bx1[4] dim $bx2[4] dim $bx3[4] dim $bx4[4]
dim $by1[4] dim $by2[4] dim $by3[4] dim $by4[4] ; Box

$ix1[1]=1 $iy1[1]=0 $ix1[2]=2 $iy1[2]=0 $ix1[3]=3 $iy1[3]=0
$ix2[1]=0 $iy2[1]=1 $ix2[2]=0 $iy2[2]=2 $ix2[3]=0 $iy2[3]=3
$ix3[1]=1 $iy3[1]=0 $ix3[2]=2 $iy3[2]=0 $ix3[3]=3 $iy3[3]=0
$ix4[1]=0 $iy4[1]=1 $ix4[2]=0 $iy4[2]=2 $ix4[3]=0 $iy4[3]=3

$lx1[1]=0 $ly1[1]=-1 $lx1[2]=1 $ly1[2]=0 $lx1[3]=2 $ly1[3]=0
$lx2[1]=1 $ly2[1]=0 $lx2[2]=0 $ly2[2]=1 $lx2[3]=0 $ly2[3]=2
$lx3[1]=0 $ly3[1]=1 $lx3[2]=-1 $ly3[2]=0 $lx3[3]=-2 $ly3[3]=0
$lx4[1]=-1 $ly4[1]=0 $lx4[2]=0 $ly4[2]=-1 $lx4[3]=0 $ly4[3]=-2

$7x1[1]=0 $7y1[1]=1 $7x1[2]=1 $7y1[2]=0 $7x1[3]=2 $7y1[3]=0
$7x2[1]=-1 $7y2[1]=0 $7x2[2]=0 $7y2[2]=1 $7x2[3]=0 $7y2[3]=2
$7x3[1]=0 $7y3[1]=-1 $7x3[2]=-1 $7y3[2]=0 $7x3[3]=-2 $7y3[3]=0
$7x4[1]=1 $7y4[1]=0 $7x4[2]=0 $7y4[2]=-1 $7x4[3]=0 $7y4[3]=-2

$tx1[1]=-1 $ty1[1]=0 $tx1[2]=0 $ty1[2]=-1 $tx1[3]=1 $ty1[3]=0
$tx2[1]=0 $ty2[1]=-1 $tx2[2]=1 $ty2[2]=0 $tx2[3]=0 $ty2[3]=1
$tx3[1]=1 $ty3[1]=0 $tx3[2]=0 $ty3[2]=1 $tx3[3]=-1 $ty3[3]=0
$tx4[1]=0 $ty4[1]=1 $tx4[2]=-1 $ty4[2]=0 $tx4[3]=0 $ty4[3]=-1

$bx1[1]=0 $by1[1]=1 $bx1[2]=1 $by1[2]=1 $bx1[3]=1 $by1[3]=0
$bx2[1]=0 $by2[1]=1 $bx2[2]=1 $by2[2]=1 $bx2[3]=1 $by2[3]=0
$bx3[1]=0 $by3[1]=1 $bx3[2]=1 $by3[2]=1 $bx3[3]=1 $by3[3]=0
$bx4[1]=0 $by4[1]=1 $bx4[2]=1 $by4[2]=1 $bx4[3]=1 $by4[3]=0

; dimension database
dim $grid[229] ; 12x19 grid - 1 is top left, 228 is bottom right

$i=1
do
$grid[$i]="." ; initialise grid database with .
$i=$i+1
until $i=229

goto main

:erase_block
;
; accepts:
;
; $x, $y: location of new block
;
; returns:
;
; block erased at ($x, $y)
;
at($x, $y) " "
at($x+$disp1x, $y+$disp1y) " "
at($x+$disp2x, $y+$disp2y) " "
at($x+$disp3x, $y+$disp3y) " "

return


:draw_block
;
; accepts:
;
; $x, $y: location of new block
;
; returns:
;
; block drawn at ($x, $y)
;
at($x, $y) chr(219)
at($x+$disp1x, $y+$disp1y) chr(219)
at($x+$disp2x, $y+$disp2y) chr(219)
at($x+$disp3x, $y+$disp3y) chr(219)

return

:random_colour
;
; accepts:
;
; nothing
;
; returns:
;
; sets the colour randomly
;
$col=rnd(6)
select
case $col=0 color b+/n
case $col=1 color g+/n
case $col=2 color c+/n
case $col=3 color r+/n
case $col=4 color m+/n
case $col=5 color y+/n
case $col=6 color w+/n
endselect

return


:choose_block
;
; accepts:
;
; $turn for rotation: 1..4
; $block for block shape: 0..4
; 0=i, 1=l, 2=7, 3=t or 4=b
;
; returns:
;
; $disp1x, $disp1y = offset of block 1
; $disp2x, $disp2y = offset of block 2
; $disp3x, $disp3y = offset of block 3
; $left = blocks to the left of base (center)
; $right = block to the right of base
; $height = blocks under base
;
select
case $block=0 ; i
select
case $turn=1
$disp1x=$ix1[1] $disp1y=$iy1[1]
$disp2x=$ix1[2] $disp2y=$iy1[2]
$disp3x=$ix1[3] $disp3y=$iy1[3]
$left=0 $right=0 $height=3
case $turn=2
$disp1x=$ix2[1] $disp1y=$iy2[1]
$disp2x=$ix2[2] $disp2y=$iy2[2]
$disp3x=$ix2[3] $disp3y=$iy2[3]
$left=0 $right=3 $height=0
case $turn=3
$disp1x=$ix3[1] $disp1y=$iy3[1]
$disp2x=$ix3[2] $disp2y=$iy3[2]
$disp3x=$ix3[3] $disp3y=$iy3[3]
$left=0 $right=0 $height=3
case $turn=4
$disp1x=$ix4[1] $disp1y=$iy4[1]
$disp2x=$ix4[2] $disp2y=$iy4[2]
$disp3x=$ix4[3] $disp3y=$iy4[3]
$left=0 $right=3 $height=0
endselect

case $block=1 ; L
select
case $turn=1
$disp1x=$lx1[1] $disp1y=$ly1[1]
$disp2x=$lx1[2] $disp2y=$ly1[2]
$disp3x=$lx1[3] $disp3y=$ly1[3]
$left=1 $right=0 $height=2
case $turn=2
$disp1x=$lx2[1] $disp1y=$ly2[1]
$disp2x=$lx2[2] $disp2y=$ly2[2]
$disp3x=$lx2[3] $disp3y=$ly2[3]
$left=0 $right=2 $height=1
case $turn=3
$disp1x=$lx3[1] $disp1y=$ly3[1]
$disp2x=$lx3[2] $disp2y=$ly3[2]
$disp3x=$lx3[3] $disp3y=$ly3[3]
$left=0 $right=1 $height=0
case $turn=4
$disp1x=$lx4[1] $disp1y=$ly4[1]
$disp2x=$lx4[2] $disp2y=$ly4[2]
$disp3x=$lx4[3] $disp3y=$ly4[3]
$left=2 $right=0 $height=0
endselect

case $block=2 ; 7
select
case $turn=1
$disp1x=$7x1[1] $disp1y=$7y1[1]
$disp2x=$7x1[2] $disp2y=$7y1[2]
$disp3x=$7x1[3] $disp3y=$7y1[3]
$left=0 $right=1 $height=2
case $turn=2
$disp1x=$7x2[1] $disp1y=$7y2[1]
$disp2x=$7x2[2] $disp2y=$7y2[2]
$disp3x=$7x2[3] $disp3y=$7y2[3]
$left=0 $right=2 $height=0
case $turn=3
$disp1x=$7x3[1] $disp1y=$7y3[1]
$disp2x=$7x3[2] $disp2y=$7y3[2]
$disp3x=$7x3[3] $disp3y=$7y3[3]
$left=1 $right=0 $height=0
case $turn=4
$disp1x=$7x4[1] $disp1y=$7y4[1]
$disp2x=$7x4[2] $disp2y=$7y4[2]
$disp3x=$7x4[3] $disp3y=$7y4[3]
$left=2 $right=0 $height=1
endselect

case $block=3 ; T
select
case $turn=1
$disp1x=$tx1[1] $disp1y=$ty1[1]
$disp2x=$tx1[2] $disp2y=$ty1[2]
$disp3x=$tx1[3] $disp3y=$ty1[3]
$left=1 $right=0 $height=1
case $turn=2
$disp1x=$tx2[1] $disp1y=$ty2[1]
$disp2x=$tx2[2] $disp2y=$ty2[2]
$disp3x=$tx2[3] $disp3y=$ty2[3]
$left=1 $right=1 $height=1
case $turn=3
$disp1x=$tx3[1] $disp1y=$ty3[1]
$disp2x=$tx3[2] $disp2y=$ty3[2]
$disp3x=$tx3[3] $disp3y=$ty3[3]
$left=0 $right=1 $height=1
case $turn=4
$disp1x=$tx4[1] $disp1y=$ty4[1]
$disp2x=$tx4[2] $disp2y=$ty4[2]
$disp3x=$tx4[3] $disp3y=$ty4[3]
$left=1 $right=1 $height=0
endselect

case $block=4 ; b
select
case $turn=1
$disp1x=$bx1[1] $disp1y=$by1[1]
$disp2x=$bx1[2] $disp2y=$by1[2]
$disp3x=$bx1[3] $disp3y=$by1[3]
$left=0 $right=1 $height=1
case $turn=2
$disp1x=$bx2[1] $disp1y=$by2[1]
$disp2x=$bx2[2] $disp2y=$by2[2]
$disp3x=$bx2[3] $disp3y=$by2[3]
$left=0 $right=1 $height=1
case $turn=3
$disp1x=$bx3[1] $disp1y=$by3[1]
$disp2x=$bx3[2] $disp2y=$by3[2]
$disp3x=$bx3[3] $disp3y=$by3[3]
$left=0 $right=1 $height=1
case $turn=4
$disp1x=$bx4[1] $disp1y=$by4[1]
$disp2x=$bx4[2] $disp2y=$by4[2]
$disp3x=$bx4[3] $disp3y=$by4[3]
$left=0 $right=1 $height=1
endselect

endselect

return

:check_block
;
; if the block is poking outside the box, move it in.
;

if $y+$right>14
$y=14-$right
at($x, $y+$right+1) chr(179) ; replace |
endif
if $y-$left<3
$y=3+$left
at($x, $y-$left-1) chr(179) ; replace |
endif

return


:show_grid
$xx=3
do
$yy=25
do
at($xx, $yy)

$quiz=(($xx-3)*12+($yy-25))+1

$disp=$grid[$quiz] "$disp"
$yy=$yy+1
until $yy=37
$xx=$xx+1
until $xx=22

return


:check_for_line
;
; Checks database for a complete line of blocks
; then removes this line and drops all other lines down
; and increments the score
;
$i=0
$line=""
do
$line=""
$column=1
do
$char=$i*12+$column
$line=$line+$grid[$char]
$column=$column+1
until $column=13

if $line="xxxxxxxxxxxx" ; Line found
do
$column=1
do
$dest=$i*12+$column
$source=$dest-12
$grid[$dest]=$grid[$source] ; move all lines down one
$column=$column+1
until $column=13
$i=$i-1
until $i=0

; update screen
$x=3
$y=3
do
$y=3
do
at($x, $y)
$scan=(($x-3)*12)+($y-3)
if $grid[$scan]="x" chr(219) else " " endif ; move all blocks down
$y=$y+1
until $y=15
$x=$x+1
until $x=22
$i=19
goto leave
endif

$i=$i+1
:leave
until $i=19


:check_grid
;
; accepts:
;
; $x, $y = screen location of block base
; $dispnX, $dispnY = additional block pieces
;
; returns:
;
; $clear = 1 next grid space down is free
; $clear = 0 next grid space down is occupied
;
$clear=0

$base=(($x-3)*12)+($y-2)
if $debug=1
color w+/n
at(3, 40) "x=$x "
at(4, 40) "y=$y "
at(5, 40) "$$base=$base "
at(6, 40) "$$blocks=$blocks "
endif

if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

$base=((($x-3)+$disp1x)*12)+($y-2)+$disp1y
if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

$base=((($x-3)+$disp2x)*12)+($y-2)+$disp2y
if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

$base=((($x-3)+$disp3x)*12)+($y-2)+$disp3y
if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

return


:main
color w+/n
box(2, 2, 22, 15, single) ; draw box
at(22, 20) ",=left .=right SPACE=rotate ENTER=drop q=quit"
at(2, 2) " " ; cut the top off
$blocks=0 ; number of blocks that have fallen
$debug=0 ; show debug info
$delay=500 ; delay in milliseconds between block drops
$colchange=0

if $debug=1 box(2, 24, 22, 37, single) endif ; draw database grid display

do
if $debug=1
at(5, 20) @error " " ; display ascii code of keypress
gosub show_grid ; display grid database
endif

$blocks=$blocks+1
at(10, 40) "Block No: $blocks "
$block=rnd(4) ; new block shape
; at(9, 40) "$$block=$block "
$turn=rnd(3)+1 ; new block direction
; at(8, 40) "$$turn=$turn "
;gosub random_colour
gosub choose_block ; choose new block
$x=3 $y=10 ; where the block starts its fall
$next=0
$nextline=0
$first=1
do
if @error=0 FLUSHKB endif
at(24, 1) ; move cursor out of the way

if $nextline=0
shell "cmd /c ddelay $delay" ; delay in milliseconds
shell "cmd /c getkey" ; get next key from buffer

gosub erase_block ; remove current block
select
case @error=46 $y=$y+1 if $y+$right>14 $y=14-$right endif ; left
case @error=44 $y=$y-1 if $y-$left<3 $y=3+$left endif ; right
case @error=32 ; rotate

if $debug=1
at(8, 40) "$$turn=$turn "
at(9, 40) "$$block=$block "
endif

$turn=$turn+1
if $turn=5 $turn=1 endif
gosub choose_block ; choose rotated block
gosub check_block ; make sure block is within the box
case @error=13 $nextline=1
case @error=113 color w+/n exit ; "Q"
case 1 $x=$x+1 ; down
endselect
else
shell "cmd /c ddelay 30"
gosub erase_block ; remove current block
$x=$x+1 ; down
endif

gosub check_grid ; check grid space is free

if $clear=1
$x=$x-1
gosub draw_block
if $first=1 $blocks=10 endif
$next=1
goto thats_it
endif

gosub draw_block ; draw new block

if $x+$height=21 $next=1 endif
:thats_it
$first=0
until $next=1 ; block has hit bottom

; update grid database
; base point
$base=(($x-3)*12)+($y-2)
if $debug=1
at(3, 40) "x=$x "
at(4, 40) "y=$y "
at(5, 40) "$$base=$base "
endif
$grid[$base]="x"

$base=((($x-3)+$disp1x)*12)+($y-2)+$disp1y
$grid[$base]="x"
$base=((($x-3)+$disp2x)*12)+($y-2)+$disp2y
$grid[$base]="x"
$base=((($x-3)+$disp3x)*12)+($y-2)+$disp3y
$grid[$base]="x"

; look for a continuous line
gosub check_for_line


until $blocks=1000 ; put your own ending in here...

quit





Top
#52050 - 2000-11-07 01:51 PM Re: an extreamly slow day.......
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
cj:

I'm not going to try your tetris game until you give us the kixlib32 version ... so there !

Shawn.

Top
#52051 - 2000-11-08 03:26 AM Re: an extreamly slow day.......
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
fair cop

I'll do it tonight.

But in the meantime, here is the block browser:

cj

P.S. It's doesn't need kixlib32

code:

cls
break on

$=setascii("on")

; normal sized DOS box perimeter
box(0, 0, 25, 79, single)

;box(2, 2, 22, 15, single) ; draw box

; Define shapes
;
; There are four kinds: I, L, T and B
; each has four pieces: 0, 1, 2 and 3
; and each has four rotations: 1, 2, 3 and 4
;
; I= XXXX
;
; X
; X
; L= XX
;
; 7= XX
; X
; X
; X
; T= XX
; X
;
; B= XX
; XX
;
; These are created from a base point and then an array of the
; other relative points
;
; ie for the T that is XXX
; X
; the base is the top center and the
; other points are numbered: 102
; 3
; so, to generate a T we draw a X at base (0, 0)
; then one at (-1, 0) then (+1, 0) and then (0, +1)
;
dim $ix1[4] dim $ix2[4] dim $ix3[4] dim $ix4[4]
dim $iy1[4] dim $iy2[4] dim $iy3[4] dim $iy4[4] ; I
dim $lx1[4] dim $lx2[4] dim $lx3[4] dim $lx4[4]
dim $ly1[4] dim $ly2[4] dim $ly3[4] dim $ly4[4] ; L
dim $7x1[4] dim $7x2[4] dim $7x3[4] dim $7x4[4]
dim $7y1[4] dim $7y2[4] dim $7y3[4] dim $7y4[4] ; 7
dim $tx1[4] dim $tx2[4] dim $tx3[4] dim $tx4[4]
dim $ty1[4] dim $ty2[4] dim $ty3[4] dim $ty4[4] ; T
dim $bx1[4] dim $bx2[4] dim $bx3[4] dim $bx4[4]
dim $by1[4] dim $by2[4] dim $by3[4] dim $by4[4] ; Box

$ix1[1]=1 $iy1[1]=0 $ix1[2]=2 $iy1[2]=0 $ix1[3]=3 $iy1[3]=0
$ix2[1]=0 $iy2[1]=1 $ix2[2]=0 $iy2[2]=2 $ix2[3]=0 $iy2[3]=3
$ix3[1]=1 $iy3[1]=0 $ix3[2]=2 $iy3[2]=0 $ix3[3]=3 $iy3[3]=0
$ix4[1]=0 $iy4[1]=1 $ix4[2]=0 $iy4[2]=2 $ix4[3]=0 $iy4[3]=3

$lx1[1]=0 $ly1[1]=-1 $lx1[2]=1 $ly1[2]=0 $lx1[3]=2 $ly1[3]=0
$lx2[1]=1 $ly2[1]=0 $lx2[2]=0 $ly2[2]=1 $lx2[3]=0 $ly2[3]=2
$lx3[1]=0 $ly3[1]=1 $lx3[2]=-1 $ly3[2]=0 $lx3[3]=-2 $ly3[3]=0
$lx4[1]=-1 $ly4[1]=0 $lx4[2]=0 $ly4[2]=-1 $lx4[3]=0 $ly4[3]=-2

$7x1[1]=0 $7y1[1]=1 $7x1[2]=1 $7y1[2]=0 $7x1[3]=2 $7y1[3]=0
$7x2[1]=-1 $7y2[1]=0 $7x2[2]=0 $7y2[2]=1 $7x2[3]=0 $7y2[3]=2
$7x3[1]=0 $7y3[1]=-1 $7x3[2]=-1 $7y3[2]=0 $7x3[3]=-2 $7y3[3]=0
$7x4[1]=1 $7y4[1]=0 $7x4[2]=0 $7y4[2]=-1 $7x4[3]=0 $7y4[3]=-2

$tx1[1]=-1 $ty1[1]=0 $tx1[2]=0 $ty1[2]=-1 $tx1[3]=1 $ty1[3]=0
$tx2[1]=0 $ty2[1]=-1 $tx2[2]=1 $ty2[2]=0 $tx2[3]=0 $ty2[3]=1
$tx3[1]=1 $ty3[1]=0 $tx3[2]=0 $ty3[2]=1 $tx3[3]=-1 $ty3[3]=0
$tx4[1]=0 $ty4[1]=1 $tx4[2]=-1 $ty4[2]=0 $tx4[3]=0 $ty4[3]=-1

$bx1[1]=0 $by1[1]=1 $bx1[2]=1 $by1[2]=1 $bx1[3]=1 $by1[3]=0
$bx2[1]=0 $by2[1]=1 $bx2[2]=1 $by2[2]=1 $bx2[3]=1 $by2[3]=0
$bx3[1]=0 $by3[1]=1 $bx3[2]=1 $by3[2]=1 $bx3[3]=1 $by3[3]=0
$bx4[1]=0 $by4[1]=1 $bx4[2]=1 $by4[2]=1 $bx4[3]=1 $by4[3]=0

$turn=1

:chooz

at(19, 1) "Choose shape: I, L, 7, T or B..."
at(20, 1) "R=Rotate Q=Quit"
get $key

if $key="q"
exit
endif

select
case $key="r"
$turn=$turn+1
if $turn=5
$turn=1
endif
$key=$lastkey

endselect

select
case $key="i"
select
case $turn=1
$disp1x=$ix1[1] $disp1y=$iy1[1]
$disp2x=$ix1[2] $disp2y=$iy1[2]
$disp3x=$ix1[3] $disp3y=$iy1[3]
case $turn=2
$disp1x=$ix2[1] $disp1y=$iy2[1]
$disp2x=$ix2[2] $disp2y=$iy2[2]
$disp3x=$ix2[3] $disp3y=$iy2[3]
case $turn=3
$disp1x=$ix3[1] $disp1y=$iy3[1]
$disp2x=$ix3[2] $disp2y=$iy3[2]
$disp3x=$ix3[3] $disp3y=$iy3[3]
case $turn=4
$disp1x=$ix4[1] $disp1y=$iy4[1]
$disp2x=$ix4[2] $disp2y=$iy4[2]
$disp3x=$ix4[3] $disp3y=$iy4[3]
endselect

case $key="l"
select
case $turn=1
$disp1x=$lx1[1] $disp1y=$ly1[1]
$disp2x=$lx1[2] $disp2y=$ly1[2]
$disp3x=$lx1[3] $disp3y=$ly1[3]
case $turn=2
$disp1x=$lx2[1] $disp1y=$ly2[1]
$disp2x=$lx2[2] $disp2y=$ly2[2]
$disp3x=$lx2[3] $disp3y=$ly2[3]
case $turn=3
$disp1x=$lx3[1] $disp1y=$ly3[1]
$disp2x=$lx3[2] $disp2y=$ly3[2]
$disp3x=$lx3[3] $disp3y=$ly3[3]
case $turn=4
$disp1x=$lx4[1] $disp1y=$ly4[1]
$disp2x=$lx4[2] $disp2y=$ly4[2]
$disp3x=$lx4[3] $disp3y=$ly4[3]
endselect

case $key="7"
select
case $turn=1
$disp1x=$7x1[1] $disp1y=$7y1[1]
$disp2x=$7x1[2] $disp2y=$7y1[2]
$disp3x=$7x1[3] $disp3y=$7y1[3]
case $turn=2
$disp1x=$7x2[1] $disp1y=$7y2[1]
$disp2x=$7x2[2] $disp2y=$7y2[2]
$disp3x=$7x2[3] $disp3y=$7y2[3]
case $turn=3
$disp1x=$7x3[1] $disp1y=$7y3[1]
$disp2x=$7x3[2] $disp2y=$7y3[2]
$disp3x=$7x3[3] $disp3y=$7y3[3]
case $turn=4
$disp1x=$7x4[1] $disp1y=$7y4[1]
$disp2x=$7x4[2] $disp2y=$7y4[2]
$disp3x=$7x4[3] $disp3y=$7y4[3]
endselect

case $key="t"
select
case $turn=1
$disp1x=$tx1[1] $disp1y=$ty1[1]
$disp2x=$tx1[2] $disp2y=$ty1[2]
$disp3x=$tx1[3] $disp3y=$ty1[3]
case $turn=2
$disp1x=$tx2[1] $disp1y=$ty2[1]
$disp2x=$tx2[2] $disp2y=$ty2[2]
$disp3x=$tx2[3] $disp3y=$ty2[3]
case $turn=3
$disp1x=$tx3[1] $disp1y=$ty3[1]
$disp2x=$tx3[2] $disp2y=$ty3[2]
$disp3x=$tx3[3] $disp3y=$ty3[3]
case $turn=4
$disp1x=$tx4[1] $disp1y=$ty4[1]
$disp2x=$tx4[2] $disp2y=$ty4[2]
$disp3x=$tx4[3] $disp3y=$ty4[3]
endselect

case $key="b"
select
case $turn=1
$disp1x=$bx1[1] $disp1y=$by1[1]
$disp2x=$bx1[2] $disp2y=$by1[2]
$disp3x=$bx1[3] $disp3y=$by1[3]
case $turn=2
$disp1x=$bx2[1] $disp1y=$by2[1]
$disp2x=$bx2[2] $disp2y=$by2[2]
$disp3x=$bx2[3] $disp3y=$by2[3]
case $turn=3
$disp1x=$bx3[1] $disp1y=$by3[1]
$disp2x=$bx3[2] $disp2y=$by3[2]
$disp3x=$bx3[3] $disp3y=$by3[3]
case $turn=4
$disp1x=$bx4[1] $disp1y=$by4[1]
$disp2x=$bx4[2] $disp2y=$by4[2]
$disp3x=$bx4[3] $disp3y=$by4[3]
endselect

endselect

; remember last key press for rotate
$lastkey=$key

; erase old symbol
box(1, 1, 10, 10, " ")

; draw symbol
$x=5 $y=5

at($x, $y) chr(219)
at($x+$disp1x, $y+$disp1y) chr(219)
at($x+$disp2x, $y+$disp2y) chr(219)
at($x+$disp3x, $y+$disp3y) chr(219)

at(9, 9) "$turn"

goto chooz



Top
#52052 - 2000-11-08 10:59 AM Re: an extreamly slow day.......
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Alors, à votre demande here is the KiXlib32 version..

I am still working on the completed line code....FIXED!!!

bug fix - thanks Shawn!

Added scoring system and game speed increases as you get better...

...added rand seed

cj


code:

cls
break on

$=setascii("on")
$seed=val(substr("@time",7,2)) $seed=$seed+1
do $=rnd(1) $seed=$seed-1 until $seed=0

; normal sized DOS box perimeter because I use a bigger box
box(0, 0, 25, 79, single)


; Define shapes
;
; There are four kinds: I, L, T and B
; each has four pieces: 0, 1, 2 and 3
; and each has four rotations: 1, 2, 3 and 4
;
; I= XXXX
;
; X
; X
; L= XX
;
; 7= XX
; X
; X
; X
; T= XX
; X
;
; B= XX
; XX
;
; These are created from a base point and then an array of the
; other relative points
;
; ie for the T that is XXX
; X
; the base is the top center and the
; other points are numbered: 102
; 3
; so, to generate a T we draw a X at base (0, 0)
; then one at (-1, 0) then (+1, 0) and then (0, +1)
;
dim $ix1[4] dim $ix2[4] dim $ix3[4] dim $ix4[4]
dim $iy1[4] dim $iy2[4] dim $iy3[4] dim $iy4[4] ; I
dim $lx1[4] dim $lx2[4] dim $lx3[4] dim $lx4[4]
dim $ly1[4] dim $ly2[4] dim $ly3[4] dim $ly4[4] ; L
dim $7x1[4] dim $7x2[4] dim $7x3[4] dim $7x4[4]
dim $7y1[4] dim $7y2[4] dim $7y3[4] dim $7y4[4] ; 7
dim $tx1[4] dim $tx2[4] dim $tx3[4] dim $tx4[4]
dim $ty1[4] dim $ty2[4] dim $ty3[4] dim $ty4[4] ; T
dim $bx1[4] dim $bx2[4] dim $bx3[4] dim $bx4[4]
dim $by1[4] dim $by2[4] dim $by3[4] dim $by4[4] ; Box

$ix1[1]=1 $iy1[1]=0 $ix1[2]=2 $iy1[2]=0 $ix1[3]=3 $iy1[3]=0
$ix2[1]=0 $iy2[1]=1 $ix2[2]=0 $iy2[2]=2 $ix2[3]=0 $iy2[3]=3
$ix3[1]=1 $iy3[1]=0 $ix3[2]=2 $iy3[2]=0 $ix3[3]=3 $iy3[3]=0
$ix4[1]=0 $iy4[1]=1 $ix4[2]=0 $iy4[2]=2 $ix4[3]=0 $iy4[3]=3

$lx1[1]=0 $ly1[1]=-1 $lx1[2]=1 $ly1[2]=0 $lx1[3]=2 $ly1[3]=0
$lx2[1]=1 $ly2[1]=0 $lx2[2]=0 $ly2[2]=1 $lx2[3]=0 $ly2[3]=2
$lx3[1]=0 $ly3[1]=1 $lx3[2]=-1 $ly3[2]=0 $lx3[3]=-2 $ly3[3]=0
$lx4[1]=-1 $ly4[1]=0 $lx4[2]=0 $ly4[2]=-1 $lx4[3]=0 $ly4[3]=-2

$7x1[1]=0 $7y1[1]=1 $7x1[2]=1 $7y1[2]=0 $7x1[3]=2 $7y1[3]=0
$7x2[1]=-1 $7y2[1]=0 $7x2[2]=0 $7y2[2]=1 $7x2[3]=0 $7y2[3]=2
$7x3[1]=0 $7y3[1]=-1 $7x3[2]=-1 $7y3[2]=0 $7x3[3]=-2 $7y3[3]=0
$7x4[1]=1 $7y4[1]=0 $7x4[2]=0 $7y4[2]=-1 $7x4[3]=0 $7y4[3]=-2

$tx1[1]=-1 $ty1[1]=0 $tx1[2]=0 $ty1[2]=-1 $tx1[3]=1 $ty1[3]=0
$tx2[1]=0 $ty2[1]=-1 $tx2[2]=1 $ty2[2]=0 $tx2[3]=0 $ty2[3]=1
$tx3[1]=1 $ty3[1]=0 $tx3[2]=0 $ty3[2]=1 $tx3[3]=-1 $ty3[3]=0
$tx4[1]=0 $ty4[1]=1 $tx4[2]=-1 $ty4[2]=0 $tx4[3]=0 $ty4[3]=-1

$bx1[1]=0 $by1[1]=1 $bx1[2]=1 $by1[2]=1 $bx1[3]=1 $by1[3]=0
$bx2[1]=0 $by2[1]=1 $bx2[2]=1 $by2[2]=1 $bx2[3]=1 $by2[3]=0
$bx3[1]=0 $by3[1]=1 $bx3[2]=1 $by3[2]=1 $bx3[3]=1 $by3[3]=0
$bx4[1]=0 $by4[1]=1 $bx4[2]=1 $by4[2]=1 $bx4[3]=1 $by4[3]=0

; dimension database
dim $grid[229] ; 12x19 grid - 1 is top left, 228 is bottom right

$i=1
do
$grid[$i]="." ; initialise grid database with .
$i=$i+1
until $i=229

goto main

:erase_block
;
; accepts:
;
; $x, $y: location of new block
;
; returns:
;
; block erased at ($x, $y)
;
at($x, $y) " "
at($x+$disp1x, $y+$disp1y) " "
at($x+$disp2x, $y+$disp2y) " "
at($x+$disp3x, $y+$disp3y) " "

return


:draw_block
;
; accepts:
;
; $x, $y: location of new block
;
; returns:
;
; block drawn at ($x, $y)
;
at($x, $y) chr(219)
at($x+$disp1x, $y+$disp1y) chr(219)
at($x+$disp2x, $y+$disp2y) chr(219)
at($x+$disp3x, $y+$disp3y) chr(219)

return

:random_colour
;
; accepts:
;
; nothing
;
; returns:
;
; sets the colour randomly
;
$col=rnd(6)
select
case $col=0 color b+/n
case $col=1 color g+/n
case $col=2 color c+/n
case $col=3 color r+/n
case $col=4 color m+/n
case $col=5 color y+/n
case $col=6 color w+/n
endselect

return


:choose_block
;
; accepts:
;
; $turn for rotation: 1..4
; $block for block shape: 0..4
; 0=i, 1=l, 2=7, 3=t or 4=b
;
; returns:
;
; $disp1x, $disp1y = offset of block 1
; $disp2x, $disp2y = offset of block 2
; $disp3x, $disp3y = offset of block 3
; $left = blocks to the left of base (center)
; $right = block to the right of base
; $height = blocks under base
;
select
case $block=0 ; i
select
case $turn=1
$disp1x=$ix1[1] $disp1y=$iy1[1]
$disp2x=$ix1[2] $disp2y=$iy1[2]
$disp3x=$ix1[3] $disp3y=$iy1[3]
$left=0 $right=0 $height=3
case $turn=2
$disp1x=$ix2[1] $disp1y=$iy2[1]
$disp2x=$ix2[2] $disp2y=$iy2[2]
$disp3x=$ix2[3] $disp3y=$iy2[3]
$left=0 $right=3 $height=0
case $turn=3
$disp1x=$ix3[1] $disp1y=$iy3[1]
$disp2x=$ix3[2] $disp2y=$iy3[2]
$disp3x=$ix3[3] $disp3y=$iy3[3]
$left=0 $right=0 $height=3
case $turn=4
$disp1x=$ix4[1] $disp1y=$iy4[1]
$disp2x=$ix4[2] $disp2y=$iy4[2]
$disp3x=$ix4[3] $disp3y=$iy4[3]
$left=0 $right=3 $height=0
endselect

case $block=1 ; L
select
case $turn=1
$disp1x=$lx1[1] $disp1y=$ly1[1]
$disp2x=$lx1[2] $disp2y=$ly1[2]
$disp3x=$lx1[3] $disp3y=$ly1[3]
$left=1 $right=0 $height=2
case $turn=2
$disp1x=$lx2[1] $disp1y=$ly2[1]
$disp2x=$lx2[2] $disp2y=$ly2[2]
$disp3x=$lx2[3] $disp3y=$ly2[3]
$left=0 $right=2 $height=1
case $turn=3
$disp1x=$lx3[1] $disp1y=$ly3[1]
$disp2x=$lx3[2] $disp2y=$ly3[2]
$disp3x=$lx3[3] $disp3y=$ly3[3]
$left=0 $right=1 $height=0
case $turn=4
$disp1x=$lx4[1] $disp1y=$ly4[1]
$disp2x=$lx4[2] $disp2y=$ly4[2]
$disp3x=$lx4[3] $disp3y=$ly4[3]
$left=2 $right=0 $height=0
endselect

case $block=2 ; 7
select
case $turn=1
$disp1x=$7x1[1] $disp1y=$7y1[1]
$disp2x=$7x1[2] $disp2y=$7y1[2]
$disp3x=$7x1[3] $disp3y=$7y1[3]
$left=0 $right=1 $height=2
case $turn=2
$disp1x=$7x2[1] $disp1y=$7y2[1]
$disp2x=$7x2[2] $disp2y=$7y2[2]
$disp3x=$7x2[3] $disp3y=$7y2[3]
$left=0 $right=2 $height=0
case $turn=3
$disp1x=$7x3[1] $disp1y=$7y3[1]
$disp2x=$7x3[2] $disp2y=$7y3[2]
$disp3x=$7x3[3] $disp3y=$7y3[3]
$left=1 $right=0 $height=0
case $turn=4
$disp1x=$7x4[1] $disp1y=$7y4[1]
$disp2x=$7x4[2] $disp2y=$7y4[2]
$disp3x=$7x4[3] $disp3y=$7y4[3]
$left=2 $right=0 $height=1
endselect

case $block=3 ; T
select
case $turn=1
$disp1x=$tx1[1] $disp1y=$ty1[1]
$disp2x=$tx1[2] $disp2y=$ty1[2]
$disp3x=$tx1[3] $disp3y=$ty1[3]
$left=1 $right=0 $height=1
case $turn=2
$disp1x=$tx2[1] $disp1y=$ty2[1]
$disp2x=$tx2[2] $disp2y=$ty2[2]
$disp3x=$tx2[3] $disp3y=$ty2[3]
$left=1 $right=1 $height=1
case $turn=3
$disp1x=$tx3[1] $disp1y=$ty3[1]
$disp2x=$tx3[2] $disp2y=$ty3[2]
$disp3x=$tx3[3] $disp3y=$ty3[3]
$left=0 $right=1 $height=1
case $turn=4
$disp1x=$tx4[1] $disp1y=$ty4[1]
$disp2x=$tx4[2] $disp2y=$ty4[2]
$disp3x=$tx4[3] $disp3y=$ty4[3]
$left=1 $right=1 $height=0
endselect

case $block=4 ; b
select
case $turn=1
$disp1x=$bx1[1] $disp1y=$by1[1]
$disp2x=$bx1[2] $disp2y=$by1[2]
$disp3x=$bx1[3] $disp3y=$by1[3]
$left=0 $right=1 $height=1
case $turn=2
$disp1x=$bx2[1] $disp1y=$by2[1]
$disp2x=$bx2[2] $disp2y=$by2[2]
$disp3x=$bx2[3] $disp3y=$by2[3]
$left=0 $right=1 $height=1
case $turn=3
$disp1x=$bx3[1] $disp1y=$by3[1]
$disp2x=$bx3[2] $disp2y=$by3[2]
$disp3x=$bx3[3] $disp3y=$by3[3]
$left=0 $right=1 $height=1
case $turn=4
$disp1x=$bx4[1] $disp1y=$by4[1]
$disp2x=$bx4[2] $disp2y=$by4[2]
$disp3x=$bx4[3] $disp3y=$by4[3]
$left=0 $right=1 $height=1
endselect

endselect

return

:check_block
;
; if the block is poking outside the box, move it in.
;

if $y+$right>14
$y=14-$right
at($x, $y+$right+1) chr(179) ; replace |
endif
if $y-$left<3
$y=3+$left
at($x, $y-$left-1) chr(179) ; replace |
endif

return


:show_grid
$xx=3
do
$yy=25
do
at($xx, $yy)

$quiz=(($xx-3)*12+($yy-25))+1

$disp=$grid[$quiz] "$disp"
$yy=$yy+1
until $yy=37
$xx=$xx+1
until $xx=22

return


:check_for_line
;
; Checks database for a complete line of blocks
; then removes this line and drops all other lines down
; and increments the score
;
$i=0
$line=""
$bFound=0 ; reset this now, if nothing is found, doesn't return here
do
$line=""
$column=1
do
$char=$i*12+$column
$line=$line+$grid[$char]
$column=$column+1
until $column=13
;at(0,0) "$i=$line " get$

if $line="xxxxxxxxxxxx" ; Line found
$bFound=1
$score=$score+10 ; you score!!!
$ibackup=$i
do
$column=1
do
$dest=$i*12+$column
$source=$dest-12
;at(0,0) "$$source=$source $$dest=$dest " get$
$grid[$dest]=$grid[$source] ; move all lines down one
$column=$column+1
until $column=13
$i=$i-1
until $i=0

$i=$ibackup
; update screen
$x=3
do
$y=3
do
at($x, $y)
$scan=(($x-3)*12)+($y-2)
if $grid[$scan]="x" chr(219) else " " endif ; move all blocks down
$y=$y+1
until $y=15
$x=$x+1
until $x=22
$i=19
goto leave
endif

$i=$i+1
:leave
until $i=19


:check_grid
;
; accepts:
;
; $x, $y = screen location of block base
; $dispnX, $dispnY = additional block pieces
;
; returns:
;
; $clear = 1 next grid space down is free
; $clear = 0 next grid space down is occupied
;
$clear=0

$base=(($x-3)*12)+($y-2)
if $debug=1
color w+/n
at(3, 40) "x=$x "
at(4, 40) "y=$y "
at(5, 40) "$$base=$base "
at(6, 40) "$$blocks=$blocks "
endif

if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

$base=((($x-3)+$disp1x)*12)+($y-2)+$disp1y
if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

$base=((($x-3)+$disp2x)*12)+($y-2)+$disp2y
if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

$base=((($x-3)+$disp3x)*12)+($y-2)+$disp3y
if $base>0 and $base<228 if $grid[$base]="x" $clear=1 endif endif

return


:choose_delay
;
; Increase speed as game progresses
;
select
case $score=100 $delay=450
case $score=200 $delay=400
case $score=300 $delay=350
case $score=400 $delay=300
case $score=500 $delay=250
case $score=600 $delay=200
case $score=700 $delay=150
case $score=800 $delay=100
case $score=900 $delay=50
endselect


return

:main
; open DLL
$kixlib=olecreateobject("kixlib32.library")
if $kixlib=0
cls
"KIXLIB32 not installed" ?
exit
endif

color w+/n
box(2, 2, 22, 15, single) ; draw box
at(22, 20) ",=left .=right SPACE=rotate ENTER=drop q=quit"
at(2, 2) " " ; cut the top off
$blocks=0 ; number of blocks that have fallen
$debug=0 ; show debug info
$delay=500 ; delay in milliseconds between block drops
$score=0

if $debug=1 box(2, 24, 22, 37, single) endif ; draw database grid display

$key=" " ;
while $key<>"q"
if $debug=1
at(5, 20) @error " " ; display ascii code of keypress
gosub show_grid ; display grid database
endif

$blocks=$blocks+1
at(10, 40) "Block No: $blocks "
at(11, 40) "Score: $score"
$block=rnd(4) ; new block shape
; at(9, 40) "$$block=$block "
$turn=rnd(3)+1 ; new block direction
; at(8, 40) "$$turn=$turn "
;gosub random_colour
gosub choose_block ; choose new block

gosub choose_delay ; game gets faster as you get better

$x=3 $y=10 ; where the block starts its fall
$next=0
$nextline=0
$first=1
do
at(24, 1) ; move cursor out of the way
$key=""
if $nextline=0
olecallfunc($kixlib,"sleep","s","$delay") ; delay in milliseconds
if olecallfunc($kixlib,"kbhit") = 1
get $key ; get next key from buffer
endif

gosub erase_block ; remove current block
select
case $key="." $y=$y+1 if $y+$right>14 $y=14-$right endif ; right
case $key="," $y=$y-1 if $y-$left<3 $y=3+$left endif ; left
case $key=" " ; rotate

if $debug=1
at(8, 40) "$$turn=$turn "
at(9, 40) "$$block=$block "
endif

$turn=$turn+1
if $turn=5 $turn=1 endif
gosub choose_block ; choose rotated block
gosub check_block ; make sure block is within the box
case $key=chr(13) $nextline=1
case $key="q" color w+/n exit ; "Q"
case 1 $x=$x+1 ; down
endselect
else
olecallfunc($kixlib,"sleep","s","30")
gosub erase_block ; remove current block
$x=$x+1 ; down
endif

gosub check_grid ; check grid space is free

if $clear=1
$x=$x-1
gosub draw_block
if $first=1 $blocks=10 endif
$next=1
goto thats_it
endif

gosub draw_block ; draw new block

if $x+$height=21 $next=1 endif
:thats_it
$first=0
until $next=1 ; block has hit bottom

; update grid database
; base point
$base=(($x-3)*12)+($y-2)
if $debug=1
at(3, 40) "x=$x "
at(4, 40) "y=$y "
at(5, 40) "$$base=$base "
endif
$grid[$base]="x"

$base=((($x-3)+$disp1x)*12)+($y-2)+$disp1y
$grid[$base]="x"
$base=((($x-3)+$disp2x)*12)+($y-2)+$disp2y
$grid[$base]="x"
$base=((($x-3)+$disp3x)*12)+($y-2)+$disp3y
$grid[$base]="x"

; look for a continuous line
$bFound=1
while $bFound=1 ; keeps checking until no lines found so multiples are got.
gosub check_for_line
loop
loop ; while $key<>"q"

quit




[This message has been edited by cj (edited 08 November 2000).]

Top
#52053 - 2000-11-09 06:41 PM Re: an extreamly slow day.......
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Colour version....

Here is prob the final release of this program for me, it's getting boring

Added colour and left/right movement checking. I played up to 450 points to test and there is a slight logic bug in the moving down of lines -50 points to however finds it

but essentially it works now.

Thanks to KixLib32 I will finish my KiX PACMAN game... you'll see it soon.

cj

code:

cls
break on

$=setascii("on")

$seed=val(substr("@time",7,2)) $seed=$seed+1
do $=rnd(1) $seed=$seed-1 until $seed=0

; normal sized DOS box perimeter because I use a bigger box
box(0, 0, 25, 79, single)


; Define shapes
;
; There are four kinds: I, L, T and B
; each has four pieces: 0, 1, 2 and 3
; and each has four rotations: 1, 2, 3 and 4
;
; I= XXXX
;
; X
; X
; L= XX
;
; 7= XX
; X
; X
; X
; T= XX
; X
;
; B= XX
; XX
;
; These are created from a base point and then an array of the
; other relative points
;
; ie for the T that is XXX
; X
; the base is the top center and the
; other points are numbered: 102
; 3
; so, to generate a T we draw a X at base (0, 0)
; then one at (-1, 0) then (+1, 0) and then (0, +1)
;
dim $ix1[4] dim $ix2[4] dim $ix3[4] dim $ix4[4]
dim $iy1[4] dim $iy2[4] dim $iy3[4] dim $iy4[4] ; I
dim $lx1[4] dim $lx2[4] dim $lx3[4] dim $lx4[4]
dim $ly1[4] dim $ly2[4] dim $ly3[4] dim $ly4[4] ; L
dim $7x1[4] dim $7x2[4] dim $7x3[4] dim $7x4[4]
dim $7y1[4] dim $7y2[4] dim $7y3[4] dim $7y4[4] ; 7
dim $tx1[4] dim $tx2[4] dim $tx3[4] dim $tx4[4]
dim $ty1[4] dim $ty2[4] dim $ty3[4] dim $ty4[4] ; T
dim $bx1[4] dim $bx2[4] dim $bx3[4] dim $bx4[4]
dim $by1[4] dim $by2[4] dim $by3[4] dim $by4[4] ; Box

$ix1[1]=1 $iy1[1]=0 $ix1[2]=2 $iy1[2]=0 $ix1[3]=3 $iy1[3]=0
$ix2[1]=0 $iy2[1]=1 $ix2[2]=0 $iy2[2]=2 $ix2[3]=0 $iy2[3]=3
$ix3[1]=1 $iy3[1]=0 $ix3[2]=2 $iy3[2]=0 $ix3[3]=3 $iy3[3]=0
$ix4[1]=0 $iy4[1]=1 $ix4[2]=0 $iy4[2]=2 $ix4[3]=0 $iy4[3]=3

$lx1[1]=0 $ly1[1]=-1 $lx1[2]=1 $ly1[2]=0 $lx1[3]=2 $ly1[3]=0
$lx2[1]=1 $ly2[1]=0 $lx2[2]=0 $ly2[2]=1 $lx2[3]=0 $ly2[3]=2
$lx3[1]=0 $ly3[1]=1 $lx3[2]=-1 $ly3[2]=0 $lx3[3]=-2 $ly3[3]=0
$lx4[1]=-1 $ly4[1]=0 $lx4[2]=0 $ly4[2]=-1 $lx4[3]=0 $ly4[3]=-2

$7x1[1]=0 $7y1[1]=1 $7x1[2]=1 $7y1[2]=0 $7x1[3]=2 $7y1[3]=0
$7x2[1]=-1 $7y2[1]=0 $7x2[2]=0 $7y2[2]=1 $7x2[3]=0 $7y2[3]=2
$7x3[1]=0 $7y3[1]=-1 $7x3[2]=-1 $7y3[2]=0 $7x3[3]=-2 $7y3[3]=0
$7x4[1]=1 $7y4[1]=0 $7x4[2]=0 $7y4[2]=-1 $7x4[3]=0 $7y4[3]=-2

$tx1[1]=-1 $ty1[1]=0 $tx1[2]=0 $ty1[2]=-1 $tx1[3]=1 $ty1[3]=0
$tx2[1]=0 $ty2[1]=-1 $tx2[2]=1 $ty2[2]=0 $tx2[3]=0 $ty2[3]=1
$tx3[1]=1 $ty3[1]=0 $tx3[2]=0 $ty3[2]=1 $tx3[3]=-1 $ty3[3]=0
$tx4[1]=0 $ty4[1]=1 $tx4[2]=-1 $ty4[2]=0 $tx4[3]=0 $ty4[3]=-1

$bx1[1]=0 $by1[1]=1 $bx1[2]=1 $by1[2]=1 $bx1[3]=1 $by1[3]=0
$bx2[1]=0 $by2[1]=1 $bx2[2]=1 $by2[2]=1 $bx2[3]=1 $by2[3]=0
$bx3[1]=0 $by3[1]=1 $bx3[2]=1 $by3[2]=1 $bx3[3]=1 $by3[3]=0
$bx4[1]=0 $by4[1]=1 $bx4[2]=1 $by4[2]=1 $bx4[3]=1 $by4[3]=0

; dimension database
dim $grid[229] ; 12x19 grid - 1 is top left, 228 is bottom right

$i=1
do
$grid[$i]="." ; initialise grid database with .
$i=$i+1
until $i=229

goto main

:erase_block
;
; accepts:
;
; $x, $y: location of new block
;
; returns:
;
; block erased at ($x, $y)
;
at($x, $y) " "
at($x+$disp1x, $y+$disp1y) " "
at($x+$disp2x, $y+$disp2y) " "
at($x+$disp3x, $y+$disp3y) " "

return


:draw_block
;
; accepts:
;
; $x, $y: location of new block
;
; returns:
;
; block drawn at ($x, $y)
;
gosub set_colour ; set to $colour
at($x, $y) chr(219)
at($x+$disp1x, $y+$disp1y) chr(219)
at($x+$disp2x, $y+$disp2y) chr(219)
at($x+$disp3x, $y+$disp3y) chr(219)
color w+/n ; reset to white

return

:set_colour
;
; accepts:
;
; $colour = number from 0..6
;
; returns:
;
; sets the colour according to the following table:
;
select
case $colour=0 color b+/n ; blue
case $colour=1 color g+/n ; green
case $colour=2 color c+/n ; cyan
case $colour=3 color r+/n ; red
case $colour=4 color m+/n ; magenta
case $colour=5 color y+/n ; yellow
case $colour=6 color w+/n ; white
endselect

return


:choose_block
;
; accepts:
;
; $turn for rotation: 1..4
; $block for block shape: 0..4
; 0=i, 1=l, 2=7, 3=t or 4=b
;
; returns:
;
; $disp1x, $disp1y = offset of block 1
; $disp2x, $disp2y = offset of block 2
; $disp3x, $disp3y = offset of block 3
; $left = blocks to the left of base (center)
; $right = block to the right of base
; $height = blocks under base
;
select
case $block=0 ; i
select
case $turn=1
$disp1x=$ix1[1] $disp1y=$iy1[1]
$disp2x=$ix1[2] $disp2y=$iy1[2]
$disp3x=$ix1[3] $disp3y=$iy1[3]
$left=0 $right=0 $height=3
case $turn=2
$disp1x=$ix2[1] $disp1y=$iy2[1]
$disp2x=$ix2[2] $disp2y=$iy2[2]
$disp3x=$ix2[3] $disp3y=$iy2[3]
$left=0 $right=3 $height=0
case $turn=3
$disp1x=$ix3[1] $disp1y=$iy3[1]
$disp2x=$ix3[2] $disp2y=$iy3[2]
$disp3x=$ix3[3] $disp3y=$iy3[3]
$left=0 $right=0 $height=3
case $turn=4
$disp1x=$ix4[1] $disp1y=$iy4[1]
$disp2x=$ix4[2] $disp2y=$iy4[2]
$disp3x=$ix4[3] $disp3y=$iy4[3]
$left=0 $right=3 $height=0
endselect

case $block=1 ; L
select
case $turn=1
$disp1x=$lx1[1] $disp1y=$ly1[1]
$disp2x=$lx1[2] $disp2y=$ly1[2]
$disp3x=$lx1[3] $disp3y=$ly1[3]
$left=1 $right=0 $height=2
case $turn=2
$disp1x=$lx2[1] $disp1y=$ly2[1]
$disp2x=$lx2[2] $disp2y=$ly2[2]
$disp3x=$lx2[3] $disp3y=$ly2[3]
$left=0 $right=2 $height=1
case $turn=3
$disp1x=$lx3[1] $disp1y=$ly3[1]
$disp2x=$lx3[2] $disp2y=$ly3[2]
$disp3x=$lx3[3] $disp3y=$ly3[3]
$left=0 $right=1 $height=0
case $turn=4
$disp1x=$lx4[1] $disp1y=$ly4[1]
$disp2x=$lx4[2] $disp2y=$ly4[2]
$disp3x=$lx4[3] $disp3y=$ly4[3]
$left=2 $right=0 $height=0
endselect

case $block=2 ; 7
select
case $turn=1
$disp1x=$7x1[1] $disp1y=$7y1[1]
$disp2x=$7x1[2] $disp2y=$7y1[2]
$disp3x=$7x1[3] $disp3y=$7y1[3]
$left=0 $right=1 $height=2
case $turn=2
$disp1x=$7x2[1] $disp1y=$7y2[1]
$disp2x=$7x2[2] $disp2y=$7y2[2]
$disp3x=$7x2[3] $disp3y=$7y2[3]
$left=0 $right=2 $height=0
case $turn=3
$disp1x=$7x3[1] $disp1y=$7y3[1]
$disp2x=$7x3[2] $disp2y=$7y3[2]
$disp3x=$7x3[3] $disp3y=$7y3[3]
$left=1 $right=0 $height=0
case $turn=4
$disp1x=$7x4[1] $disp1y=$7y4[1]
$disp2x=$7x4[2] $disp2y=$7y4[2]
$disp3x=$7x4[3] $disp3y=$7y4[3]
$left=2 $right=0 $height=1
endselect

case $block=3 ; T
select
case $turn=1
$disp1x=$tx1[1] $disp1y=$ty1[1]
$disp2x=$tx1[2] $disp2y=$ty1[2]
$disp3x=$tx1[3] $disp3y=$ty1[3]
$left=1 $right=0 $height=1
case $turn=2
$disp1x=$tx2[1] $disp1y=$ty2[1]
$disp2x=$tx2[2] $disp2y=$ty2[2]
$disp3x=$tx2[3] $disp3y=$ty2[3]
$left=1 $right=1 $height=1
case $turn=3
$disp1x=$tx3[1] $disp1y=$ty3[1]
$disp2x=$tx3[2] $disp2y=$ty3[2]
$disp3x=$tx3[3] $disp3y=$ty3[3]
$left=0 $right=1 $height=1
case $turn=4
$disp1x=$tx4[1] $disp1y=$ty4[1]
$disp2x=$tx4[2] $disp2y=$ty4[2]
$disp3x=$tx4[3] $disp3y=$ty4[3]
$left=1 $right=1 $height=0
endselect

case $block=4 ; b
select
case $turn=1
$disp1x=$bx1[1] $disp1y=$by1[1]
$disp2x=$bx1[2] $disp2y=$by1[2]
$disp3x=$bx1[3] $disp3y=$by1[3]
$left=0 $right=1 $height=1
case $turn=2
$disp1x=$bx2[1] $disp1y=$by2[1]
$disp2x=$bx2[2] $disp2y=$by2[2]
$disp3x=$bx2[3] $disp3y=$by2[3]
$left=0 $right=1 $height=1
case $turn=3
$disp1x=$bx3[1] $disp1y=$by3[1]
$disp2x=$bx3[2] $disp2y=$by3[2]
$disp3x=$bx3[3] $disp3y=$by3[3]
$left=0 $right=1 $height=1
case $turn=4
$disp1x=$bx4[1] $disp1y=$by4[1]
$disp2x=$bx4[2] $disp2y=$by4[2]
$disp3x=$bx4[3] $disp3y=$by4[3]
$left=0 $right=1 $height=1
endselect

endselect

return

:check_block
;
; if the block is poking outside the box, move it in.
;

if $y+$right>14
$y=14-$right
at($x, $y+$right+1) chr(179) ; replace |
endif
if $y-$left<3
$y=3+$left
at($x, $y-$left-1) chr(179) ; replace |
endif

return


:show_grid
$xx=3
do
$yy=25
do
at($xx, $yy)

$quiz=(($xx-3)*12+($yy-25))+1

$disp=$grid[$quiz] "$disp"
$yy=$yy+1
until $yy=37
$xx=$xx+1
until $xx=22

return


:check_for_line
;
; Checks database for a complete line of blocks
; then removes this line and drops all other lines down
; and increments the score
;
$i=0
$line=""
$bFound=0 ; reset this now, if nothing is found, doesn't return here
do
$line=""
$column=1
do
$char=$i*12+$column
$line=$line+$grid[$char]
$column=$column+1
until $column=13
;at(0,0) "$i=$line " get$

if instr($line, ".")=0 ; Line found without "." means full
$bFound=1
$score=$score+10 ; you score!!!
$ibackup=$i
do
$column=1
do
$dest=$i*12+$column
$source=$dest-12
;at(0,0) "$$source=$source $$dest=$dest " get$
$grid[$dest]=$grid[$source] ; move all lines down one
$column=$column+1
until $column=13
$i=$i-1
until $i=0

$i=$ibackup
; update screen
$x=3
do
$y=3
do ; move line down...
at($x, $y)
$scan=(($x-3)*12)+($y-2)
if $grid[$scan]="."
" " ; draw space
else
$colour=$grid[$scan]
gosub set_colour
chr(219) ; draw coloured block
color w+/n
endif
$y=$y+1
until $y=15 ; column...
$x=$x+1
until $x=22 ; all lines
$i=19
goto leave
endif

$i=$i+1 ; check next line
:leave
until $i=19


:check_grid
;
; accepts:
;
; $x, $y = screen location of block base
; $dispnX, $dispnY = additional block pieces
; $check = which direction to check - "below", "left" or "right"
;
; returns:
;
; $clear = 1 next grid space $check is free
; $clear = 0 space not free
;
$clear=1

select
case $check="below" $cx=$x-3 $cy=$y-2
case $check="left" $cx=$x-3 $cy=$y-3
case $check="right" $cx=$x-3 $cy=$y-1
endselect

$base=(($cx)*12)+($cy)
if $base>0 and $base<228 $scan=$grid[$base] if $scan<>"." $clear=0 endif endif
if $debug=1 at(3, 40) "x=$x " at(4, 40) "y=$y " at(5, 40) "$$base=$base $check $clear " at(6, 40) "$$blocks=$blocks " at(2, 40) "$$scan=$scan " endif

$base=((($cx)+$disp1x)*12)+($cy)+$disp1y
if $base>0 and $base<228 $scan=$grid[$base] if $scan<>"." $clear=0 endif endif
if $debug=1 at(3, 40) "x=$x " at(4, 40) "y=$y " at(5, 40) "$$base=$base $check $clear " at(6, 40) "$$blocks=$blocks " at(2, 40) "$$scan=$scan " endif

$base=((($cx)+$disp2x)*12)+($cy)+$disp2y
if $base>0 and $base<228 $scan=$grid[$base] if $scan<>"." $clear=0 endif endif
if $debug=1 at(3, 40) "x=$x " at(4, 40) "y=$y " at(5, 40) "$$base=$base $check $clear " at(6, 40) "$$blocks=$blocks " at(2, 40) "$$scan=$scan " endif

$base=((($cx)+$disp3x)*12)+($cy)+$disp3y
if $base>0 and $base<228 $scan=$grid[$base] if $scan<>"." $clear=0 endif endif
if $debug=1 at(3, 40) "x=$x " at(4, 40) "y=$y " at(5, 40) "$$base=$base $check $clear " at(6, 40) "$$blocks=$blocks " at(2, 40) "$$scan=$scan " endif

return


:choose_delay
;
; Increase speed as game progresses
;
select
case $score=100 $delay=450
case $score=200 $delay=400
case $score=300 $delay=350
case $score=400 $delay=300
case $score=500 $delay=250
case $score=600 $delay=200
case $score=700 $delay=150
case $score=800 $delay=100
case $score=900 $delay=50
endselect


return

:main
; open DLL
$kixlib=olecreateobject("kixlib32.library")
if $kixlib=0
cls
"KIXLIB32 not installed" ?
exit
endif

color w+/n
box(2, 2, 22, 15, single) ; draw box
at(22, 20) ",=left .=right SPACE=rotate ENTER=drop q=quit"
at(2, 2) " " ; cut the top off

$blocks=0 ; number of blocks that have fallen
$debug=0 ; show debug info
$delay=500 ; delay in milliseconds between block drops
$score=0 ; starting score

if $debug=1 box(2, 24, 22, 37, single) endif ; draw database grid display

$key=" " ; reset var
while $key<>"q"
if $debug=1
at(5, 20) @error " " ; display ascii code of keypress
gosub show_grid ; display grid database
endif

$blocks=$blocks+1
at(10, 40) "Block No: $blocks "
at(11, 40) "Score: $score"
$block=rnd(4) ; new block shape
; at(9, 40) "$$block=$block "
$turn=rnd(3)+1 ; new block direction
; at(8, 40) "$$turn=$turn "
;gosub random_colour
gosub choose_block ; choose new block
$colour=rnd(6) ; choose new colour

gosub choose_delay ; game gets faster as you get better

$x=4 $y=10 ; where the block starts its fall
$next=0
$nextline=0
$first=1
do
at(24, 1) ; move cursor out of the way
if $nextline=0
olecallfunc($kixlib,"sleep","s","$delay") ; delay in milliseconds
$key=""
if olecallfunc($kixlib,"kbhit") = 1
get $key ; get next key from buffer
endif

gosub erase_block ; remove current block
select
case $key="." ; right
$check="right"
gosub check_grid ; can we move left?
if $clear=0 ; NO
goto thats_it
endif
$y=$y+1
if $y+$right>14
$y=14-$right
goto thats_it
endif
case $key="," ; left
$check="left"
gosub check_grid ; can we move left?
if $clear=0 ; NO
goto thats_it
endif
$y=$y-1
if $y-$left<3
$y=3+$left
goto thats_it
endif
case $key=" " ; rotate
if $debug=1
at(8, 40) "$$turn=$turn "
at(9, 40) "$$block=$block "
endif
$turn=$turn+1
if $turn=5 $turn=1 endif
gosub choose_block ; choose rotated block
gosub check_block ; make sure block is within the box
case $key=chr(13) $nextline=1
case $key="q" color w+/n exit ; "Q"
case 1 $x=$x+1 ; down
endselect
else
olecallfunc($kixlib,"sleep","s","30")
gosub erase_block ; remove current block
$x=$x+1 ; down
endif

$check="below"
gosub check_grid ; check grid space is free

if $clear=0 ; landed on a block
$x=$x-1
gosub draw_block
if $first=1 $blocks=10 endif
$next=1
goto thats_it
endif

gosub draw_block ; draw new block

if $x+$height=21 $next=1 endif
:thats_it
$first=0
until $next=1 ; block has hit bottom

; update grid database with $colour
; base point
$base=(($x-3)*12)+($y-2)
if $debug=1
at(3, 40) "x=$x "
at(4, 40) "y=$y "
at(5, 40) "$$base=$base "
endif
$grid[$base]=$colour

$base=((($x-3)+$disp1x)*12)+($y-2)+$disp1y
$grid[$base]=$colour
$base=((($x-3)+$disp2x)*12)+($y-2)+$disp2y
$grid[$base]=$colour
$base=((($x-3)+$disp3x)*12)+($y-2)+$disp3y
$grid[$base]=$colour

; look for a continuous line
$bFound=1
while $bFound=1 ; keeps checking until no lines found so multiples are got.
gosub check_for_line
loop
loop ; while $key<>"q"

quit




Top
#52054 - 2000-11-09 07:35 PM Re: an extreamly slow day.......
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Been thinking of adding some new "gaming" functions for our kix library ...

GetTickCount

The GetTickCount function retrieves
the number of milliseconds that have
elapsed since the system was started.
[Might be useful when seeding your
RND() function]

SetConsoleTitle

The SetConsoleTitle function sets
the title bar string for the current
console window.

SetConsoleCursorInfo

The SetConsoleCursorInfo
function sets the size and visibility
of the cursor for the specified console
screen buffer. [Temporarily gets rid of
that nasty console cursor]

Anybody else have any ideas ?

Shawn.


Top
#52055 - 2000-11-09 07:43 PM Re: an extreamly slow day.......
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
I would love that cursor hide... I have tried to do it the old fashioned way by moving it to a non visible location, but NT gets upset. I even tried making it 0 pixels high (used to work in DOS) but NT wouldn't hear of it

The SRND function in KiX can't take a $var, only a hard coded int... but a RNG in kixlib32 would be cool... I found a cool reg key in Software\microsoft\cryptography\RNG called SEED and it changes every now and then...

cj

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 533 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.156 seconds in which 0.074 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org