diff --git a/entity.lua b/entity.lua index e5758d0..4e90f8a 100644 --- a/entity.lua +++ b/entity.lua @@ -4,6 +4,7 @@ function Entity:initialize(t) self.x, self.y = t.x, t.y self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()} self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16} + self.cellShape = t.cellShape or self:cellShapeFromBox(self.size) self.color = Color:new(t.color) self.collision = t.collision --"none", "moveable", "unmoveable" self.sprite = t.sprite @@ -32,18 +33,36 @@ end function Entity:getOccupiedCells(coords) --we have this offset so we can project what a movement would do local offset = coords or {x = 0, y = 0} - local box = self:getGridBox() local cells = {} + local pos = self:getGridPos() + + for _, cell in ipairs(self:getCellShape()) do + local adjustedCell = {} + + adjustedCell.x = pos.x + cell.x - 1 + offset.x + adjustedCell.y = pos.y + cell.y - 1 + offset.y + table.insert(cells, adjustedCell) + end - for i = box.x + offset.x, box.x + box.w - 1 + offset.x do - for j = box.y + offset.y, box.y + box.h - 1 + offset.y do + return cells +end + +function Entity:cellShapeFromBox(box) + local cells = {} + for i = 1, box.w do + for j = 1, box.h do table.insert(cells, {x = i, y = j}) + io.write(" boop: " .. i .. ", " .. j) end end - + io.write("\n") return cells end +function Entity:getCellShape() + return self.cellShape +end + function Entity:getDrawBox() local drawPos = self:getDrawPos() return {x = drawPos.x, y = drawPos.y, w = self.spriteSize.w * drawScale, h = self.spriteSize.h * drawScale} @@ -80,14 +99,14 @@ function Entity:draw() end function Entity:canMove() - if self.collision == "moveable" then + if self:getCollision() == "moveable" then return true end return false end function Entity:canPassOver() - if self.collision == "none" then + if self:getCollision() == "none" then return true end return false diff --git a/main.lua b/main.lua index 75c3e70..3bba00f 100644 --- a/main.lua +++ b/main.lua @@ -5,12 +5,12 @@ class = require "libs/middleclass" Timer = require "libs/hump/timer" sfxr = require "libs/sfxrlua/sfxr" json = require "libs/json4lua/json/json" +require "_debug_helpers" require "_helpers" require "input" require "color" require "room" require "shaders" -require "_debug_helpers" function love.load() _initDefaults() diff --git a/room.lua b/room.lua index a435af6..ee4cff2 100644 --- a/room.lua +++ b/room.lua @@ -33,15 +33,15 @@ function Room:initialize(t) -- self.activeColors[color] = true -- end - for i=1, 30 do - local x, y = randomPosition() - local door = Door:new(x, y, self.colorsPlayerHas) - table.insert(self.doors, door) + -- for i=1, 30 do + -- local x, y = randomPosition() + -- local door = Door:new(x, y, self.colorsPlayerHas) + -- table.insert(self.doors, door) - for color, active in pairs(self.activeColors) do - self.collideables[color]["w: " .. x .. ", " .. y] = door - end - end + -- for color, active in pairs(self.activeColors) do + -- self.collideables[color]["w: " .. x .. ", " .. y] = door + -- end + -- end for i=0, 5 do local x, y = randomPosition() @@ -50,25 +50,25 @@ function Room:initialize(t) end end - for i = 0, 5 do - local x, y = randomPosition() - print(x, y) - local c = randomColor() - table.insert(self.switches[c], Switch:new(x, y, c)) - end + -- for i = 0, 5 do + -- local x, y = randomPosition() + -- print(x, y) + -- local c = randomColor() + -- table.insert(self.switches[c], Switch:new(x, y, c)) + -- end for color, active in pairs(self.activeColors) do local x, y = 6, 3 -- if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "animals/processed/", "me_rach") end local x, y = 1, 1 - if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "house/processed/", "toilet") end + if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "tech/processed/", "mac_smaller") end self.collideables[color]["n: " .. x .. ", " .. y]:getOccupiedCells() - local x, y = 7, 7 - if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "food/processed/", "beer_mug") end + -- local x, y = 7, 7 + -- if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "food/processed/", "beer_mug") end - self.collideables[color]["fpp"] = Artifact:new(6, 6, color) + -- self.collideables[color]["fpp"] = Artifact:new(6, 6, color) end