i have recently started a tetris project it all works but i dont know how to put the shapes in as it only spawns 1 coloured square on the grid at a time here is my code so far:
sync on : sync rate 15
set window on
hide mouse
screenX=200 : screenY=50
size=20
delay = 500
type tetromino
hue as integer
active as boolean
endtype
true = 1 : false = 0
global dim grid (10,20) as tetromino
global block as tetromino
//Define Colours
DIM colour(7)
black=0 : red=1 : orange=2 : yellow=3 : green=4 : cyan=5 : blue=6 : magenta=7
colour(black)=0
colour(red)=rgb(255,0,0)
colour(orange)=rgb(255,128,0)
colour(yellow)=rgb(255,255,0)
colour(green)=rgb(0,255,0)
colour(cyan)=rgb(0,255,255)
colour(blue)=rgb(0,0,255)
colour(magenta)=rgb(255,0,255)
//clearing grid
for gy=0 to 19
for gx=0 to 9
grid(gx,gy).hue = 0
grid(gx,gy).active = false
next gx
next gy
//random colour
randomize timer()
gosub newblock
do
gosub removeline
//moving block right
for gy = 19 to 0 step - 1
for gx = 8 to 0 step - 1
if rightkey()= 1
if grid(gx+1,gy).hue=0 and grid(gx,gy).active = true
grid(gx+1,gy)=grid(gx,gy)
grid(gx,gy).active=false
grid(gx,gy).hue=0
endif
endif
next gx
next gy
//move block down
if downkey()= 1 then delay = 200
if downkey()= 0 then delay = 500
//moving block left
for gy = 18 to 0 step - 1
for gx = 1 to 9
if leftkey()= 1
if grid(gx-1,gy).hue=0 and grid(gx,gy).active = true
grid(gx-1,gy)=grid(gx,gy)
grid(gx,gy).active=false
grid(gx,gy).hue=0
endif
endif
next gx
next gy
//move block down
for gy = 19 to 0 step - 1
for gx = 0 to 9
if grid(gx,gy).active=true
if grid(gx,gy+1).hue=0
grid(gx,gy+1)=grid(gx,gy)
if gy = 18
grid(gx,gy+1).active=false
gosub newblock
endif
grid(gx,gy).active=false
grid(gx,gy).hue=0
else
grid(gx,gy).active=false
gosub newblock
exit
endif
endif
next gx
next gy
for gy=0 to 19
for gx=0 to 9
ink grid(gx,gy).hue,0
box screenX+(gx*size),screenY+(gy*size),screenX+(gx*size)+size,screenY+(gy*size)+size
next gx
next gy
ink rgb(255,255,255),0
line screenX-1,screenY,screenX-1,screenY+(size*20)
line screenX+1+(size*10),screenY,screenX+1+(size*10),screenY+(size*20)
line screenX-1,screenY+(size*20),screenX+1+(size*10),screenY+(size*20)
sync
wait delay
LOOP
newblock:
//random colour
block.hue = colour(rnd(6)+1)
if grid(5,0).hue = 0
grid(5,0).hue = block.hue
grid(5,0).active = true
else
text 265,300,"Game Over!"
sync
wait key
end
endif
return
//removing lines and dropping the rows down
removeline:
for gy = 19 to 0 step - 1
fullline = true
for gx = 0 to 9
if grid(gx,gy).hue=0 then fullline = false
next gx
if fullline = true
for gx = 0 to 9
grid(gx,gy).hue=-1
next gx
emptyline = true
for gx = 0 to 9
if grid(gx,gy).hue>0 then emptyline = false
next gx
if emptyline = true and gy>0
for ay = gy to 1 step - 1
for gx = 0 to 9
if grid(gx,ay).hue=-1
grid(gx,ay)=grid(gx,ay-1)
grid(gx,ay-1).hue=-1
endif
next gx
next ay
for ay = 19 to 0 step - 1
for gx = 0 to 9
if grid(gx,ay).hue=-1
grid(gx,ay).hue=0
endif
next gx
next ay
endif
endif
next gy
return
blockshape:
data 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0
Tshape:
data 2,2,2,0,0,2,0,0,0,0,0,0,0,0,0,0
Lshape:
data 3,3,3,0,0,0,3,0,0,0,0,0,0,0,0,0
Zshape:
data 4,4,0,0,0,4,4,0,0,0,0,0,0,0,0,0
any help will be greatly appreciated.