111 lines
2.2 KiB
Lua
111 lines
2.2 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)
|
|
|
|
textureGrid = textureLoad("minesweeper/grid_bg.dpi")
|
|
|
|
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 / 20) % 1
|
|
local scaleX = screenGetWidth() / textureGrid.width
|
|
local scaleY = screenGetHeight() / textureGrid.height
|
|
local u0 = t * scaleX
|
|
local v0 = t * scaleY
|
|
local u1 = scaleX + u0
|
|
local v1 = scaleY + v0
|
|
|
|
spriteBatchPush(textureGrid,
|
|
0, 0,
|
|
screenGetWidth(), screenGetHeight(),
|
|
colorWhite(),
|
|
u0, v0,
|
|
u1, v1
|
|
)
|
|
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]
|
|
)
|
|
break
|
|
end
|
|
end
|
|
spriteBatchFlush()
|
|
|
|
cameraPopMatrix()
|
|
end |