Asset refactor
This commit is contained in:
44
assets/scene/main_menu/main_menu.lua
Normal file
44
assets/scene/main_menu/main_menu.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
module('spritebatch')
|
||||
module('camera')
|
||||
module('color')
|
||||
module('ui')
|
||||
module('screen')
|
||||
module('time')
|
||||
module('text')
|
||||
module('tileset')
|
||||
module('texture')
|
||||
module('input')
|
||||
module('shader')
|
||||
module('locale')
|
||||
|
||||
screenSetBackground(colorCornflowerBlue())
|
||||
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||
|
||||
function sceneDispose()
|
||||
end
|
||||
|
||||
function sceneUpdate()
|
||||
end
|
||||
|
||||
function sceneRender()
|
||||
-- Update camera
|
||||
camera.top = screenGetHeight()
|
||||
camera.right = screenGetWidth()
|
||||
|
||||
shaderBind(SHADER_UNLIT)
|
||||
proj = cameraGetProjectionMatrix(camera)
|
||||
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)
|
||||
view = cameraGetViewMatrix(camera)
|
||||
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view)
|
||||
|
||||
-- shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil)
|
||||
-- spriteBatchPush(
|
||||
-- 32, 32,
|
||||
-- 64, 64,
|
||||
-- colorWhite()
|
||||
-- )
|
||||
-- spriteBatchFlush()
|
||||
|
||||
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
|
||||
spriteBatchFlush()
|
||||
end
|
||||
@@ -1,264 +0,0 @@
|
||||
module('spritebatch')
|
||||
module('camera')
|
||||
module('color')
|
||||
module('ui')
|
||||
module('screen')
|
||||
module('time')
|
||||
module('glm')
|
||||
module('text')
|
||||
module('tileset')
|
||||
module('texture')
|
||||
module('input')
|
||||
module('shader')
|
||||
|
||||
CELL_STATE_DEFAULT = 0
|
||||
CELL_STATE_HOVER = 1
|
||||
CELL_STATE_DOWN = 2
|
||||
CELL_STATE_DISABLED = 3
|
||||
|
||||
screenSetBackground(colorCornflowerBlue())
|
||||
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||
|
||||
-- tilesetUi = tilesetGetByName("ui")
|
||||
-- textureUi = textureLoad(tilesetUi.texture)
|
||||
|
||||
-- tilesetBorder = tilesetGetByName("border")
|
||||
-- textureBorder = textureLoad(tilesetBorder.texture)
|
||||
|
||||
-- textureGrid = textureLoad("minesweeper/grid_bg.dpi")
|
||||
|
||||
-- tilesetCell = tilesetGetByName("cell")
|
||||
-- textureCell = textureLoad(tilesetCell.texture)
|
||||
-- cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5)
|
||||
-- cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
|
||||
-- cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
|
||||
-- cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
|
||||
|
||||
-- sweepwerCols = 10
|
||||
-- sweeperRows = 14
|
||||
|
||||
-- mouseX = -1
|
||||
-- mouseY = -1
|
||||
-- centerX = 0
|
||||
-- centerY = 0
|
||||
-- boardWidth = sweepwerCols * tilesetCell.tileWidth
|
||||
-- boardHeight = sweeperRows * tilesetCell.tileHeight
|
||||
|
||||
-- i = 0
|
||||
-- cells = {}
|
||||
-- for y = 1, sweeperRows do
|
||||
-- for x = 1, sweepwerCols do
|
||||
-- cells[i] = CELL_STATE_DEFAULT
|
||||
-- i = i + 1
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function cellDraw(x, y, type)
|
||||
local slice = cellSliceDefault
|
||||
if type == CELL_STATE_HOVER then
|
||||
slice = cellSliceHover
|
||||
elseif type == CELL_STATE_DOWN then
|
||||
slice = cellSliceDown
|
||||
elseif type == CELL_STATE_DISABLED then
|
||||
slice = cellSliceDisabled
|
||||
end
|
||||
|
||||
spriteBatchPush(
|
||||
x, y,
|
||||
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||
colorWhite(),
|
||||
slice.u0, slice.v0,
|
||||
slice.u1, slice.v1
|
||||
)
|
||||
end
|
||||
|
||||
function backgroundDraw()
|
||||
local t = (TIME.time / 40) % 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 borderDraw(x, y, innerWidth, innerHeight)
|
||||
-- Top Left
|
||||
local uv = tilesetPositionGetUV(tilesetBorder, 0, 0)
|
||||
spriteBatchPush(textureBorder,
|
||||
x - tilesetBorder.tileWidth, y - tilesetBorder.tileWidth,
|
||||
x, y,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Top Right
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 10, 0)
|
||||
spriteBatchPush(textureBorder,
|
||||
x + innerWidth, y - tilesetBorder.tileHeight,
|
||||
x + innerWidth + tilesetBorder.tileWidth, y,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Bottom Left
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 0, 10)
|
||||
spriteBatchPush(textureBorder,
|
||||
x - tilesetBorder.tileWidth, y + innerHeight,
|
||||
x, y + innerHeight + tilesetBorder.tileHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Bottom Right
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 10, 10)
|
||||
spriteBatchPush(textureBorder,
|
||||
x + innerWidth, y + innerHeight,
|
||||
x + innerWidth + tilesetBorder.tileWidth, y + innerHeight + tilesetBorder.tileHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Top
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 1, 0)
|
||||
spriteBatchPush(textureBorder,
|
||||
x, y - tilesetBorder.tileHeight,
|
||||
x + innerWidth, y,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Bottom
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 1, 10)
|
||||
spriteBatchPush(textureBorder,
|
||||
x, y + innerHeight,
|
||||
x + innerWidth, y + innerHeight + tilesetBorder.tileHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Left
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 0, 1)
|
||||
spriteBatchPush(textureBorder,
|
||||
x - tilesetBorder.tileWidth, y,
|
||||
x, y + innerHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
|
||||
-- Right
|
||||
uv = tilesetPositionGetUV(tilesetBorder, 10, 1)
|
||||
spriteBatchPush(textureBorder,
|
||||
x + innerWidth, y,
|
||||
x + innerWidth + tilesetBorder.tileWidth, y + innerHeight,
|
||||
colorWhite(),
|
||||
uv.u0, uv.v0,
|
||||
uv.u1, uv.v1
|
||||
)
|
||||
end
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
function sceneDispose()
|
||||
end
|
||||
|
||||
function sceneUpdate()
|
||||
x = x + inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT)
|
||||
y = y + inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
|
||||
end
|
||||
|
||||
function sceneRender()
|
||||
-- Update camera
|
||||
camera.bottom = 0
|
||||
camera.top = screenGetHeight()
|
||||
camera.right = screenGetWidth()
|
||||
|
||||
shaderBind(SHADER_UNLIT)
|
||||
proj = cameraGetProjectionMatrix(camera)
|
||||
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)
|
||||
view = cameraGetViewMatrix(camera)
|
||||
shaderSetMatrix(SHADER_UNLIT, SHADER_UNLIT_VIEW, view)
|
||||
|
||||
shaderSetTexture(SHADER_UNLIT, SHADER_UNLIT_TEXTURE, nil)
|
||||
spriteBatchPush(
|
||||
x, y,
|
||||
x + 32, y + 32,
|
||||
colorWhite()
|
||||
)
|
||||
spriteBatchFlush()
|
||||
|
||||
textDraw(10, 10, "Hello World\nHow are you?", colorRed())
|
||||
spriteBatchFlush()
|
||||
|
||||
-- Update mouse position
|
||||
-- if INPUT_POINTER then
|
||||
-- mouseX = inputGetValue(INPUT_ACTION_POINTERX) * screenGetWidth()
|
||||
-- mouseY = inputGetValue(INPUT_ACTION_POINTERY) * screenGetHeight()
|
||||
|
||||
-- -- Draw cursor
|
||||
-- spriteBatchPush(
|
||||
-- nil,
|
||||
-- mouseX - 2, mouseY - 2,
|
||||
-- mouseX + 2, mouseY + 2,
|
||||
-- colorRed(),
|
||||
-- 0, 0,
|
||||
-- 1, 1
|
||||
-- )
|
||||
-- end
|
||||
|
||||
|
||||
-- textDraw(10, 10, "Hello World")
|
||||
|
||||
-- centerX = math.floor(screenGetWidth() / 2)
|
||||
-- centerY = math.floor(screenGetHeight() / 2)
|
||||
|
||||
-- Draw elements
|
||||
-- backgroundDraw()
|
||||
-- borderDraw(
|
||||
-- centerX - (boardWidth / 2), centerY - (boardHeight / 2),
|
||||
-- boardWidth, boardHeight
|
||||
-- )
|
||||
|
||||
-- i = 0
|
||||
-- -- Foreach cell
|
||||
-- local offX = centerX - (boardWidth / 2)
|
||||
-- local offY = centerY - (boardHeight / 2)
|
||||
-- for y = 0, sweeperRows - 1 do
|
||||
-- for x = 0, sweepwerCols - 1 do
|
||||
-- i = y * sweepwerCols + x
|
||||
|
||||
-- -- Hovered
|
||||
-- if
|
||||
-- cells[i] == CELL_STATE_DEFAULT and
|
||||
-- mouseX >= x * tilesetCell.tileWidth + offX and mouseX < (x + 1) * tilesetCell.tileWidth + offX and
|
||||
-- mouseY >= y * tilesetCell.tileHeight + offY and mouseY < (y + 1) * tilesetCell.tileHeight + offY
|
||||
-- then
|
||||
-- cells[i] = CELL_STATE_HOVER
|
||||
-- else
|
||||
-- cells[i] = CELL_STATE_DEFAULT
|
||||
-- end
|
||||
|
||||
-- cellDraw(
|
||||
-- x * tilesetCell.tileWidth + offX,
|
||||
-- y * tilesetCell.tileHeight + offY,
|
||||
-- cells[i]
|
||||
-- )
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
Reference in New Issue
Block a user