generated from sage/tiny-ecs-love-template
Add teleporter. Drop some lingering playdate code.
This commit is contained in:
parent
cffb946fc7
commit
f59e21b70b
|
@ -57,6 +57,14 @@ SmallSandTrap = love.graphics.newImage("assets/images/SmallSandTrap.png")
|
||||||
---@type love.Texture
|
---@type love.Texture
|
||||||
StartButton = love.graphics.newImage("assets/images/StartButton.png")
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,6 @@ T = {
|
||||||
marker = SOME_TABLE,
|
marker = SOME_TABLE,
|
||||||
---@type fun(self)
|
---@type fun(self)
|
||||||
SelfFunction = function() end,
|
SelfFunction = function() end,
|
||||||
---@type pd_image
|
|
||||||
pd_image = SOME_TABLE,
|
|
||||||
---@type pd_font
|
|
||||||
pd_font = SOME_TABLE,
|
|
||||||
|
|
||||||
---@type AnyComponent
|
---@type AnyComponent
|
||||||
AnyComponent = SOME_TABLE,
|
AnyComponent = SOME_TABLE,
|
||||||
|
|
|
@ -70,11 +70,7 @@ T = {
|
||||||
str = "",
|
str = "",
|
||||||
marker = SOME_TABLE,
|
marker = SOME_TABLE,
|
||||||
---@type fun(self)
|
---@type fun(self)
|
||||||
SelfFunction = function() end,
|
SelfFunction = function() end,!!(dumpTypeObjects())
|
||||||
---@type pd_image
|
|
||||||
pd_image = SOME_TABLE,
|
|
||||||
---@type pd_font
|
|
||||||
pd_font = SOME_TABLE,!!(dumpTypeObjects())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
---@generic T
|
---@generic T
|
||||||
|
|
55
main.lua
55
main.lua
|
@ -14,7 +14,6 @@ local width, height = love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
|
||||||
local squareSide = 80
|
local squareSide = 80
|
||||||
local tileSize = math.floor(squareSide * 1.2)
|
local tileSize = math.floor(squareSide * 1.2)
|
||||||
local marginSize = 10
|
|
||||||
local squareSize = { x = squareSide, y = squareSide }
|
local squareSize = { x = squareSide, y = squareSide }
|
||||||
|
|
||||||
CursorMask = 1
|
CursorMask = 1
|
||||||
|
@ -126,7 +125,7 @@ Scenarios = {
|
||||||
current.below = yxGrid[1][x]
|
current.below = yxGrid[1][x]
|
||||||
end
|
end
|
||||||
if x == xCount then
|
if x == xCount then
|
||||||
-- Connect last entry to first Entry
|
-- Connect last column to first column
|
||||||
current.toRight = yxGrid[y][1]
|
current.toRight = yxGrid[y][1]
|
||||||
yxGrid[y][1].toLeft = current
|
yxGrid[y][1].toLeft = current
|
||||||
end
|
end
|
||||||
|
@ -207,8 +206,17 @@ Scenarios = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
addClickable({
|
addClickable({
|
||||||
drawAsSprite = Ramp,
|
drawAsText = {
|
||||||
spriteAfterEffect = Ramp,
|
text = "ROCK",
|
||||||
|
},
|
||||||
|
effectsToApply = {
|
||||||
|
slowsTo = { x = -1, y = -1 },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
addClickable({
|
||||||
|
drawAsText = {
|
||||||
|
text = "RAMP",
|
||||||
|
},
|
||||||
effectsToApply = {
|
effectsToApply = {
|
||||||
fliesFor = 1,
|
fliesFor = 1,
|
||||||
slowsBy = { x = 3, y = 3 },
|
slowsBy = { x = 3, y = 3 },
|
||||||
|
@ -218,7 +226,7 @@ Scenarios = {
|
||||||
drawAsSprite = GolferRight,
|
drawAsSprite = GolferRight,
|
||||||
spriteAfterEffect = GolferRightActivated,
|
spriteAfterEffect = GolferRightActivated,
|
||||||
effectsToApply = {
|
effectsToApply = {
|
||||||
movement = { x = 8, y = 0 },
|
movement = { x = 5, y = 0 },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
addClickable({
|
addClickable({
|
||||||
|
@ -228,12 +236,30 @@ Scenarios = {
|
||||||
movement = { x = 0, y = 6 },
|
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({
|
addClickable({
|
||||||
drawAsSprite = SmallSandTrap,
|
drawAsSprite = SmallSandTrap,
|
||||||
spriteAfterEffect = SmallSandTrapActivated,
|
spriteAfterEffect = SmallSandTrapActivated,
|
||||||
effectsToApply = {
|
effectsToApply = {
|
||||||
slowsTo = { x = 1, y = 1 },
|
slowsTo = { x = 1, y = 1 },
|
||||||
--movement = { x = 0, y = 0 },
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
World:addEntity({
|
World:addEntity({
|
||||||
|
@ -246,17 +272,16 @@ Scenarios = {
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local currentLevel = Scenarios.firstLevel
|
|
||||||
currentLevel()
|
|
||||||
|
|
||||||
function love.load()
|
|
||||||
love.graphics.setBackgroundColor(1, 1, 1)
|
|
||||||
love.graphics.setFont(EtBt7001Z0xa(32))
|
|
||||||
end
|
|
||||||
|
|
||||||
local bail = false
|
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()
|
function love.draw()
|
||||||
local dt = love.timer.getDelta()
|
local dt = love.timer.getDelta()
|
||||||
|
|
|
@ -58,17 +58,19 @@ local function slowTo(n, nToSlowTo)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class BallEffects
|
---@class BallEffects
|
||||||
|
---@field gridPosition nil | XyPair
|
||||||
---@field slowsTo nil | XyPair
|
---@field slowsTo nil | XyPair
|
||||||
---@field slowsBy nil | XyPair
|
---@field slowsBy nil | XyPair
|
||||||
---@field movement nil | XyPair
|
---@field movement nil | XyPair
|
||||||
---@field fliesFor nil | number
|
---@field fliesFor nil | number
|
||||||
|
---@field teleportTo nil | BallEffects
|
||||||
|
|
||||||
---@type BallEffects
|
---@type BallEffects
|
||||||
local BallEffects = {}
|
local BallEffects = {}
|
||||||
|
|
||||||
local activeBallEffects = filteredSystem(
|
local activeBallEffects = filteredSystem(
|
||||||
"activeBallEffects",
|
"activeBallEffects",
|
||||||
{ ballEffects = BallEffects, gridPosition = T.XyPair },
|
{ ballEffects = BallEffects, gridPosition = T.XyPair, position = T.XyPair },
|
||||||
function(e, _, system)
|
function(e, _, system)
|
||||||
local gridPosition, effects = e.gridPosition, e.ballEffects
|
local gridPosition, effects = e.gridPosition, e.ballEffects
|
||||||
|
|
||||||
|
@ -101,26 +103,39 @@ local activeBallEffects = filteredSystem(
|
||||||
-- Apply any effects currently connected to this ball --
|
-- Apply any effects currently connected to this ball --
|
||||||
--------------------------------------------------------
|
--------------------------------------------------------
|
||||||
|
|
||||||
if effects.movement ~= nil then
|
if effects.teleportTo ~= nil then
|
||||||
if effects.slowsBy ~= nil then
|
local targetGridPos = effects.teleportTo.gridPosition
|
||||||
effects.movement.x = slowBy(effects.movement.x, effects.slowsBy.x)
|
gridPosition.x = targetGridPos.x
|
||||||
effects.movement.y = slowBy(effects.movement.y, effects.slowsBy.y)
|
gridPosition.y = targetGridPos.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
|
-- Jump to position directly, instead of animating there gradually
|
||||||
effects.movement = nil
|
e.position = PositionAtGridXy(gridPosition.x, gridPosition.y)
|
||||||
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)
|
-- Deactivate receiving teleporter
|
||||||
effects.movement.y = effects.movement.y - math.sign(effects.movement.y)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,7 +151,6 @@ local activeBallEffects = filteredSystem(
|
||||||
-- Return if there are any effects left
|
-- Return if there are any effects left
|
||||||
-- print("Setting roundState to animating...")
|
-- print("Setting roundState to animating...")
|
||||||
system.world:addEntity({ roundState = "animating" })
|
system.world:addEntity({ roundState = "animating" })
|
||||||
-- system.world:removeEntity(e)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
local band = bit.band
|
||||||
|
|
||||||
collidingEntities = filteredSystem("collidingEntitites", {
|
collidingEntities = filteredSystem("collidingEntitites", {
|
||||||
position = T.XyPair,
|
position = T.XyPair,
|
||||||
size = T.XyPair,
|
size = T.XyPair,
|
||||||
|
@ -28,12 +30,12 @@ filteredSystem(
|
||||||
if
|
if
|
||||||
(e ~= collider)
|
(e ~= collider)
|
||||||
and collider.canCollideWith
|
and collider.canCollideWith
|
||||||
|
and e.position
|
||||||
and e.canBeCollidedBy
|
and e.canBeCollidedBy
|
||||||
and bit.band(collider.canCollideWith, e.canBeCollidedBy) ~= 0
|
and band(collider.canCollideWith, e.canBeCollidedBy) ~= 0
|
||||||
|
and intersects(e, collider)
|
||||||
then
|
then
|
||||||
if intersects(e, collider) then
|
system.world:addEntity({ collisionBetween = { e, collider } })
|
||||||
system.world:addEntity({ collisionBetween = { e, collider } })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,9 +37,6 @@ Collisions = filteredSystem("collisionResolution", { collisionBetween = T.Collis
|
||||||
collidedInto.canReceiveButtons = T.marker
|
collidedInto.canReceiveButtons = T.marker
|
||||||
system.world:addEntity(collidedInto)
|
system.world:addEntity(collidedInto)
|
||||||
end
|
end
|
||||||
if collidedInto.gridPosition then
|
|
||||||
--print("ready to place " .. #HeldByCursor.entities .. " entities")
|
|
||||||
end
|
|
||||||
if MouseJustPressed(1, true) and collider.isCursor then
|
if MouseJustPressed(1, true) and collider.isCursor then
|
||||||
system.world:addEntity({ activated = collidedInto })
|
system.world:addEntity({ activated = collidedInto })
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
local floor = math.floor
|
|
||||||
local gfx = love.graphics
|
local gfx = love.graphics
|
||||||
---
|
---
|
||||||
---@generic T
|
---@generic T
|
||||||
|
@ -19,7 +18,7 @@ local function drawSystem(name, shape, process)
|
||||||
return system
|
return system
|
||||||
end
|
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)
|
local target = PositionAtGridXy(e.gridPosition.x, e.gridPosition.y)
|
||||||
if e.position == nil then
|
if e.position == nil then
|
||||||
e.position = target
|
e.position = target
|
||||||
|
@ -80,11 +79,11 @@ drawSystem(
|
||||||
"drawText",
|
"drawText",
|
||||||
{ position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.pd_font) } },
|
{ position = T.XyPair, drawAsText = { text = T.str, style = Maybe(T.str), font = Maybe(T.pd_font) } },
|
||||||
function(e)
|
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 textHeight = font:getHeight()
|
||||||
local textWidth = font:getWidth(e.drawAsText.text)
|
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 bgTopEdge = e.position.y - 2
|
||||||
local bgWidth, bgHeight = textWidth + (margin * 2), textHeight + 2
|
local bgWidth, bgHeight = textWidth + (margin * 2), textHeight + 2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue