Started worm sprite + got the rendering sorted out

This commit is contained in:
2024-12-06 20:10:19 -06:00
parent 1f1144fb77
commit 8ae0a3cc52
4 changed files with 59 additions and 11 deletions

BIN
assets/images/worm.aseprite Normal file

Binary file not shown.

BIN
assets/images/worm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

View File

@@ -11,6 +11,25 @@ Worm.__index = Worm
local directions = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } }
local atlas = love.graphics.newImage 'assets/images/worm.png'
local wormQuads = {
love.graphics.newQuad(1 * TILE_SIZE, 1 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- head/tail
love.graphics.newQuad(0 * TILE_SIZE, 2 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- n
love.graphics.newQuad(1 * TILE_SIZE, 2 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- e
love.graphics.newQuad(2 * TILE_SIZE, 1 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- ne
love.graphics.newQuad(0 * TILE_SIZE, 1 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- s
love.graphics.newQuad(1 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- v
love.graphics.newQuad(2 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- se
nil,
love.graphics.newQuad(2 * TILE_SIZE, 2 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- w
love.graphics.newQuad(3 * TILE_SIZE, 1 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- nw
love.graphics.newQuad(0 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- h
nil,
love.graphics.newQuad(3 * TILE_SIZE, 0 * TILE_SIZE, TILE_SIZE, TILE_SIZE, atlas:getDimensions()), -- sw
}
local spriteBatch = love.graphics.newSpriteBatch(atlas)
function Worm.new(game)
setmetatable(Worm, { __index = LoveNode })
local self = setmetatable(LoveNode.new(), Worm)
@@ -46,11 +65,45 @@ end
function Worm:draw()
-- Draw worm body
love.graphics.setColor(0.88, 0.22, 0.88)
for _, node in ipairs(self.tail) do
love.graphics.setColor(1, 1, 1)
spriteBatch:clear()
for i, node in ipairs(self.tail) do
local x, y = unpack(node)
local cx, cy = x + (self.size.w / 2), y + (self.size.h / 2)
love.graphics.circle('fill', cx, cy, TILE_SIZE / 2)
if #self.tail == 1 then
-- Draw head/tail alone
spriteBatch:add(wormQuads[1], math.floor(x), math.floor(y))
else
-- Count neighbors
local spriteIndex = 0
local function findNeighbor(index)
if index < 1 or index > #self.tail then return end
local tx, ty = unpack(self.tail[index])
local dx, dy = (tx - x) / TILE_SIZE, (ty - y) / TILE_SIZE
if dx == -1 then
spriteIndex = spriteIndex + 8
elseif dx == 1 then
spriteIndex = spriteIndex + 2
end
if dy == -1 then
spriteIndex = spriteIndex + 1
elseif dy == 1 then
spriteIndex = spriteIndex + 4
end
end
findNeighbor(i - 1)
findNeighbor(i + 1)
local quad = wormQuads[spriteIndex + 1]
if quad then
spriteBatch:add(quad, math.floor(x), math.floor(y))
end
end
love.graphics.draw(spriteBatch)
end
-- Debug draw potential collisions
@@ -182,10 +235,4 @@ function Worm:_move()
end
end
--
function Worm:_checkIsStuck()
end
return Worm

View File

@@ -8,7 +8,6 @@
- Make a mouse sprite for the player
- [ ] Fix CRT bubble effect (doesn't like RS displays)
- [ ] Try replacing the Moonshine scan-line effect with the custom shader (or delete it)
- [ ] Create a worm sprite
- [ ] Create a siren sprite
- [ ] Make the maze end after 5 solves, with progressive difficulty (9x9 no enemies, increase size + enemy count each stage)
- [ ] Create a that displays in the top corner as the game goes on
@@ -17,6 +16,8 @@
# in progress
- [ ] Create a worm sprite
# complete
- [x] Set up Lua formatter