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