i am currently doing a project which is tetris and i need a bit of help can anyone steer me in the right direction with this?
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 integer
endtype
row = 2
true = 1 : false = 0
global dim grid (10,20) as tetromino
global block as tetromino
dim shape (3,2) 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 > 0 //= 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 = 19 to 0 step - 1
for gx = 1 to 9
if leftkey()= 1
if grid(gx-1,gy).hue=0 and grid(gx,gy).active > 0 //= true
grid(gx-1,gy)=grid(gx,gy)
grid(gx,gy).active=false
grid(gx,gy).hue=0
endif
endif
next gx
next gy
//new block
nb=false
//move block down
for gy = 19 to 0 step - 1
for gx = 0 to 9
if grid(gx,gy).active >0 //=true your blocks have active set to 2, 3,4 etc
if grid(gx,gy+1).hue=0
grid(gx,gy+1)=grid(gx,gy)
if gy = 19
grid(gx,gy+1).active=false
nb=true
endif
grid(gx,gy).active=false
grid(gx,gy).hue=0
else
grid(gx,gy).active=false
nb=true
//exit //?????
endif
endif
next gx
next gy
if nb = true
gosub newblock
//introducing 2nd part new shape
else
if row = 1
gx = 4
for sx = 0 to 2
if shape(sx,row).hue <> 0
if grid(gx+sx,0).hue = 0
grid(gx+sx,0).hue = shape(sx,row).hue
grid(gx+sx,0).active = shape(sx,row).active
else
text 265,300,"Game Over! 112"
sync
wait key
sync:wait key
end
endif
endif
inc gx
next sx
inc row //inc not dec row
endif //endif row
endif //another endif
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
rcolour = colour(rnd(6)+1)
rshape = (rnd(3)+1)
row = 1
select rshape
case 1 : restore blockshape : endcase
case 2 : restore Tshape : endcase
case 3 : restore Lshape : endcase
case 4 : restore Zshape : endcase
endselect
for gy = 0 to 1
for gx = 0 to 2
read shape(gx,gy).active
if shape(gx,gy).active <> 9
shape(gx,gy).hue=rcolour
else
shape(gx,gy).hue=0
endif
next gx
next gy
gx = 4
if row > -1
for sx = 0 to 2
if shape(sx,row).hue <> 0
if grid(gx+sx,0).hue = 0
grid(gx+sx,0).hue = shape(sx,row).hue
grid(gx+sx,0).active = shape(sx,row).active
else
text 265,300,"Game Over! 174"
sync
wait key
sync:wait key
end
endif
else
grid(gx,0).active = true
endif
inc gx
next sx
// dec row //not needed
endif //endif row
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 2,2,9,2,2,9
Tshape:
data 2,2,2,9,2,9
Lshape:
data 3,3,3,9,9,3
Zshape:
data 4,4,9,9,4,4
atm the shapes are sprawled over my interface