zetris: fix rotated sprite
This commit is contained in:
parent
f161168a29
commit
530a47a085
31
zetris.lua
31
zetris.lua
|
@ -27,12 +27,9 @@ function rotatedpiece()
|
|||
return currentPiece.piece
|
||||
elseif currentPiece.rotation == 1 then
|
||||
for i=1, 4 do
|
||||
points[i] = {x=currentPiece.piece[i].x,
|
||||
y=currentPiece.piece[i].y}
|
||||
--points[i].x = currentPiece.piece[i].y * -1
|
||||
--points[i].y = currentPiece.piece[i].x
|
||||
points[i].x = currentPiece.piece[i].x
|
||||
points[i].y = currentPiece.piece[i].y
|
||||
points[i] = {x=0,y=0}
|
||||
points[i].x = currentPiece.piece[i].y * -1
|
||||
points[i].y = currentPiece.piece[i].x
|
||||
end
|
||||
elseif currentPiece.rotation == 2 then
|
||||
for i=1, 4 do
|
||||
|
@ -50,7 +47,6 @@ function rotatedpiece()
|
|||
return points
|
||||
end
|
||||
|
||||
|
||||
function piecedropped()
|
||||
piece = rotatedpiece()
|
||||
point = currentPiece.position
|
||||
|
@ -88,9 +84,11 @@ function droppiece()
|
|||
end
|
||||
|
||||
function resetcurrent()
|
||||
currentPiece = { piece = pieces.t,
|
||||
currentPiece = {
|
||||
piece = pieces.t,
|
||||
position = {x = 11, y = 2},
|
||||
rotation = 0 }
|
||||
rotation = 0
|
||||
}
|
||||
end
|
||||
|
||||
function drawpiece()
|
||||
|
@ -100,14 +98,16 @@ function drawpiece()
|
|||
point = { x = (piece[i].x + origin.x) * blocksize,
|
||||
y = (piece[i].y + origin.y) * blocksize}
|
||||
|
||||
spr(piece.sprite, point.x, point.y)
|
||||
spr(currentPiece.piece.sprite, point.x, point.y)
|
||||
end
|
||||
end
|
||||
|
||||
function TIC()
|
||||
map(0,0,30,17)
|
||||
local newPosition = {x = currentPiece.position.x,
|
||||
y = currentPiece.position.y}
|
||||
local newPosition = {
|
||||
x = currentPiece.position.x,
|
||||
y = currentPiece.position.y
|
||||
}
|
||||
if btnp(2) then
|
||||
newPosition.x = newPosition.x - 1
|
||||
elseif btnp(3) then
|
||||
|
@ -117,6 +117,13 @@ function TIC()
|
|||
elseif btnp(4) then
|
||||
r = currentPiece.rotation
|
||||
currentPiece.rotation = (r+1)%4
|
||||
rpiece = rotatedpiece()
|
||||
trace('position: '..currentPiece.position.x..', '..currentPiece.position.y)
|
||||
trace('sprite: '..currentPiece.piece.sprite)
|
||||
trace('rotation: '..currentPiece.rotation)
|
||||
for i = 1, 4 do
|
||||
trace(rpiece[i].x..', '..rpiece[i].y)
|
||||
end
|
||||
end
|
||||
|
||||
if canmove(newPosition) then
|
||||
|
|
Loading…
Reference in a new issue