Burger -> Cart
Add several sprite-based ingredients! Centralizing caching in the new ingredients.lua
This commit is contained in:
parent
22ff80cea7
commit
a6f9dabd88
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ all:
|
||||||
pdc --skip-unknown src Luncher.pdx
|
pdc --skip-unknown src Luncher.pdx
|
||||||
|
|
||||||
assets:
|
assets:
|
||||||
# lua lib/preprocess-cl.lua src/assets.lua2p
|
lua lib/preprocess-cl.lua src/assets.lua2p
|
||||||
|
|
||||||
check: assets
|
check: assets
|
||||||
stylua -c --indent-type Spaces src/
|
stylua -c --indent-type Spaces src/
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Luncher
|
# Luncher
|
||||||
|
|
||||||
Build the BIGGEST burger by **lunching** it through *delicious* ingredients.
|
Load up the BIGGEST cart by **lunching** it through *delicious* ingredients.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
-- GENERATED FILE - DO NOT EDIT
|
||||||
|
-- Instead, edit the source file directly: assets.lua2p.
|
||||||
|
|
||||||
|
-- luacheck: ignore
|
||||||
|
---@type pd_image
|
||||||
|
CartSprite = playdate.graphics.image.new("assets/images/CartSprite.png")
|
||||||
|
|
||||||
|
-- luacheck: ignore
|
||||||
|
---@type pd_image
|
||||||
|
CheeseSprite = playdate.graphics.image.new("assets/images/CheeseSprite.png")
|
||||||
|
|
||||||
|
-- luacheck: ignore
|
||||||
|
---@type pd_image
|
||||||
|
LettuceSprite = playdate.graphics.image.new("assets/images/LettuceSprite.png")
|
||||||
|
|
||||||
|
-- luacheck: ignore
|
||||||
|
---@type pd_image
|
||||||
|
MushroomSprite = playdate.graphics.image.new("assets/images/MushroomSprite.png")
|
||||||
|
|
||||||
|
-- luacheck: ignore
|
||||||
|
---@type pd_image
|
||||||
|
TomatoSprite = playdate.graphics.image.new("assets/images/TomatoSprite.png")
|
||||||
|
|
||||||
|
|
||||||
|
-- !!(dirLookup('assets/sounds', 'wav', 'playdate.sound.sampleplayer.new', 'pd_sampleplayer'))
|
||||||
|
-- !!(dirLookup('assets/music', 'wav', 'playdate.sound.sampleplayer.new', 'pd_sampleplayer'))
|
||||||
|
-- !!(dirLookup('assets/fonts', 'fnt', 'playdate.graphics.font.new', 'pd_font', nil, nil, function(varName, value)
|
||||||
|
-- return varName:gsub("[- ]", "") .. " = " .. value:gsub("fnt", "pft")
|
||||||
|
-- end))
|
|
@ -0,0 +1,33 @@
|
||||||
|
!(function dirLookup(dir, extension, newFunc, type, sep, indent, handle)
|
||||||
|
indent = indent or ""
|
||||||
|
sep = sep or "\n\n"
|
||||||
|
handle = handle ~= nil and handle or function(varName, value)
|
||||||
|
return varName .. ' = ' .. value
|
||||||
|
end
|
||||||
|
|
||||||
|
local p = io.popen('find src/' .. dir .. ' -maxdepth 1 -type f | sort -h')
|
||||||
|
|
||||||
|
local assetCode = ""
|
||||||
|
--Loop through all files
|
||||||
|
for file in p:lines() do
|
||||||
|
if file:find(extension) then
|
||||||
|
local varName = file:gsub(".*/(.*)." .. extension, "%1")
|
||||||
|
file = file:gsub("src/", "")
|
||||||
|
assetCode = assetCode .. indent .. '-- luacheck: ignore\n'
|
||||||
|
assetCode = assetCode .. indent .. '---@type ' .. type ..'\n'
|
||||||
|
assetCode = assetCode .. indent .. handle(varName, newFunc .. '("' .. file .. '")') .. sep
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return assetCode
|
||||||
|
end
|
||||||
|
function generatedFileWarning()
|
||||||
|
-- Only in a function to make clear that THIS .lua2p is not the generated file!
|
||||||
|
return "-- GENERATED FILE - DO NOT EDIT\n-- Instead, edit the source file directly: assets.lua2p."
|
||||||
|
end)!!(generatedFileWarning())
|
||||||
|
|
||||||
|
!!(dirLookup('assets/images', 'png', 'playdate.graphics.image.new', 'pd_image'))
|
||||||
|
-- !!(dirLookup('assets/sounds', 'wav', 'playdate.sound.sampleplayer.new', 'pd_sampleplayer'))
|
||||||
|
-- !!(dirLookup('assets/music', 'wav', 'playdate.sound.sampleplayer.new', 'pd_sampleplayer'))
|
||||||
|
-- !!(dirLookup('assets/fonts', 'fnt', 'playdate.graphics.font.new', 'pd_font', nil, nil, function(varName, value)
|
||||||
|
-- return varName:gsub("[- ]", "") .. " = " .. value:gsub("fnt", "pft")
|
||||||
|
-- end))
|
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 761 B |
Binary file not shown.
After Width: | Height: | Size: 719 B |
Binary file not shown.
After Width: | Height: | Size: 701 B |
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
|
@ -1,32 +0,0 @@
|
||||||
Burger = {}
|
|
||||||
|
|
||||||
local gfx <const> = playdate.graphics
|
|
||||||
|
|
||||||
function Burger.reset(o)
|
|
||||||
o.position = {
|
|
||||||
x = 20,
|
|
||||||
y = 50,
|
|
||||||
}
|
|
||||||
o.velocity = {
|
|
||||||
x = 50 + (150 * math.random()),
|
|
||||||
y = 150 * (math.random() - 1),
|
|
||||||
}
|
|
||||||
o.size = {
|
|
||||||
x = 10,
|
|
||||||
y = 10,
|
|
||||||
}
|
|
||||||
o.canBeBounced = {
|
|
||||||
flat = { x = 0, y = 0 },
|
|
||||||
mult = { x = 1, y = 1 },
|
|
||||||
}
|
|
||||||
o.mass = T.marker
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Burger.new()
|
|
||||||
return setmetatable(Burger.reset({}), { __index = Burger })
|
|
||||||
end
|
|
||||||
|
|
||||||
function Burger:draw()
|
|
||||||
gfx.fillCircleAtPoint(burger.position.x, burger.position.y, 10)
|
|
||||||
end
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
Cart = {}
|
||||||
|
|
||||||
|
local sizeX, sizeY = CartSprite:getSize()
|
||||||
|
local size = { x = sizeX, y = sizeY * 0.75 }
|
||||||
|
|
||||||
|
function Cart.reset(o)
|
||||||
|
o.position = {
|
||||||
|
x = 20,
|
||||||
|
y = 50,
|
||||||
|
}
|
||||||
|
o.velocity = {
|
||||||
|
x = 50 + (150 * math.random()),
|
||||||
|
y = 150 * (math.random() - 1),
|
||||||
|
}
|
||||||
|
o.size = size
|
||||||
|
o.canBeBounced = {
|
||||||
|
flat = { x = 0, y = 0 },
|
||||||
|
mult = { x = 1, y = 1 },
|
||||||
|
}
|
||||||
|
o.mass = T.marker
|
||||||
|
o.drawAsSprite = CartSprite
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function Cart.new()
|
||||||
|
return setmetatable(Cart.reset({}), { __index = Cart })
|
||||||
|
end
|
|
@ -1,45 +0,0 @@
|
||||||
Booster = {}
|
|
||||||
|
|
||||||
local function newBooster(x, y)
|
|
||||||
local size = { x = 40, y = 10 }
|
|
||||||
return {
|
|
||||||
score = 1,
|
|
||||||
expireAfterCollision = true,
|
|
||||||
size = size,
|
|
||||||
position = { x = x, y = y },
|
|
||||||
canBounce = {
|
|
||||||
flat = { x = 122, y = 190 },
|
|
||||||
mult = { x = 1, y = -0.5 },
|
|
||||||
},
|
|
||||||
drawAsRectangle = { size = size },
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
boosterIndex = 1
|
|
||||||
boosterCache = {}
|
|
||||||
for i = 1, 100 do
|
|
||||||
boosterCache[i] = newBooster(-999, 999)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Booster.cacheSize()
|
|
||||||
return #boosterCache
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Boosters should be "initialized" almost always increasing in X value
|
|
||||||
function Booster.get(x, y)
|
|
||||||
local booster = boosterCache[boosterIndex]
|
|
||||||
booster.position.x = x
|
|
||||||
booster.position.y = y
|
|
||||||
|
|
||||||
boosterIndex = boosterIndex + 1
|
|
||||||
if boosterIndex > #boosterCache then
|
|
||||||
boosterIndex = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
return booster
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Assumes that at least one Booster has already been created.
|
|
||||||
function Booster.newestBooster()
|
|
||||||
return boosterCache[boosterIndex]
|
|
||||||
end
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
Cheese = {}
|
||||||
|
|
||||||
|
local sizeX, sizeY = CheeseSprite:getSize()
|
||||||
|
local size = { x = sizeX, y = sizeY }
|
||||||
|
local expireWhenOffScreenBy = { x = 2000, y = 480 }
|
||||||
|
|
||||||
|
local canBounce = {
|
||||||
|
flat = { x = 50, y = 390 },
|
||||||
|
mult = { x = 0.7, y = -0.5 },
|
||||||
|
}
|
||||||
|
|
||||||
|
function Cheese.initialize(o, x, y)
|
||||||
|
o.score = 5
|
||||||
|
o.expireAfterCollision = true
|
||||||
|
o.size = size
|
||||||
|
o.position = { x = x, y = y }
|
||||||
|
o.drawAsSprite = CheeseSprite
|
||||||
|
o.expireWhenOffScreenBy = expireWhenOffScreenBy
|
||||||
|
o.canBounce = canBounce
|
||||||
|
newestBooster = o
|
||||||
|
return newestBooster
|
||||||
|
end
|
|
@ -0,0 +1,50 @@
|
||||||
|
import("ingredients/cheese.lua")
|
||||||
|
import("ingredients/lettuce.lua")
|
||||||
|
import("ingredients/mushroom.lua")
|
||||||
|
import("ingredients/tomato.lua")
|
||||||
|
|
||||||
|
---@class
|
||||||
|
Ingredients = {}
|
||||||
|
|
||||||
|
local ingredientCache = {}
|
||||||
|
|
||||||
|
local _ingredientCacheIndex = 1
|
||||||
|
local maxCache = 100
|
||||||
|
for i = 1, maxCache do
|
||||||
|
ingredientCache[i] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local newestIngredient = {}
|
||||||
|
function Ingredients.newestIngredient()
|
||||||
|
assert(newestIngredient.position ~= nil, "All ingredients are implicitly required to have a position component.")
|
||||||
|
return newestIngredient
|
||||||
|
end
|
||||||
|
|
||||||
|
function Ingredients.cacheSize()
|
||||||
|
return maxCache
|
||||||
|
end
|
||||||
|
|
||||||
|
function Ingredients.getNext(x, y)
|
||||||
|
local index = _ingredientCacheIndex
|
||||||
|
_ingredientCacheIndex = _ingredientCacheIndex + 1
|
||||||
|
if _ingredientCacheIndex >= maxCache then
|
||||||
|
_ingredientCacheIndex = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local o = ingredientCache[index]
|
||||||
|
for key in pairs(o) do
|
||||||
|
o[key] = nil
|
||||||
|
end
|
||||||
|
newestIngredient = o
|
||||||
|
|
||||||
|
local odds = math.random()
|
||||||
|
if odds > 0.3 then
|
||||||
|
return Lettuce.initialize(o, x, y)
|
||||||
|
elseif odds > 0.2 then
|
||||||
|
return Tomato.initialize(o, x, y)
|
||||||
|
elseif odds > 0.1 then
|
||||||
|
return Mushroom.initialize(o, x, 218 + math.random(1, 5))
|
||||||
|
else
|
||||||
|
return Cheese.initialize(o, x, y)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,22 @@
|
||||||
|
Lettuce = {}
|
||||||
|
|
||||||
|
local sizeX, sizeY = LettuceSprite:getSize()
|
||||||
|
local size = { x = sizeX, y = sizeY / 2 }
|
||||||
|
local expireWhenOffScreenBy = { x = 2000, y = 480 }
|
||||||
|
|
||||||
|
local canBounce = {
|
||||||
|
flat = { x = 22, y = 190 },
|
||||||
|
mult = { x = 1, y = -0.5 },
|
||||||
|
}
|
||||||
|
|
||||||
|
function Lettuce.initialize(o, x, y)
|
||||||
|
o.score = 1
|
||||||
|
o.expireAfterCollision = true
|
||||||
|
o.size = size
|
||||||
|
o.position = { x = x, y = y }
|
||||||
|
o.drawAsSprite = LettuceSprite
|
||||||
|
o.expireWhenOffScreenBy = expireWhenOffScreenBy
|
||||||
|
o.canBounce = canBounce
|
||||||
|
newestBooster = o
|
||||||
|
return newestBooster
|
||||||
|
end
|
|
@ -0,0 +1,22 @@
|
||||||
|
Mushroom = {}
|
||||||
|
|
||||||
|
local sizeX, sizeY = MushroomSprite:getSize()
|
||||||
|
local size = { x = sizeX, y = sizeY }
|
||||||
|
local expireWhenOffScreenBy = { x = 2000, y = 480 }
|
||||||
|
|
||||||
|
local canBounce = {
|
||||||
|
flat = { x = 0, y = 190 },
|
||||||
|
mult = { x = 1, y = -2 },
|
||||||
|
}
|
||||||
|
|
||||||
|
function Mushroom.initialize(o, x, y)
|
||||||
|
o.score = 5
|
||||||
|
o.expireAfterCollision = true
|
||||||
|
o.size = size
|
||||||
|
o.position = { x = x, y = y }
|
||||||
|
o.drawAsSprite = MushroomSprite
|
||||||
|
o.expireWhenOffScreenBy = expireWhenOffScreenBy
|
||||||
|
o.canBounce = canBounce
|
||||||
|
newestBooster = o
|
||||||
|
return newestBooster
|
||||||
|
end
|
|
@ -1,36 +1,16 @@
|
||||||
Tomato = {}
|
Tomato = {}
|
||||||
|
|
||||||
local function newTomato(x, y)
|
local sizeX, sizeY = TomatoSprite:getSize()
|
||||||
local size = { x = 20, y = 20 }
|
local size = { x = sizeX, y = sizeY }
|
||||||
return {
|
local expireWhenOffScreenBy = { x = 2000, y = 480 }
|
||||||
score = 15,
|
|
||||||
expireAfterCollision = true,
|
function Tomato.initialize(o, x, y)
|
||||||
position = { x = x, y = y },
|
o.score = 15
|
||||||
size = size,
|
o.expireAfterCollision = true
|
||||||
drawAsRectangle = { size = size },
|
o.size = size
|
||||||
}
|
o.position = { x = x, y = y }
|
||||||
end
|
o.drawAsSprite = TomatoSprite
|
||||||
|
o.expireWhenOffScreenBy = expireWhenOffScreenBy
|
||||||
local tomatoIndex = 1
|
newestBooster = o
|
||||||
local tomatoCache = {}
|
return newestBooster
|
||||||
for i = 1, 100 do
|
|
||||||
tomatoCache[i] = newTomato(-999, 999)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Tomato.cacheSize()
|
|
||||||
return #tomatoCache
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tomatos should be "initialized" almost always increasing in X value
|
|
||||||
function Tomato.get(x, y)
|
|
||||||
local tomato = tomatoCache[tomatoIndex]
|
|
||||||
tomato.position.x = x
|
|
||||||
tomato.position.y = y
|
|
||||||
|
|
||||||
tomatoIndex = tomatoIndex + 1
|
|
||||||
if tomatoIndex > #tomatoCache then
|
|
||||||
tomatoIndex = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
return tomato
|
|
||||||
end
|
end
|
||||||
|
|
56
src/main.lua
56
src/main.lua
|
@ -11,22 +11,22 @@ import 'CoreLibs/utilities/where.lua'
|
||||||
|
|
||||||
import("../lib/tiny.lua")
|
import("../lib/tiny.lua")
|
||||||
import("tiny-tools.lua")
|
import("tiny-tools.lua")
|
||||||
|
import("assets.lua")
|
||||||
import("systems/filter-types.lua")
|
import("systems/filter-types.lua")
|
||||||
import("systems/collision-detection.lua")
|
import("systems/collision-detection.lua")
|
||||||
import("systems/collision-resolution.lua")
|
import("systems/collision-resolution.lua")
|
||||||
import("systems/draw.lua")
|
import("systems/draw.lua")
|
||||||
import("systems/gravity.lua")
|
import("systems/gravity.lua")
|
||||||
import("systems/velocity.lua")
|
import("systems/velocity.lua")
|
||||||
import("ingredients/booster.lua")
|
import("ingredients/ingredients.lua")
|
||||||
import("ingredients/tomato.lua")
|
import("cart.lua")
|
||||||
import("burger.lua")
|
|
||||||
|
|
||||||
local tiny <const> = tiny
|
local tiny <const> = tiny
|
||||||
local gfx <const> = playdate.graphics
|
local gfx <const> = playdate.graphics
|
||||||
playdate.display.setRefreshRate(50)
|
playdate.display.setRefreshRate(50)
|
||||||
gfx.setBackgroundColor(gfx.kColorWhite)
|
gfx.setBackgroundColor(gfx.kColorWhite)
|
||||||
|
|
||||||
burger = Burger.new()
|
cart = Cart.new()
|
||||||
local floorSize = { x = 10000, y = 10 }
|
local floorSize = { x = 10000, y = 10 }
|
||||||
floor = {
|
floor = {
|
||||||
position = { x = 0, y = 235 },
|
position = { x = 0, y = 235 },
|
||||||
|
@ -40,6 +40,7 @@ floor = {
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera = {
|
Camera = {
|
||||||
|
--- The upper-left corner of the Camera is represented by this `pan` value
|
||||||
pan = {
|
pan = {
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0,
|
y = 0,
|
||||||
|
@ -65,38 +66,43 @@ world = tiny.world(
|
||||||
velocitySystem,
|
velocitySystem,
|
||||||
collisionResolution,
|
collisionResolution,
|
||||||
collisionDetection,
|
collisionDetection,
|
||||||
drawSystem,
|
|
||||||
drawRectanglesSystem,
|
|
||||||
|
|
||||||
burger,
|
drawRectanglesSystem,
|
||||||
|
drawSpriteSystem,
|
||||||
|
|
||||||
|
cart,
|
||||||
floor
|
floor
|
||||||
)
|
)
|
||||||
|
|
||||||
for i = 1, Booster.cacheSize() do
|
local ingredientsEveryX = 50
|
||||||
world:addEntity(Booster.get(i * 60 + (math.random(0, 50)), math.random(50, 200)))
|
|
||||||
|
local function init()
|
||||||
|
for i = 1, Ingredients.cacheSize() do
|
||||||
|
world:addEntity(Ingredients.getNext(i * ingredientsEveryX + (math.random(0, 20)), math.random(50, 200)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
init()
|
||||||
|
|
||||||
function playdate.update()
|
function playdate.update()
|
||||||
local deltaSeconds = playdate.getElapsedTime()
|
local deltaSeconds = playdate.getElapsedTime()
|
||||||
playdate.resetElapsedTime()
|
playdate.resetElapsedTime()
|
||||||
gfx.clear(gfx.kColorWhite)
|
gfx.clear(gfx.kColorWhite)
|
||||||
playdate.drawFPS(5, 5)
|
playdate.drawFPS(5, 5)
|
||||||
|
|
||||||
Camera.pan.x = math.min(0, -burger.position.x + 200)
|
Camera.pan.x = math.max(0, cart.position.x - 200)
|
||||||
Camera.pan.y = math.max(0, -burger.position.y + 120)
|
Camera.pan.y = math.min(0, cart.position.y - 120)
|
||||||
local newestX = Booster.newestBooster().position.x
|
|
||||||
local panX = -Camera.pan.x
|
local newestX = Ingredients.newestIngredient().position.x
|
||||||
|
local panX = Camera.pan.x
|
||||||
|
local rightEdge = panX + 400
|
||||||
local offset = 600
|
local offset = 600
|
||||||
if newestX + 300 < panX then
|
while newestX < (rightEdge + 100) do
|
||||||
if math.random() > 0.5 then
|
newestX = newestX + ingredientsEveryX
|
||||||
world:addEntity(Tomato.get(panX + offset + (math.random(0, 50)), math.random(-500, 150)))
|
world:addEntity(Ingredients.getNext(newestX, math.random(-500, 150)))
|
||||||
else
|
|
||||||
-- Implicitly updates cached boosters
|
|
||||||
Booster.get(panX + offset + (math.random(0, 50)), math.random(-500, 150))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
floor.position.x = -Camera.pan.x - offset
|
floor.position.x = Camera.pan.x - offset
|
||||||
gfx.setDrawOffset(Camera.pan.x, Camera.pan.y)
|
gfx.setDrawOffset(-Camera.pan.x, -Camera.pan.y)
|
||||||
|
|
||||||
world:update(deltaSeconds)
|
world:update(deltaSeconds)
|
||||||
|
|
||||||
|
@ -104,9 +110,7 @@ function playdate.update()
|
||||||
Score:draw()
|
Score:draw()
|
||||||
|
|
||||||
if playdate.buttonJustPressed(playdate.kButtonA) then
|
if playdate.buttonJustPressed(playdate.kButtonA) then
|
||||||
Burger.reset(burger)
|
Cart.reset(cart)
|
||||||
for i = 1, Booster.cacheSize() do
|
init()
|
||||||
Booster.get(i * 60 + (math.random(0, 50)), math.random(50, 200))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
collisionDetection = filteredSystem(
|
collisionDetection = filteredSystem(
|
||||||
{ position = T.XyPair, size = T.XyPair, isSolid = Maybe(T.bool) },
|
{ position = T.XyPair, size = T.XyPair, isSolid = Maybe(T.bool) },
|
||||||
-- Here, the entity, e, refers to some entity that the burger global(!) may be colliding with.
|
-- Here, the entity, e, refers to some entity that the cart global(!) may be colliding with.
|
||||||
function(e, _, system)
|
function(e, _, system)
|
||||||
local collider = burger
|
local collider = cart
|
||||||
if not collider.velocity then
|
if not collider.velocity then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
collisionResolution = filteredSystem({ collisionBetween = T.Collision }, function(e, _, system)
|
collisionResolution = filteredSystem({ collisionBetween = T.Collision }, function(e, _, system)
|
||||||
local collider, probablyBurger = e.collisionBetween[1], e.collisionBetween[2]
|
local collider, probablyCart = e.collisionBetween[1], e.collisionBetween[2]
|
||||||
local colliderTop = collider.position.y
|
local colliderTop = collider.position.y
|
||||||
|
|
||||||
if collider.isSolid then
|
if collider.isSolid then
|
||||||
-- Assumes impact from the top
|
-- Assumes impact from the top
|
||||||
probablyBurger.position.y = colliderTop - probablyBurger.size.y
|
probablyCart.position.y = colliderTop - probablyCart.size.y
|
||||||
end
|
end
|
||||||
|
|
||||||
if collider.canBounce and probablyBurger.canBeBounced then
|
if collider.canBounce and probablyCart.canBeBounced then
|
||||||
probablyBurger.velocity.x = probablyBurger.velocity.x
|
probablyCart.velocity.x = probablyCart.velocity.x
|
||||||
+ collider.canBounce.flat.x
|
+ collider.canBounce.flat.x
|
||||||
+ probablyBurger.canBeBounced.flat.x
|
+ probablyCart.canBeBounced.flat.x
|
||||||
|
|
||||||
probablyBurger.velocity.x = probablyBurger.velocity.x
|
probablyCart.velocity.x = probablyCart.velocity.x
|
||||||
* collider.canBounce.mult.x
|
* collider.canBounce.mult.x
|
||||||
* probablyBurger.canBeBounced.mult.x
|
* probablyCart.canBeBounced.mult.x
|
||||||
|
|
||||||
-- abs() makes sure we always push upward
|
-- abs() makes sure we always push upward
|
||||||
probablyBurger.velocity.y = math.abs(probablyBurger.velocity.y)
|
probablyCart.velocity.y = math.abs(probablyCart.velocity.y)
|
||||||
+ collider.canBounce.flat.y
|
+ collider.canBounce.flat.y
|
||||||
+ probablyBurger.canBeBounced.flat.y
|
+ probablyCart.canBeBounced.flat.y
|
||||||
|
|
||||||
probablyBurger.velocity.y = probablyBurger.velocity.y
|
probablyCart.velocity.y = probablyCart.velocity.y
|
||||||
* collider.canBounce.mult.y
|
* collider.canBounce.mult.y
|
||||||
* probablyBurger.canBeBounced.mult.y
|
* probablyCart.canBeBounced.mult.y
|
||||||
end
|
end
|
||||||
|
|
||||||
if collider.score then
|
if collider.score then
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
local gfx <const> = playdate.graphics
|
local gfx <const> = playdate.graphics
|
||||||
|
|
||||||
drawSystem = filteredSystem({ draw = T.SelfFunction }, function(e, dt)
|
|
||||||
e:draw()
|
|
||||||
end)
|
|
||||||
|
|
||||||
drawRectanglesSystem = filteredSystem({ position = T.XyPair, drawAsRectangle = { size = T.XyPair } }, function(e, dt)
|
drawRectanglesSystem = filteredSystem({ position = T.XyPair, drawAsRectangle = { size = T.XyPair } }, function(e, dt)
|
||||||
gfx.fillRect(e.position.x, e.position.y, e.drawAsRectangle.size.x, e.drawAsRectangle.size.y)
|
gfx.fillRect(e.position.x, e.position.y, e.drawAsRectangle.size.x, e.drawAsRectangle.size.y)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
drawSpriteSystem = filteredSystem({ position = T.XyPair, drawAsSprite = T.PdImage }, function(e, dt, system)
|
||||||
|
e.drawAsSprite:draw(e.position.x, e.position.y)
|
||||||
|
end)
|
|
@ -7,9 +7,11 @@
|
||||||
---@type Entity
|
---@type Entity
|
||||||
local Entity = {}
|
local Entity = {}
|
||||||
|
|
||||||
|
---@type XyPair
|
||||||
|
local XyPair = { x = 1, y = 1 }
|
||||||
|
|
||||||
T = {
|
T = {
|
||||||
---@type XyPair
|
XyPair = XyPair,
|
||||||
XyPair = { x = 1, y = 1 },
|
|
||||||
bool = true,
|
bool = true,
|
||||||
number = 0,
|
number = 0,
|
||||||
numberArray = { 1, 2, 3 },
|
numberArray = { 1, 2, 3 },
|
||||||
|
@ -20,16 +22,18 @@ T = {
|
||||||
--- Actor
|
--- Actor
|
||||||
CanBounce = {
|
CanBounce = {
|
||||||
isSolid = true,
|
isSolid = true,
|
||||||
flat = { x = 1, y = 1 },
|
flat = XyPair,
|
||||||
mult = { x = 1, y = 1 },
|
mult = XyPair,
|
||||||
},
|
},
|
||||||
--- Receiver
|
--- Receiver
|
||||||
CanBeBounced = {
|
CanBeBounced = {
|
||||||
flat = { x = 1, y = 1 },
|
flat = XyPair,
|
||||||
mult = { x = 1, y = 1 },
|
mult = XyPair,
|
||||||
},
|
},
|
||||||
---@type Collision
|
---@type Collision
|
||||||
Collision = { Entity, Entity },
|
Collision = { Entity, Entity },
|
||||||
|
---@type pd_image
|
||||||
|
PdImage = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
---@generic T
|
---@generic T
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
local screenWidth, screenHeight = 400, 240
|
||||||
|
|
||||||
|
offscreenSystem = filteredSystem({ position = T.XyPair, expireWhenOffScreenBy = T.XyPair }, function(e, dt, system)
|
||||||
|
-- if Camera.pan.x - e.expireWhenOffScreenBy.x > e.position.x then
|
||||||
|
-- print("Fell behind")
|
||||||
|
-- system.world:removeEntity(e)
|
||||||
|
-- end
|
||||||
|
-- if Camera.pan.x + screenWidth + e.expireWhenOffScreenBy.x < e.position.x then
|
||||||
|
-- print("Too far ahead")
|
||||||
|
-- system.world:removeEntity(e)
|
||||||
|
-- end
|
||||||
|
-- if Camera.pan.y - e.expireWhenOffScreenBy.y > e.position.y then
|
||||||
|
-- print("Too high")
|
||||||
|
-- system.world:removeEntity(e)
|
||||||
|
-- end
|
||||||
|
-- if Camera.pan.y + screenHeight + e.expireWhenOffScreenBy.y < e.position.y then
|
||||||
|
-- print("Too low")
|
||||||
|
-- system.world:removeEntity(e)
|
||||||
|
-- end
|
||||||
|
end)
|
Loading…
Reference in New Issue