fix renderer
This commit is contained in:
parent
3ceb07f4d1
commit
886679816b
3 changed files with 42 additions and 56 deletions
45
room.lua
45
room.lua
|
|
@ -124,41 +124,20 @@ end
|
|||
|
||||
function Room:draw()
|
||||
|
||||
-- you only perceive the color channels the player actually has: with only a
|
||||
-- red copy, only the red layer is drawn (a stacked r+g+b wall shows as red,
|
||||
-- not white). Doors span all channels, so dedupe and draw them once.
|
||||
local visible = {}
|
||||
for _, c in ipairs(self.colorsPlayerHas) do visible[c] = true end
|
||||
-- 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
|
||||
|
||||
for color, player in pairs(self.player) do
|
||||
if visible[color] then player:draw() end
|
||||
end
|
||||
local drawnDoors = {}
|
||||
for color, entityArray in pairs(self.collideables) do
|
||||
if visible[color] then
|
||||
for _, entity in pairs(entityArray) do
|
||||
if entity:isInstanceOf(Door) then
|
||||
if not drawnDoors[entity] then
|
||||
drawnDoors[entity] = true
|
||||
entity:draw()
|
||||
end
|
||||
else
|
||||
entity:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for color, switchArray in pairs(self.switches) do
|
||||
if visible[color] then
|
||||
for _, switch in pairs(switchArray) do
|
||||
switch:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
-- npcs (old "sages") are just markers for now: draw a "?" in their cell,
|
||||
-- tinted to only the channels the player has (never a white pixel)
|
||||
-- npcs (old "sages") are markers for now: a "?" tinted to the player's channels
|
||||
local cellW, cellH = width / gridWidth, height / gridHeight
|
||||
love.graphics.setColor(visible.red and 255 or 0, visible.green and 255 or 0, visible.blue and 255 or 0)
|
||||
love.graphics.setColor(has.red and 255 or 0, has.green and 255 or 0, has.blue and 255 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)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue