Sweeper
All checks were successful
Build Dusk / run-tests (push) Successful in 1m28s
Build Dusk / build-linux (push) Successful in 1m33s
Build Dusk / build-psp (push) Successful in 1m53s
Build Dusk / build-dolphin (push) Successful in 2m19s

This commit is contained in:
2026-02-10 21:06:09 -06:00
parent e1f08b07aa
commit b37e5f45ca
13 changed files with 374 additions and 32 deletions

View File

@@ -48,7 +48,12 @@ else
inputBind("q", INPUT_ACTION_CANCEL)
inputBind("escape", INPUT_ACTION_RAGEQUIT)
end
end
if INPUT_POINTER then
inputBind("mouse_x", INPUT_ACTION_POINTERX)
inputBind("mouse_y", INPUT_ACTION_POINTERY)
end
end
localeSet(DUSK_LOCALE_EN_US)

View File

@@ -5,4 +5,5 @@
add_asset(TILESET ui.png type=PALETTIZED tileWidth=8 tileHeight=8)
add_asset(TILESET cell.png type=PALETTIZED tileWidth=8 tileHeight=8)
add_asset(TILESET border.png type=PALETTIZED tileWidth=8 tileHeight=8)
add_asset(IMAGE grid_bg.png type=PALETTIZED)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 B

After

Width:  |  Height:  |  Size: 123 B

View File

@@ -8,6 +8,7 @@ module('glm')
module('text')
module('tileset')
module('texture')
module('input')
CELL_STATE_DEFAULT = 0
CELL_STATE_HOVER = 1
@@ -20,30 +21,46 @@ 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)
cellSliceDefault = tilesetPositionGetUV(tilesetCell, 0, 4)
-- cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
-- cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
-- cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5)
cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
width = 10
height = 14
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, height do
for x = 1, width do
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)
slice = cellSliceDefault
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(textureCell,
x, y,
@@ -55,7 +72,7 @@ function cellDraw(x, y, type)
end
function backgroundDraw()
local t = (TIME.time / 20) % 1
local t = (TIME.time / 40) % 1
local scaleX = screenGetWidth() / textureGrid.width
local scaleY = screenGetHeight() / textureGrid.height
local u0 = t * scaleX
@@ -72,6 +89,88 @@ function backgroundDraw()
)
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
function sceneDispose()
end
@@ -79,26 +178,53 @@ function sceneUpdate()
end
function sceneRender()
-- UI
-- Update camera
cameraPushMatrix(camera)
camera.bottom = screenGetHeight()
camera.right = screenGetWidth()
cellDraw(0, 0, 0)
-- backgroundDraw()
-- Update mouse position
if INPUT_POINTER then
mouseX = inputGetValue(INPUT_ACTION_POINTERX) * screenGetWidth()
mouseY = inputGetValue(INPUT_ACTION_POINTERY) * screenGetHeight()
end
-- 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
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
spriteBatchFlush()
cameraPopMatrix()