import("CoreLibs/animation.lua") import("CoreLibs/animator.lua") import("CoreLibs/easing.lua") import("CoreLibs/graphics.lua") import("CoreLibs/object.lua") import("CoreLibs/timer.lua") import("CoreLibs/ui.lua") import("CoreLibs/utilities/where.lua") import("../lib/tiny.lua") import("tiny-tools.lua") import("assets.lua") import("systems/filter-types.lua") import("systems/camera-pan.lua") import("systems/collision-detection.lua") import("systems/collision-resolution.lua") import("systems/draw.lua") import("systems/gravity.lua") import("systems/rounds.lua") import("systems/velocity.lua") import("ingredients/ingredients.lua") import("cart.lua") local tiny = tiny local gfx = playdate.graphics playdate.display.setRefreshRate(50) gfx.setBackgroundColor(gfx.kColorWhite) cart = Cart.new() local floorSize = { x = 10000, y = 10 } floor = { position = { x = 0, y = 235 }, size = floorSize, canBeCollidedBy = 1 | 2 | 4, canBounce = { flat = { x = 0, y = 0 }, mult = { x = 0.9, y = -0.5 }, }, drawAsRectangle = { size = floorSize }, isSolid = true, sparkOnCollision = true, } Camera = { --- The upper-left corner of the Camera is represented by this `pan` value pan = { x = 0, y = 0, }, } Score = { points = 0, } -- TODO: Shops with random upgrades instead of fixed ones. function Score:add(add) self.points = self.points + add end function Score:draw() gfx.drawText("Z|" .. self.points, 360, 5) end world = tiny.world( fallSystem, velocitySystem, roundSystem, collectedEntities, collidingEntities, collisionResolution, collisionDetection, cameraPanSystem, drawRectanglesSystem, drawSpriteSystem, floor, cart ) local ingredientsEveryX = 60 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 init() -- TODO: Re-enable when cart stops playdate.setAutoLockDisabled(true) function playdate.update() local deltaSeconds = playdate.getElapsedTime() playdate.resetElapsedTime() gfx.clear(gfx.kColorWhite) playdate.drawFPS(5, 5) local newestX = Ingredients.newestIngredient().position.x local panX = Camera.pan.x local rightEdge = panX + 400 local offset = 600 while newestX < rightEdge + 100 do newestX = newestX + ingredientsEveryX world:addEntity(Ingredients.getNext(newestX, math.random(-500, 150))) end floor.position.x = Camera.pan.x - offset world:update(deltaSeconds) gfx.setDrawOffset(0, 0) Score:draw() if playdate.buttonJustPressed(playdate.kButtonA) then Cart.reset(cart) init() end end