some changes, idr, hehe sorry

This commit is contained in:
0x81c 2015-03-15 05:26:47 -04:00
parent c668dc513b
commit b553d3f664
5 changed files with 116 additions and 48 deletions

129
room.lua
View file

@ -7,16 +7,14 @@ require "artifact"
require "npc"
require "art"
require "assorted"
require "switch"
function Room:initialize(t)
self.exits = t.exits
self.name = t.name
self.player = Player:new(t.player.x, t.player.y, t.player.activeColors)
self.collideables = {
red = {},
green = {},
blue = {}
}
self.switches = { red = {}, green = {}, blue = {} }
self.collideables = { red = {}, green = {}, blue = {} }
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...}
self.activeColors = {
@ -44,6 +42,13 @@ function Room:initialize(t)
end
end
for i = 0, 5 do
local x, y = randomPosition()
print(x, y)
local c = randomColor()
table.insert(self.switches[c], Switch:new(x, y, c))
end
for color, active in pairs(self.activeColors) do
local x, y = 6, 3
-- if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "animals/processed/", "me_rach") end
@ -77,6 +82,11 @@ function Room:draw()
entity:draw()
end
end
for color, switchArray in pairs(self.switches) do
for _, switch in pairs(switchArray) do
switch:draw()
end
end
end
function Room:createCollideablesMatrix(collideables)
@ -128,7 +138,7 @@ function Room:movePlayer(key)
dir.x, axis = 1, "x"
end
local move
local move = true
local entitiesToPush = {
red = {},
green = {},
@ -146,55 +156,58 @@ function Room:movePlayer(key)
x = pos.x + dir.x, y = pos.y + dir.y
} -- this is for reference for each color as we change the targetCells table
local move = true
local targetCells
if not self:isInBounds(initialTargetCell) then
move = true
else
local targetCells
--so the way this worx is....
for _, color in pairs(activeColors) do
--for each color...
targetCells = {initialTargetCell} -- ...we start with our attempted movement...
local doneSearching
while not doneSearching do
nextTargetCells = {} -- ...then we create this array to save our next group of cells
local emptyCells = {}
for _, cell in pairs(targetCells) do
if self:isInBounds(cell) then
local entity = self:getCellInMatrix(self.collidableMatrices[color], cell)
if entity then
--something is here!!
if not entitiesToPush[color][entity] then --if the entity hasnt been found already
if entity:canMove() then
local projectedCells = entity:getOccupiedCells(dir) -- we project the movement here
entitiesToPush[color][entity] = entity
for _, projectedCell in ipairs(projectedCells) do
table.insert(nextTargetCells, projectedCell)
--so the way this worx is....
for _, color in pairs(activeColors) do
--for each color...
targetCells = {initialTargetCell} -- ...we start with our attempted movement...
local doneSearching
while not doneSearching do
nextTargetCells = {} -- ...then we create this array to save our next group of cells
local emptyCells = {}
for _, cell in pairs(targetCells) do
if self:isInBounds(cell) then
local entity = self:getCellInMatrix(self.collidableMatrices[color], cell)
if entity then
--something is here!!
if not entitiesToPush[color][entity] then --if the entity hasnt been found already
if entity:canMove() then
local projectedCells = entity:getOccupiedCells(dir) -- we project the movement here
entitiesToPush[color][entity] = entity
for _, projectedCell in ipairs(projectedCells) do
table.insert(nextTargetCells, projectedCell)
end
else
move = false
doneSearching = true
end
else
move = false
doneSearching = true
end
else
--there's nothin there!!
table.insert(emptyCells, cell)
end
else
--there's nothin there!!
table.insert(emptyCells, cell)
else
--we are out of bounds now
move = false
doneSearching = true
end
else
--we are out of bounds now
move = false
end
--if every projected cell is empty then we can do the move
if #emptyCells == #targetCells then
move = true
doneSearching = true
end
end
--if every projected cell is empty then we can do the move
if #emptyCells == #targetCells then
move = true
doneSearching = true
targetCells = nextTargetCells
end
targetCells = nextTargetCells
--let's get out of this loop b/c if we can't move one color we can't move at all
if move == false then break end
end
--let's get out of this loop b/c if we can't move one color we can't move at all
if move == false then break end
end
@ -309,9 +322,31 @@ function Room:isInBounds(cell)
end
function Room:nextRoomCheck()
if not self:isInBounds(self.player:getGridPos()) then
nextRoom(self.player:getGridPos())
end
end
function nextRoom()
function nextRoom(pos)
local exit
local newPos = {x = pos.x, y = pos.y}
if pos.x > gridWidth then
exit = "right"
newPos.x = 1
elseif pos.x < 1 then
exit = "left"
newPos.x = gridWidth
elseif pos.y > gridHeight then
exit = "bottom"
newPos.y = 1
elseif pos.y < 1 then
exit = "top"
newPos.y = gridHeight
end
currentRoom = Room:new{
player = {
x = newPos.x, y = newPos.y, activeColors = currentRoom.player:getActiveColors()
}
}
end