diff --git a/generated/assets.lua b/generated/assets.lua index c6051b0..920d609 100644 --- a/generated/assets.lua +++ b/generated/assets.lua @@ -57,6 +57,14 @@ SmallSandTrap = love.graphics.newImage("assets/images/SmallSandTrap.png") ---@type love.Texture StartButton = love.graphics.newImage("assets/images/StartButton.png") +-- luacheck: ignore +---@type love.Texture +TeleporterInactive = love.graphics.newImage("assets/images/TeleporterInactive.png") + +-- luacheck: ignore +---@type love.Texture +Teleporter = love.graphics.newImage("assets/images/Teleporter.png") + diff --git a/generated/filter-types.lua b/generated/filter-types.lua index 9f7a508..26d8329 100644 --- a/generated/filter-types.lua +++ b/generated/filter-types.lua @@ -22,10 +22,6 @@ T = { marker = SOME_TABLE, ---@type fun(self) SelfFunction = function() end, - ---@type pd_image - pd_image = SOME_TABLE, - ---@type pd_font - pd_font = SOME_TABLE, ---@type AnyComponent AnyComponent = SOME_TABLE, diff --git a/generated/filter-types.lua2p b/generated/filter-types.lua2p index a5c4ccd..8a40092 100644 --- a/generated/filter-types.lua2p +++ b/generated/filter-types.lua2p @@ -70,11 +70,7 @@ T = { str = "", marker = SOME_TABLE, ---@type fun(self) - SelfFunction = function() end, - ---@type pd_image - pd_image = SOME_TABLE, - ---@type pd_font - pd_font = SOME_TABLE,!!(dumpTypeObjects()) + SelfFunction = function() end,!!(dumpTypeObjects()) } ---@generic T diff --git a/main.lua b/main.lua index dbc859b..c47fa7f 100644 --- a/main.lua +++ b/main.lua @@ -14,7 +14,6 @@ local width, height = love.graphics.getWidth(), love.graphics.getHeight() local squareSide = 80 local tileSize = math.floor(squareSide * 1.2) -local marginSize = 10 local squareSize = { x = squareSide, y = squareSide } CursorMask = 1 @@ -126,7 +125,7 @@ Scenarios = { current.below = yxGrid[1][x] end if x == xCount then - -- Connect last entry to first Entry + -- Connect last column to first column current.toRight = yxGrid[y][1] yxGrid[y][1].toLeft = current end @@ -207,8 +206,17 @@ Scenarios = { } }) addClickable({ - drawAsSprite = Ramp, - spriteAfterEffect = Ramp, + drawAsText = { + text = "ROCK", + }, + effectsToApply = { + slowsTo = { x = -1, y = -1 }, + } + }) + addClickable({ + drawAsText = { + text = "RAMP", + }, effectsToApply = { fliesFor = 1, slowsBy = { x = 3, y = 3 }, @@ -218,7 +226,7 @@ Scenarios = { drawAsSprite = GolferRight, spriteAfterEffect = GolferRightActivated, effectsToApply = { - movement = { x = 8, y = 0 }, + movement = { x = 5, y = 0 }, }, }) addClickable({ @@ -228,12 +236,30 @@ Scenarios = { movement = { x = 0, y = 6 }, }, }) + local teleporterA = addClickable({ + drawAsSprite = Teleporter, + spriteAfterEffect = TeleporterInactive, + effectsToApply = {} + }) + local teleporterB = addClickable({ + drawAsSprite = Teleporter, + spriteAfterEffect = TeleporterInactive, + effectsToApply = {} + }) + teleporterA.effectsToApply.teleportTo = teleporterB + teleporterB.effectsToApply.teleportTo = teleporterA + addClickable({ + drawAsSprite = SmallSandTrap, + spriteAfterEffect = SmallSandTrapActivated, + effectsToApply = { + slowsTo = { x = 1, y = 1 }, + }, + }) addClickable({ drawAsSprite = SmallSandTrap, spriteAfterEffect = SmallSandTrapActivated, effectsToApply = { slowsTo = { x = 1, y = 1 }, - --movement = { x = 0, y = 0 }, }, }) World:addEntity({ @@ -246,17 +272,16 @@ Scenarios = { end, } -local currentLevel = Scenarios.firstLevel -currentLevel() - -function love.load() - love.graphics.setBackgroundColor(1, 1, 1) - love.graphics.setFont(EtBt7001Z0xa(32)) -end - local bail = false -World:setSystemIndex(LiveForNFrames, 1) +local currentLevel = Scenarios.firstLevel + +function love.load() + -- World:setSystemIndex(LiveForNFrames, 1) + love.graphics.setBackgroundColor(1, 1, 1) + love.graphics.setFont(EtBt7001Z0xa(32)) + currentLevel() +end function love.draw() local dt = love.timer.getDelta() diff --git a/systems/ballEffects.lua b/systems/ballEffects.lua index 20587d7..67646d5 100644 --- a/systems/ballEffects.lua +++ b/systems/ballEffects.lua @@ -58,17 +58,19 @@ local function slowTo(n, nToSlowTo) end ---@class BallEffects +---@field gridPosition nil | XyPair ---@field slowsTo nil | XyPair ---@field slowsBy nil | XyPair ---@field movement nil | XyPair ---@field fliesFor nil | number +---@field teleportTo nil | BallEffects ---@type BallEffects local BallEffects = {} local activeBallEffects = filteredSystem( "activeBallEffects", - { ballEffects = BallEffects, gridPosition = T.XyPair }, + { ballEffects = BallEffects, gridPosition = T.XyPair, position = T.XyPair }, function(e, _, system) local gridPosition, effects = e.gridPosition, e.ballEffects @@ -101,26 +103,39 @@ local activeBallEffects = filteredSystem( -- Apply any effects currently connected to this ball -- -------------------------------------------------------- - if effects.movement ~= nil then - if effects.slowsBy ~= nil then - effects.movement.x = slowBy(effects.movement.x, effects.slowsBy.x) - effects.movement.y = slowBy(effects.movement.y, effects.slowsBy.y) - effects.slowsBy = nil - end - if effects.slowsTo ~= nil then - effects.movement.x = slowTo(effects.movement.x, effects.slowsTo.x) - effects.movement.y = slowTo(effects.movement.y, effects.slowsTo.y) - effects.slowsTo = nil - end + if effects.teleportTo ~= nil then + local targetGridPos = effects.teleportTo.gridPosition + gridPosition.x = targetGridPos.x + gridPosition.y = targetGridPos.y - if effects.movement.x == 0 and effects.movement.y == 0 then - effects.movement = nil - else - gridPosition.x = gridPosition.x + math.sign(effects.movement.x) - gridPosition.y = gridPosition.y + math.sign(effects.movement.y) + -- Jump to position directly, instead of animating there gradually + e.position = PositionAtGridXy(gridPosition.x, gridPosition.y) - effects.movement.x = effects.movement.x - math.sign(effects.movement.x) - effects.movement.y = effects.movement.y - math.sign(effects.movement.y) + -- Deactivate receiving teleporter + effects.teleportTo.effectsToApply = {} + effects.teleportTo = nil + else + if effects.movement ~= nil then + if effects.slowsBy ~= nil then + effects.movement.x = slowBy(effects.movement.x, effects.slowsBy.x) + effects.movement.y = slowBy(effects.movement.y, effects.slowsBy.y) + effects.slowsBy = nil + end + if effects.slowsTo ~= nil then + effects.movement.x = slowTo(effects.movement.x, effects.slowsTo.x) + effects.movement.y = slowTo(effects.movement.y, effects.slowsTo.y) + effects.slowsTo = nil + end + + if effects.movement.x == 0 and effects.movement.y == 0 then + effects.movement = nil + else + gridPosition.x = gridPosition.x + math.sign(effects.movement.x) + gridPosition.y = gridPosition.y + math.sign(effects.movement.y) + + effects.movement.x = effects.movement.x - math.sign(effects.movement.x) + effects.movement.y = effects.movement.y - math.sign(effects.movement.y) + end end end @@ -136,7 +151,6 @@ local activeBallEffects = filteredSystem( -- Return if there are any effects left -- print("Setting roundState to animating...") system.world:addEntity({ roundState = "animating" }) - -- system.world:removeEntity(e) return end diff --git a/systems/collision-detection.lua b/systems/collision-detection.lua index 866bbe3..9fae0a8 100644 --- a/systems/collision-detection.lua +++ b/systems/collision-detection.lua @@ -1,3 +1,5 @@ +local band = bit.band + collidingEntities = filteredSystem("collidingEntitites", { position = T.XyPair, size = T.XyPair, @@ -28,12 +30,12 @@ filteredSystem( if (e ~= collider) and collider.canCollideWith + and e.position and e.canBeCollidedBy - and bit.band(collider.canCollideWith, e.canBeCollidedBy) ~= 0 + and band(collider.canCollideWith, e.canBeCollidedBy) ~= 0 + and intersects(e, collider) then - if intersects(e, collider) then - system.world:addEntity({ collisionBetween = { e, collider } }) - end + system.world:addEntity({ collisionBetween = { e, collider } }) end end end diff --git a/systems/collision-resolution.lua b/systems/collision-resolution.lua index 3303f9d..b7e44d0 100644 --- a/systems/collision-resolution.lua +++ b/systems/collision-resolution.lua @@ -37,9 +37,6 @@ Collisions = filteredSystem("collisionResolution", { collisionBetween = T.Collis collidedInto.canReceiveButtons = T.marker system.world:addEntity(collidedInto) end - if collidedInto.gridPosition then - --print("ready to place " .. #HeldByCursor.entities .. " entities") - end if MouseJustPressed(1, true) and collider.isCursor then system.world:addEntity({ activated = collidedInto }) end diff --git a/systems/draw.lua b/systems/draw.lua index 4861251..f522ea7 100644 --- a/systems/draw.lua +++ b/systems/draw.lua @@ -1,4 +1,3 @@ -local floor = math.floor local gfx = love.graphics --- ---@generic T @@ -19,7 +18,7 @@ local function drawSystem(name, shape, process) return system end -local mapGridPositions = filteredSystem("mapGridPositionToRealPosition", { gridPosition = T.XyPair }, function(e, dt, system) +filteredSystem("mapGridPositionToRealPosition", { gridPosition = T.XyPair }, function(e, dt, system) local target = PositionAtGridXy(e.gridPosition.x, e.gridPosition.y) if e.position == nil then e.position = target @@ -80,11 +79,11 @@ drawSystem( "drawText", { position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.pd_font) } }, function(e) - local font = e.font or gfx.getFont() -- e.drawAsText.font or AshevilleSans14Bold + local font = e.drawAsText.font or gfx.getFont() -- e.drawAsText.font or AshevilleSans14Bold local textHeight = font:getHeight() local textWidth = font:getWidth(e.drawAsText.text) - local bgLeftEdge = e.position.x - margin - textWidth / 2 + local bgLeftEdge = e.position.x - margin -- - (textWidth / 2) local bgTopEdge = e.position.y - 2 local bgWidth, bgHeight = textWidth + (margin * 2), textHeight + 2