Add Zetris
This commit is contained in:
parent
02d0cad4dd
commit
f161168a29
186
zetris.lua
Normal file
186
zetris.lua
Normal file
|
@ -0,0 +1,186 @@
|
|||
-- title: Zetris
|
||||
-- author: Pascal Batty
|
||||
-- desc: First training game
|
||||
-- script: lua
|
||||
|
||||
blocksize=8
|
||||
bgspriteof=-240
|
||||
|
||||
pieces = {
|
||||
t={sprite=256,
|
||||
{x=0, y=0},
|
||||
{x=-1, y=0},
|
||||
{x=1, y=0},
|
||||
{x=0, y=-1}
|
||||
}
|
||||
}
|
||||
|
||||
-- GAME STATE
|
||||
currentPiece = { piece = pieces.t,
|
||||
position = {x = 11, y = 2},
|
||||
rotation = 0
|
||||
}
|
||||
|
||||
function rotatedpiece()
|
||||
points = {}
|
||||
if currentPiece.rotation == 0 then
|
||||
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
|
||||
end
|
||||
elseif currentPiece.rotation == 2 then
|
||||
for i=1, 4 do
|
||||
points[i] = {x=0,y=0}
|
||||
points[i].x = currentPiece.piece[i].x * -1
|
||||
points[i].y = currentPiece.piece[i].y * -1
|
||||
end
|
||||
elseif currentPiece.rotation == 3 then
|
||||
for i=1, 4 do
|
||||
points[i] = {x=0,y=0}
|
||||
points[i].x = currentPiece.piece[i].y
|
||||
points[i].y = currentPiece.piece[i].x * -1
|
||||
end
|
||||
end
|
||||
return points
|
||||
end
|
||||
|
||||
|
||||
function piecedropped()
|
||||
piece = rotatedpiece()
|
||||
point = currentPiece.position
|
||||
for i=1, 4 do
|
||||
x=(point.x + piece[i].x)
|
||||
y=(point.y + piece[i].y)
|
||||
if mget(x, y+1) ~= 0 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function canmove(point)
|
||||
piece = rotatedpiece()
|
||||
for i=1, 4 do
|
||||
x=(point.x + piece[i].x)
|
||||
y=(point.y + piece[i].y)
|
||||
if mget(x, y) ~= 0 then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function droppiece()
|
||||
piece = rotatedpiece()
|
||||
point = currentPiece.position
|
||||
sprite = piece.sprite + bgspriteof
|
||||
for i=1, 4 do
|
||||
x=(point.x + piece[i].x)
|
||||
y=(point.y + piece[i].y)
|
||||
mset(x, y, 16)
|
||||
end
|
||||
end
|
||||
|
||||
function resetcurrent()
|
||||
currentPiece = { piece = pieces.t,
|
||||
position = {x = 11, y = 2},
|
||||
rotation = 0 }
|
||||
end
|
||||
|
||||
function drawpiece()
|
||||
piece = rotatedpiece()
|
||||
origin = currentPiece.position
|
||||
for i = 1, 4 do
|
||||
point = { x = (piece[i].x + origin.x) * blocksize,
|
||||
y = (piece[i].y + origin.y) * blocksize}
|
||||
|
||||
spr(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}
|
||||
if btnp(2) then
|
||||
newPosition.x = newPosition.x - 1
|
||||
elseif btnp(3) then
|
||||
newPosition.x = newPosition.x + 1
|
||||
elseif btnp(1) then
|
||||
newPosition.y = newPosition.y + 1
|
||||
elseif btnp(4) then
|
||||
r = currentPiece.rotation
|
||||
currentPiece.rotation = (r+1)%4
|
||||
end
|
||||
|
||||
if canmove(newPosition) then
|
||||
currentPiece.position = newPosition
|
||||
elseif piecedropped() then
|
||||
droppiece()
|
||||
resetcurrent()
|
||||
end
|
||||
|
||||
drawpiece()
|
||||
end
|
||||
|
||||
-- <TILES>
|
||||
-- 001:0ffffff0ffffffffffffffffffffffffffffffffffffffffffffffff0ffffff0
|
||||
-- 016:1111111190000001901111019019910190199101901111019000000199999999
|
||||
-- 017:66666666e0000006e0666606e06ee606e06ee606e0666606e0000006eeeeeeee
|
||||
-- 018:bbbbbbbb3000000b30bbbb0b30b33b0b30b33b0b30bbbb0b3000000b33333333
|
||||
-- 019:22222222a0000002a0222202a02aa202a02aa202a0222202a0000002aaaaaaaa
|
||||
-- 020:44444444c0000004c0444404c04cc404c04cc404c0444404c0000004cccccccc
|
||||
-- 021:dddddddd5000000d50dddd0d50d55d0d50d55d0d50dddd0d5000000d55555555
|
||||
-- 022:8888888870000008708888087087780870877808708888087000000877777777
|
||||
-- </TILES>
|
||||
|
||||
-- <SPRITES>
|
||||
-- 000:1111111190000001901111019019910190199101901111019000000199999999
|
||||
-- 001:66666666e0000006e0666606e06ee606e06ee606e0666606e0000006eeeeeeee
|
||||
-- 002:bbbbbbbb3000000b30bbbb0b30b33b0b30b33b0b30bbbb0b3000000b33333333
|
||||
-- 003:22222222a0000002a0222202a02aa202a02aa202a0222202a0000002aaaaaaaa
|
||||
-- 004:44444444c0000004c0444404c04cc404c04cc404c0444404c0000004cccccccc
|
||||
-- 005:dddddddd5000000d50dddd0d50d55d0d50d55d0d50dddd0d5000000d55555555
|
||||
-- 006:8888888870000008708888087087780870877808708888087000000877777777
|
||||
-- </SPRITES>
|
||||
|
||||
-- <MAP>
|
||||
-- 000:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 001:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 002:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 003:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 004:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 005:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 006:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 007:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 008:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 009:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 010:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 011:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 012:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 013:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 014:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 015:000000000000100000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- 016:000000000000101010101010101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
-- </MAP>
|
||||
|
||||
-- <WAVES>
|
||||
-- 000:00000000ffffffff00000000ffffffff
|
||||
-- 001:0123456789abcdeffedcba9876543210
|
||||
-- 002:0123456789abcdef0123456789abcdef
|
||||
-- </WAVES>
|
||||
|
||||
-- <SFX>
|
||||
-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
|
||||
-- </SFX>
|
||||
|
||||
-- <PALETTE>
|
||||
-- 000:140c1ceaea30555dd64c794cc6810834a1a5d04648a5249dca71ced2ae2c3030956daa2c7555286dd6e2ba2418d6dad2
|
||||
-- </PALETTE>
|
||||
|
Loading…
Reference in a new issue