add dialog
This commit is contained in:
parent
c92c0f6ff7
commit
5413823b26
13 changed files with 390 additions and 32 deletions
30
room.lua
30
room.lua
|
|
@ -120,19 +120,11 @@ function Room:draw()
|
|||
-- draw only the channels the player has. Each object just exposes sprites per
|
||||
-- channel via Entity:draw(channel); a door registered on all three channels
|
||||
-- naturally draws its red sprite on the red pass, etc. No per-object logic.
|
||||
local has = {}
|
||||
for _, channel in ipairs(self.colorsPlayerHas) do
|
||||
has[channel] = true
|
||||
if self.player[channel] then self.player[channel]:draw(channel) end
|
||||
for _, entity in pairs(self.collideables[channel]) do entity:draw(channel) end
|
||||
for _, switch in pairs(self.switches[channel]) do switch:draw(channel) end
|
||||
end
|
||||
|
||||
-- npcs (old "sages") are markers for now: a "?" tinted to the player's channels
|
||||
local cellW, cellH = width / gridWidth, height / gridHeight
|
||||
love.graphics.setColor(has.red and 1 or 0, has.green and 1 or 0, has.blue and 1 or 0)
|
||||
for _, npc in ipairs(self.npcs) do
|
||||
love.graphics.print("?", (npc.x - 1) * cellW + cellW * 0.3, (npc.y - 1) * cellH + cellH * 0.1, 0, 2, 2)
|
||||
for _, npc in ipairs(self.npcs) do npc:draw(channel) end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -140,6 +132,14 @@ function Room:createCollideablesMatrix()
|
|||
for color, entities in pairs(self.collideables) do
|
||||
self.collidableMatrices[color] = self:createEntityMatrix(entities)
|
||||
end
|
||||
-- Dialogables (npcs) block every channel, so stamp them into each matrix.
|
||||
for _, npc in ipairs(self.npcs) do
|
||||
for _, cell in ipairs(npc:getOccupiedCells()) do
|
||||
for color in pairs(self.collidableMatrices) do
|
||||
self.collidableMatrices[color][cell.y][cell.x] = npc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Room:createSwitchMatrix()
|
||||
|
|
@ -541,8 +541,9 @@ end
|
|||
-- keyword handled directly since it has no art.
|
||||
function Room:createEntity(class, color, x, y)
|
||||
if class == "npc" then
|
||||
self:registerNpc(x, y)
|
||||
return
|
||||
local entity = Sign:new(x, y)
|
||||
self:registerNpc(entity)
|
||||
return entity
|
||||
end
|
||||
|
||||
local props = globalAssetProperties and globalAssetProperties[class]
|
||||
|
|
@ -602,8 +603,11 @@ function Room:registerPlayer(entityPointer, color)
|
|||
self.player[color] = entityPointer
|
||||
end
|
||||
|
||||
function Room:registerNpc(x, y)
|
||||
table.insert(self.npcs, { x = x, y = y })
|
||||
function Room:registerNpc(entity)
|
||||
-- npcs are dialogable entities: they carry .x/.y like any Entity, so
|
||||
-- serialize's npc loop still round-trips them, and they get stamped into the
|
||||
-- collision matrix (see createCollideablesMatrix) so a bump is a rejected move.
|
||||
table.insert(self.npcs, entity)
|
||||
end
|
||||
|
||||
function Room:getCellFromMousePos(mouseX, mouseY)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue