fixed overlap chec
This commit is contained in:
parent
df7dd1b1f3
commit
cd2e0d862a
4 changed files with 44 additions and 11 deletions
1
box.lua
1
box.lua
|
|
@ -6,7 +6,6 @@ function Box:initialize(x, y, color)
|
||||||
Entity.initialize(self, {
|
Entity.initialize(self, {
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
name = "box",
|
|
||||||
sizeX = 1,
|
sizeX = 1,
|
||||||
sizeY = 1,
|
sizeY = 1,
|
||||||
color = color,
|
color = color,
|
||||||
|
|
|
||||||
11
entity.lua
11
entity.lua
|
|
@ -10,7 +10,7 @@ function Entity:initialize(t)
|
||||||
self.collision = t.collision --"none", "moveable", "unmoveable"
|
self.collision = t.collision --"none", "moveable", "unmoveable"
|
||||||
self.sprite = t.sprite
|
self.sprite = t.sprite
|
||||||
self.shaAmount = t.sha or 1
|
self.shaAmount = t.sha or 1
|
||||||
self.onBump = t.onBump or function() return true end
|
self.onBump = t.onBump or function(self) return true end
|
||||||
|
|
||||||
self.drawOffset = {x = 0, y = 0}
|
self.drawOffset = {x = 0, y = 0}
|
||||||
if self.size.w < 1 or self.size.h < 1 then
|
if self.size.w < 1 or self.size.h < 1 then
|
||||||
|
|
@ -19,6 +19,13 @@ function Entity:initialize(t)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Entity.static.positionsAreEqual = function(cell1, cell2)
|
||||||
|
if cell1.x == cell2.x and cell1.y == cell2.y then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function Entity:getCollision()
|
function Entity:getCollision()
|
||||||
return self.collision
|
return self.collision
|
||||||
end
|
end
|
||||||
|
|
@ -126,5 +133,5 @@ function Entity:sha()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:bump()
|
function Entity:bump()
|
||||||
return self.onBump()
|
return self:onBump()
|
||||||
end
|
end
|
||||||
7
npc.lua
7
npc.lua
|
|
@ -5,7 +5,10 @@ function npc:initialize(x, y, color, name)
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
color = color,
|
color = color,
|
||||||
collision = "none", --player can't push other player
|
collision = "unmoveable",
|
||||||
sprite = sprites.npc[name][color]
|
sprite = sprites.npc[name][color],
|
||||||
|
onBump = function(self)
|
||||||
|
self.tal_ing = true
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
36
room.lua
36
room.lua
|
|
@ -143,10 +143,13 @@ end
|
||||||
function Room:movePlayer(key)
|
function Room:movePlayer(key)
|
||||||
|
|
||||||
local moved = false
|
local moved = false
|
||||||
|
local previousPositions = {} --these are so we can perform the overlap chec_
|
||||||
|
local newPositions = {}
|
||||||
|
|
||||||
for _, color in pairs(self:getActiveColors()) do
|
for _, color in pairs(self:getActiveColors()) do
|
||||||
local entitiesToPush, entitiesToPull = {}, {}
|
local entitiesToPush, entitiesToPull = {}, {}
|
||||||
local pos = self.player[color]:getGridPos()
|
local pos = self.player[color]:getGridPos()
|
||||||
|
previousPositions[color] = pos
|
||||||
local x, y = pos.x, pos.y
|
local x, y = pos.x, pos.y
|
||||||
local dir = {x = 0, y = 0}
|
local dir = {x = 0, y = 0}
|
||||||
local axis
|
local axis
|
||||||
|
|
@ -288,10 +291,11 @@ function Room:movePlayer(key)
|
||||||
self.player[color]:move(axis, dir[axis])
|
self.player[color]:move(axis, dir[axis])
|
||||||
moved = true
|
moved = true
|
||||||
end
|
end
|
||||||
|
newPositions[color] = self.player[color]:getGridPos()
|
||||||
end
|
end
|
||||||
|
|
||||||
if moved then
|
if moved then
|
||||||
|
self:playerJoinCheck(previousPositions, newPositions)
|
||||||
self:tick()
|
self:tick()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -330,6 +334,13 @@ function Room:getActiveColors()
|
||||||
return colors
|
return colors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Room:colorIsActive(color)
|
||||||
|
if self.activeColors[color] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function Room:getInactiveColors()
|
function Room:getInactiveColors()
|
||||||
local colors = {}
|
local colors = {}
|
||||||
|
|
||||||
|
|
@ -375,12 +386,21 @@ function Room:tick()
|
||||||
print(door)
|
print(door)
|
||||||
door:setColors(setDoorColors)
|
door:setColors(setDoorColors)
|
||||||
end
|
end
|
||||||
self:playerJoinCheck()
|
|
||||||
self:nextRoomCheck()
|
self:nextRoomCheck()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:playerJoinCheck()
|
function Room:playerJoinCheck(previousPositions, newPositions)
|
||||||
local join = {}
|
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
|
for _, inactiveColor in ipairs(self:getInactiveColors()) do
|
||||||
local overlapping = 0
|
local overlapping = 0
|
||||||
|
|
@ -393,13 +413,17 @@ function Room:playerJoinCheck()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if overlapping == #activeColors then
|
if overlapping == #activeColors then
|
||||||
table.insert(join, inactiveColor)
|
table.insert(activate, inactiveColor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, color in ipairs(join) do
|
for _, color in ipairs(activate) do
|
||||||
self:setActiveColor(color, true)
|
self:setActiveColor(color, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for _, color in ipairs(deactivate) do
|
||||||
|
self:setActiveColor(color, false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:getPlayerPos(color)
|
function Room:getPlayerPos(color)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue