Hello Löve forum. I'm currently trying to do a tetris clone in Löve to learn how Löve and Lua works.
I was currently trying to get the different parts of the tetromino so i saved it into a 16 size table that shows the value.
Code: Select all
iTetromino= {0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0}
Code: Select all
function getNewTetromino()
local t ={}
t.xPos =PLAYFIELD_WIDTH/2
t.yPos = 0
local blockType = love.math.random(7)
t.block = zTetromino
if blockType == 1 then t.block = iTetromino
elseif blockType == 2 then t.block = oTetromino
elseif blockType == 3 then t.block = tTetromino
elseif blockType == 4 then t.block = jTetromino
elseif blockType == 5 then t.block = lTetromino
elseif blockType == 6 then t.block = sTetromino
else t.block = zTetromino end
return t
end
Code: Select all
if tetromino.block[x+y*4] > 0 then
To make the game not crash I had to add so it won't run the code if there is a problem but it never runs then.
Code: Select all
not tetromino.block[x+y*4] == nil
I know that it might be vauge so here are the examples when it doesn't work at all.
Code: Select all
function fallUpdate(tetromino)
tetromino.yPos = tetromino.yPos +1
TetrominoFallTimer = FALL_SPEED
if checkTetrominoCollision(tetromino,tetromino.xPos,tetromino.yPos+1,g_playfield) then
for x = 0,3 do
for y = 0,3 do
if not tetromino.block[x+y*4] == nil and tetromino.block[x+y*4] > 0 then
playfield.blocks[tetromino.xPos+x][tetromino.yPos+y] = tetromino.block[x+y*4]
end
end
end
getNextTetromino()
end
end
Code: Select all
function checkTetrominoCollision(tetromino,xOffset,yOffset,playfield)
if xOffset <0 or xOffset>7 or yOffset>17 then
return true
end
for x = 0,3 do
for y = 0,3 do
if not tetromino.block[x+y*4] == nil and tetromino.block[x+y*4] > 0 then
if playfield.blocks[xOffset+x][yOffset+y] > 0 then
return true
end
end
end
end
return false
end
Code: Select all
function drawTetromino(xOffset,yOffset,tetromino)
for x = 0,3 do
for y = 0,3 do
-- love.graphics.print("Test", x, y)
-- drawBlock(2,2,2)
drawBlock(tetromino.block[x+y*4],xOffset+ math.floor(x+tetromino.xPos)*BLOCK_WIDTH,
yOffset+math.floor(y+tetromino.yPos)*BLOCK_HEIGHT)
end
end
end