setscreen ("graphics:300;600,position:center;center,nobuttonbar,offscreenonly,title:..." + repeat (" ", 19) + "TETRIS" + repeat (" ", 20))
var piece : array 1 .. 7, 1 .. 4 of int := init (1, 2, 3, 5, 1, 2, 4, 7, 1, 2, 3, 4, 1, 2, 4, 6, 1, 2, 4, 5, 1, 2, 3, 6, 1, 3, 4, 5)
var shape : array 1 .. 7, 1 .. 3 of int := init (0, 0, 0, 90, 90, 15, 180, 180, 15, 270, 270, 15, 90, 180, 30, 270, 180, 30, 90, 90, 30)
var box, col : array - 3 .. 12, -3 .. 20 of int
var blockx, blocky, newblockx, newblocky, nextblockx, nextblocky : array 1 .. 4 of int
var chars : array char of boolean
var x, y, pos, p, np, inc, score := 0
var gameOver := false
colourback (7)
colour (0)
for m : 0 .. 9
for n : 0 .. 17
box (m, n) := 0
end for
end for
for m : -3 .. 12
for n : 1 .. 3
box (m, 0 - n) := -1
box (m, 17 + n) := -1
end for
end for
for m : 1 .. 3
for n : -3 .. 20
box (0 - m, n) := -1
box (9 + m, n) := -1
end for
end for
randint (p, 1, 7)
randint (np, 1, 7)
x := 120
y := 510
fcn rsin (n : int) : int
result round (sind (n))
end rsin
fcn rcos (n : int) : int
result round (cosd (n))
end rcos
proc assign
for m : 0 .. 9
for n : 0 .. 17
if box (m, n) > 0 then
box (m, n) := 0
end if
end for
end for
for n : 1 .. 4
blockx (n) := (rsin (pos + shape (piece (p, n), 1)) + rsin (pos + shape (piece (p, n), 2))) * shape (piece (p, n), 3) + x
blocky (n) := (rcos (pos + shape (piece (p, n), 1)) + rcos (pos + shape (piece (p, n), 2))) * shape (piece (p, n), 3) + y
if box (blockx (n) div 30, blocky (n) div 30) = -1 then
gameOver := true
exit
else
box (blockx (n) div 30, blocky (n) div 30) := 1
end if
end for
for m : 0 .. 9
for n : 0 .. 17
if box (m, n) > 0 then
col (m, n) := p
end if
end for
end for
end assign
proc output
cls
for m : 0 .. 9
for n : 0 .. 17
if box (m, n) not= 0 then
drawfillbox (m * 30, n * 30, m * 30 + 30, n * 30 + 30, col (m, n))
drawbox (m * 30, n * 30, m * 30 + 30, n * 30 + 30, 0)
end if
end for
end for
drawline (0, 540, 300, 540, 0)
put "Score : ", score
locate (1, 14)
put "Next"
locate (2, 14)
put "Piece"
drawline (170, 540, 170, 600, 0)
for n : 1 .. 4
nextblockx (n) := (rsin (shape (piece (np, n), 1)) + rsin (shape (piece (np, n), 2))) * shape (piece (np, n), 3) + 200
nextblocky (n) := (rcos (shape (piece (np, n), 1)) + rcos (shape (piece (np, n), 2))) * shape (piece (np, n), 3) + 570
drawfillbox (nextblockx (n), nextblocky (n), nextblockx (n) + 30, nextblocky (n) + 30, np)
drawbox (nextblockx (n), nextblocky (n), nextblockx (n) + 30, nextblocky (n) + 30, 0)
end for
View.Update
delay (100)
end output
fcn moveOk (dirx, diry : int) : boolean
var numOk := 0
for n : 1 .. 4
if box (blockx (n) div 30 + dirx, blocky (n) div 30 + diry) not= -1 then
numOk += 1
end if
end for
if numOk = 4 then
result true
else
result false
end if
end moveOk
fcn rotateOk : boolean
var numOk := 0
pos += 90
for n : 1 .. 4
newblockx (n) := (rsin (pos + shape (piece (p, n), 1)) + rsin (pos + shape (piece (p, n), 2))) * shape (piece (p, n), 3) + x
newblocky (n) := (rcos (pos + shape (piece (p, n), 1)) + rcos (pos + shape (piece (p, n), 2))) * shape (piece (p, n), 3) + y
end for
pos -= 90
for n : 1 .. 4
if box (newblockx (n) div 30, newblocky (n) div 30) not= -1 then
numOk += 1
end if
end for
if numOk = 4 then
result true
else
result false
end if
end rotateOk
proc movement
Input.KeyDown (chars)
if chars (' ') and p not= 1 and rotateOk then
pos += 90
assign
end if
inc += 1
if inc mod 5 = 1 and moveOk (0, -1) then
y -= 30
assign
elsif inc mod 5 = 1 then
for n : 1 .. 4
box (blockx (n) div 30, blocky (n) div 30) := -1
col (blockx (n) div 30, blocky (n) div 30) := p
end for
p := np
randint (np, 1, 7)
for n : 1 .. 4
x := 120
y := 510
pos := 0
end for
assign
end if
if chars (chr (205)) and moveOk (1, 0) then
x += 30
assign
elsif chars (chr (203)) and moveOk (-1, 0) then
x -= 30
assign
end if
if chars (chr (208)) and moveOk (0, -1) then
y -= 30
assign
end if
end movement
proc comprow
var linesum : array 0 .. 17 of int
for N : 0 .. 17
loop
for n : 0 .. 17
linesum (n) := 0
end for
for m : 0 .. 9
for n : 0 .. 17
linesum (n) += box (m, n)
end for
end for
if linesum (N) = -10 then
score += 10
for m : 0 .. 9
for n : N .. 16
box (m, n) := box (m, n + 1)
end for
end for
for n : 0 .. 9
box (n, 17) := 0
end for
else
exit
end if
end loop
end for
end comprow
loop
assign
output
exit when gameOver
movement
comprow
end loop
cls
drawline (0, 540, 300, 540, 0)
put "Score : ", score
locate (1, 14)
put "Next"
locate (2, 14)
put "Piece"
drawline (170, 540, 170, 600, 0)
View.Update
delay (100)
Font.Draw ("Game Over", 25, 300, Font.New ("sanserif:36"), 0) |