basic stuff w movemet n collision done
This commit is contained in:
parent
bffa27ec01
commit
662de9407a
4 changed files with 30 additions and 18 deletions
24
room.lua
24
room.lua
|
|
@ -3,6 +3,7 @@ Room = class("Room")
|
|||
require "player"
|
||||
require "box"
|
||||
require "wall"
|
||||
require "artifact"
|
||||
|
||||
function Room:initialize(t)
|
||||
self.exits = t.exits
|
||||
|
|
@ -23,18 +24,21 @@ function Room:initialize(t)
|
|||
self.activeColors[color] = true
|
||||
end
|
||||
|
||||
for i=0, 50 do
|
||||
for i=0, 10 do
|
||||
local c = randomColor()
|
||||
local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
|
||||
self.collideables[c]["b: " .. x .. ", " .. y] = Box:new(x, y, c)
|
||||
end
|
||||
|
||||
|
||||
for i=0, 50 do
|
||||
for i=0, 10 do
|
||||
local c = randomColor()
|
||||
local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
|
||||
self.collideables[c]["w: " .. x .. ", " .. y] = Wall:new(x, y, c)
|
||||
end
|
||||
|
||||
self.collideables["green"]["fpp"] = Artifact:new(6, 6, "green")
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -106,7 +110,7 @@ function Room:getAdjacentEntities(entities, pos, axis, direction)
|
|||
--first we gather all entities in direction of movement
|
||||
for _, entity in pairs(entities) do
|
||||
if axis == "x" then
|
||||
if entity:isAlignedWithPlayerMovement("y", pos.y) 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
|
||||
|
|
@ -114,7 +118,7 @@ function Room:getAdjacentEntities(entities, pos, axis, direction)
|
|||
end
|
||||
end
|
||||
elseif axis == "y" then
|
||||
if entity:isAlignedWithPlayerMovement("x", pos.x) 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
|
||||
|
|
@ -139,14 +143,12 @@ end
|
|||
function Room:checkAndPull(entities, pos, axis, direction)
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
local entPos = entity:getGridPos()
|
||||
print(pos.x, pos.y, entPos.x, entPos.y)
|
||||
if axis == "x" and entPos.x == pos.x - direction and entPos.y == pos.y then
|
||||
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 entPos.x == pos.x and entPos.y == pos.y - direction then
|
||||
elseif axis == "y" and entity:atGridPos(pos.x, pos.y - direction) then
|
||||
if entity:canMove() then
|
||||
entity:move(axis, direction)
|
||||
return
|
||||
|
|
@ -160,14 +162,16 @@ function Room:tryPlayerMove(entities, pos, axis, direction)
|
|||
local entitiesToMove = {}
|
||||
|
||||
for _, entity in ipairs(entities) do
|
||||
if entity:getGridPos()[axis] == pos[axis] + counter then
|
||||
pos[axis] = pos[axis] + direction
|
||||
if entity:atGridPos(pos.x, pos.y) then
|
||||
print("HOW????")
|
||||
if entity:canMove() then
|
||||
table.insert(entitiesToMove, entity)
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
break
|
||||
-- break
|
||||
end
|
||||
counter = counter + direction
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue