diff options
| author | cursed22bc <admin@pixeldawn.org> | 2026-03-10 21:26:24 +0200 |
|---|---|---|
| committer | cursed22bc <admin@pixeldawn.org> | 2026-03-10 21:26:24 +0200 |
| commit | 70b6d2a335a40ae60e990cc5f37b828ed9dbf526 (patch) | |
| tree | 025b946feae41782f2cddb57e444e05cc6f9ac39 /pickup.lua | |
| parent | a64d77bc12cadb3989a7faf094adc1d5c581d565 (diff) | |
pickups
Diffstat (limited to 'pickup.lua')
| -rw-r--r-- | pickup.lua | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/pickup.lua b/pickup.lua new file mode 100644 index 0000000..69fe37d --- /dev/null +++ b/pickup.lua @@ -0,0 +1,65 @@ +local Entity = require("entity") + +local Pickup = {} +Pickup.__index = Pickup + +function Pickup.new(entity) + local self = setmetatable({}, Pickup) + + self.x = entity.x + self.y = entity.y + self.width = entity.width + self.height = entity.height + self.image = nil + self.body = nil + self.fixture = nil + self.object = entity:get("object", "") + self.isPickup = true + self.collected = false + + return self +end + +function Pickup:assignImage() + if self.object == "key" then + self.image = love.graphics.newImage("assets/misc/key.png") + elseif self.object == "dbljump" then + self.image = love.graphics.newImage("assets/misc/dbljump.png") + end +end + +function Pickup:setWorldPhysics(world) + local cx = self.x + self.width / 2 + local cy = self.y + self.height / 2 + + self.body = love.physics.newBody(world, cx, cy, "static") + local shape = love.physics.newRectangleShape(self.width, self.height) + + self.fixture = love.physics.newFixture(self.body, shape) + self.fixture:setSensor(true) + self.fixture:setUserData(self) +end + +function Pickup:syncFromPhysicsBody() end + +function Pickup:update(dt) end + +function Pickup:draw() + if not self.collected then + love.graphics.draw(self.image, self.x, self.y) + end +end + +function Pickup:pickup(world, player) + if self.collected then return end + self.collected = true + world.player.pickups[self.object] = (world.player.pickups[self.object] or 0) + 1 + world.playerTextbox:show( + "Picked up " .. self.object .. " (" .. world.player.pickups[self.object] .. ")", + { player.x + player.width/2, player.y - 20, "center" }, + "write", + { life = 3, fontSize = 9, centeredText = true, wrapToFit = true } + ) +end + +return Pickup
\ No newline at end of file |
