120 lines
2.7 KiB
Lua
120 lines
2.7 KiB
Lua
module('spritebatch')
|
|
module('camera')
|
|
module('color')
|
|
module('ui')
|
|
module('screen')
|
|
module('time')
|
|
module('glm')
|
|
module('text')
|
|
module('tileset')
|
|
module('texture')
|
|
|
|
CELL_STATE_DEFAULT = 0
|
|
CELL_STATE_HOVER = 1
|
|
CELL_STATE_DOWN = 2
|
|
CELL_STATE_DISABLED = 3
|
|
|
|
screenSetBackground(colorBlack())
|
|
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
|
|
|
tilesetUi = tilesetGetByName("ui")
|
|
textureUi = textureLoad(tilesetUi.texture)
|
|
|
|
tilesetGrid = tilesetGetByName("grid")
|
|
textureGrid = textureLoad(tilesetGrid.texture)
|
|
gridPiece = tilesetPositionGetUV(tilesetGrid, 0, 0)
|
|
gridSlice = tilesetPositionGetUV(tilesetGrid, 11, 3)
|
|
|
|
tilesetCell = tilesetGetByName("cell")
|
|
textureCell = textureLoad(tilesetCell.texture)
|
|
cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
|
|
cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5)
|
|
cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
|
|
cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
|
|
|
|
width = 10
|
|
height = 14
|
|
|
|
i = 0
|
|
cells = {}
|
|
for y = 1, height do
|
|
for x = 1, width do
|
|
cells[i] = CELL_STATE_DEFAULT
|
|
i = i + 1
|
|
end
|
|
end
|
|
|
|
function cellDraw(x, y, type)
|
|
if type == CELL_STATE_HOVER then
|
|
slice = cellSliceHover
|
|
elseif type == CELL_STATE_DOWN then
|
|
slice = cellSliceDown
|
|
elseif type == CELL_STATE_DISABLED then
|
|
slice = cellSliceDisabled
|
|
else
|
|
slice = cellSliceDefault
|
|
end
|
|
|
|
spriteBatchPush(textureCell,
|
|
x, y,
|
|
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
|
colorWhite(),
|
|
slice.u0, slice.v0,
|
|
slice.u1, slice.v1
|
|
)
|
|
end
|
|
|
|
function backgroundDraw()
|
|
local t = (TIME.time * 3) % 1
|
|
local offXStart = gridPiece.u1 * t
|
|
local offYStart = gridPiece.v1 * t
|
|
local offXEnd = offXStart + gridPiece.u1
|
|
local offYEnd = offYStart + gridPiece.v1
|
|
|
|
-- Tile background
|
|
local cols = math.ceil(screenGetWidth() / tilesetGrid.tileWidth)
|
|
local rows = math.ceil(screenGetHeight() / tilesetGrid.tileHeight)
|
|
|
|
for y = 0, rows do
|
|
for x = 0, cols do
|
|
spriteBatchPush(
|
|
textureGrid,
|
|
x * tilesetGrid.tileWidth, y * tilesetGrid.tileHeight,
|
|
(x + 1) * tilesetGrid.tileWidth, (y + 1) * tilesetGrid.tileHeight,
|
|
colorWhite(),
|
|
gridSlice.u0 + offXStart, gridSlice.v0 + offYStart,
|
|
gridSlice.u1 + offXEnd, gridSlice.v1 + offYEnd
|
|
)
|
|
end
|
|
end
|
|
end
|
|
|
|
function sceneDispose()
|
|
end
|
|
|
|
function sceneUpdate()
|
|
end
|
|
|
|
function sceneRender()
|
|
-- UI
|
|
cameraPushMatrix(camera)
|
|
camera.bottom = screenGetHeight()
|
|
camera.right = screenGetWidth()
|
|
|
|
backgroundDraw()
|
|
|
|
offsetX = 32
|
|
offsetY = 32
|
|
for y = 0, height - 1 do
|
|
for x = 0, width - 1 do
|
|
cellDraw(
|
|
x * tilesetCell.tileWidth + offsetX,
|
|
y * tilesetCell.tileHeight + offsetY,
|
|
cells[i]
|
|
)
|
|
end
|
|
end
|
|
spriteBatchFlush()
|
|
|
|
cameraPopMatrix()
|
|
end |