fixed overlap chec

This commit is contained in:
0x81c 2015-03-16 08:47:08 -04:00
parent df7dd1b1f3
commit cd2e0d862a
4 changed files with 44 additions and 11 deletions

View file

@ -143,10 +143,13 @@ end
function Room:movePlayer(key)
local moved = false
local previousPositions = {} --these are so we can perform the overlap chec_
local newPositions = {}
for _, color in pairs(self:getActiveColors()) do
local entitiesToPush, entitiesToPull = {}, {}
local pos = self.player[color]:getGridPos()
previousPositions[color] = pos
local x, y = pos.x, pos.y
local dir = {x = 0, y = 0}
local axis
@ -288,10 +291,11 @@ function Room:movePlayer(key)
self.player[color]:move(axis, dir[axis])
moved = true
end
newPositions[color] = self.player[color]:getGridPos()
end
if moved then
self:playerJoinCheck(previousPositions, newPositions)
self:tick()
end
end
@ -330,6 +334,13 @@ function Room:getActiveColors()
return colors
end
function Room:colorIsActive(color)
if self.activeColors[color] then
return true
end
return false
end
function Room:getInactiveColors()
local colors = {}
@ -375,12 +386,21 @@ function Room:tick()
print(door)
door:setColors(setDoorColors)
end
self:playerJoinCheck()
self:nextRoomCheck()
end
function Room:playerJoinCheck()
local join = {}
function Room:playerJoinCheck(previousPositions, newPositions)
local activate = {}
local deactivate = {}
local activeColors = self:getActiveColors()
for _, color in ipairs(activeColors) do
if #activeColors > 1 then
if Entity.positionsAreEqual(previousPositions[color], newPositions[color]) then
table.insert(deactivate, color)
end
end
end
for _, inactiveColor in ipairs(self:getInactiveColors()) do
local overlapping = 0
@ -393,13 +413,17 @@ function Room:playerJoinCheck()
end
end
if overlapping == #activeColors then
table.insert(join, inactiveColor)
table.insert(activate, inactiveColor)
end
end
for _, color in ipairs(join) do
for _, color in ipairs(activate) do
self:setActiveColor(color, true)
end
for _, color in ipairs(deactivate) do
self:setActiveColor(color, false)
end
end
function Room:getPlayerPos(color)