toreit out git add -A
This commit is contained in:
parent
2f40eaf000
commit
3ae6c416e5
2 changed files with 4 additions and 109 deletions
100
room.lua
100
room.lua
|
|
@ -77,33 +77,6 @@ end
|
|||
|
||||
function Room:movePlayer(key)
|
||||
|
||||
local moveAxis
|
||||
local direction
|
||||
|
||||
if key == "up" then
|
||||
moveAxis, direction = "y", -1
|
||||
elseif key == "down" then
|
||||
moveAxis, direction = "y", 1
|
||||
elseif key == "left" then
|
||||
moveAxis, direction = "x", -1
|
||||
elseif key == "right" then
|
||||
moveAxis, direction = "x", 1
|
||||
else
|
||||
error("wtf did u do")
|
||||
end
|
||||
|
||||
for color, active in pairs(self.activeColors) do
|
||||
if active then
|
||||
local playerPos = self.player[color]:getGridPos()
|
||||
local entities = self:getAdjacentEntities(self.collideables[color], playerPos, moveAxis, direction)
|
||||
local canMove = self:tryPlayerMove(entities, playerPos, moveAxis, direction)
|
||||
if canMove then
|
||||
self:checkAndPull(self.collideables[color], playerPos, moveAxis, direction)
|
||||
self.player[color]:move(moveAxis, direction)
|
||||
self:tick()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Room:switchPlayer(colorToActivate)
|
||||
|
|
@ -121,88 +94,15 @@ function Room:setActiveColor(color, bool)
|
|||
end
|
||||
|
||||
function Room:getAdjacentEntities(entities, pos, axis, direction)
|
||||
local t = {}
|
||||
|
||||
--first we gather all entities in direction of movement
|
||||
for _, entity in pairs(entities) do
|
||||
if axis == "x" then
|
||||
if entity:isAlignedWithPlayerMovement("y", pos, direction) then
|
||||
if direction > 0 and entity:getGridPos()[axis] > pos[axis] then
|
||||
table.insert(t, entity)
|
||||
elseif direction < 0 and entity:getGridPos()[axis] < pos[axis] then
|
||||
table.insert(t, entity)
|
||||
end
|
||||
end
|
||||
elseif axis == "y" then
|
||||
if entity:isAlignedWithPlayerMovement("x", pos, direction) then
|
||||
if direction > 0 and entity:getGridPos()[axis] > pos[axis] then
|
||||
table.insert(t, entity)
|
||||
elseif direction < 0 and entity:getGridPos()[axis] < pos[axis] then
|
||||
table.insert(t, entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--then we put them in order
|
||||
table.sort(t, function(a, b)
|
||||
if direction > 0 then
|
||||
return a:getGridPos()[axis] < b:getGridPos()[axis]
|
||||
else
|
||||
return a:getGridPos()[axis] > b:getGridPos()[axis]
|
||||
end
|
||||
end)
|
||||
|
||||
shallowTablePrint(t)
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
function Room:checkAndPull(entities, pos, axis, direction)
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
if axis == "x" and entity:atGridPos(pos.x - direction, pos.y) then
|
||||
if entity:canMove() then
|
||||
entity:move(axis, direction)
|
||||
return
|
||||
end
|
||||
elseif axis == "y" and entity:atGridPos(pos.x, pos.y - direction) then
|
||||
if entity:canMove() then
|
||||
entity:move(axis, direction)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Room:tryPlayerMove(entities, pos, axis, direction)
|
||||
local counter = direction
|
||||
local entitiesToMove = {}
|
||||
local origPosAxis = pos[axis]
|
||||
|
||||
for _, entity in ipairs(entities) do
|
||||
pos[axis] = pos[axis] + direction
|
||||
print(pos[axis])
|
||||
print(origPosAxis + counter)
|
||||
if entity:atGridPos(pos.x, pos.y) then
|
||||
if entity:canMove() then
|
||||
table.insert(entitiesToMove, entity)
|
||||
else
|
||||
print(entity)
|
||||
return false
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
counter = counter + direction
|
||||
end
|
||||
|
||||
for _, entity in ipairs(entitiesToMove) do
|
||||
entity:move(axis, direction)
|
||||
end
|
||||
print("wowe true")
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Room:tick()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue