This commit is contained in:
0x81c 2015-03-25 01:38:53 -04:00 committed by Your Name
parent b19f58726c
commit 01d272981e
133 changed files with 822 additions and 66 deletions

100
room.lua
View file

@ -11,6 +11,8 @@ require "assorted"
require "switch"
require "door"
require "dialogue_manager"
require "generic_moveable"
require "generic_unmoveable"
function Room:initialize(t)
self.player = {}
@ -23,9 +25,17 @@ function Room:initialize(t)
if t.name then
print("loaded!!")
self:load(t.name)
for _, color in ipairs(t.player.activeColors) do
self:registerPlayer(Player:new(t.player.x, t.player.y, color), color)
self:setActiveColor(color, true)
print(t.name)
if t.player then
for _, color in ipairs(t.player.activeColors) do
self:registerPlayer(Player:new(t.player.x, t.player.y, color), color)
self:setActiveColor(color, true)
end
else
for color, active in pairs(self.activeColors) do
self:registerPlayer(Player:new(1, 1, color), color)
self:setActiveColor(color, true)
end
end
self.exits = t.exits
self.name = t.name
@ -45,36 +55,36 @@ function Room:initialize(t)
-- self.activeColors[color] = true
-- end
for i=1, 1 do
local x, y = randomPosition()
-- local door = Door:new(x, y, self.colorsPlayerHas)
-- table.insert(self.doors, door)
for color, active in pairs(self.activeColors) do
table.insert(self.collideables[color], Wall:new(x, y, color))
end
end
for i=0, 5 do
local x, y = randomPosition()
for color, active in pairs(self.activeColors) do
table.insert(self.collideables[color], Box:new(x, y, color))
end
end
-- for i = 0, 5 do
-- for i=1, 1 do
-- local x, y = randomPosition()
-- print(x, y)
-- local c = randomColor()
-- table.insert(self.switches[c], Switch:new(x, y, c))
-- -- local door = Door:new(x, y, self.colorsPlayerHas)
-- -- table.insert(self.doors, door)
-- for color, active in pairs(self.activeColors) do
-- table.insert(self.collideables[color], Wall:new(x, y, color))
-- end
-- end
-- for i=0, 5 do
-- local x, y = randomPosition()
-- for color, active in pairs(self.activeColors) do
-- table.insert(self.collideables[color], Box:new(x, y, color))
-- 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
local x, y = 1, 1
if active then table.insert(self.collideables[color], Ass:new(x, y, color, "nature/", "palm_scaled_reduced")) end
-- if active then table.insert(self.collideables[color], Ass:new(x, y, color, "nature/", "palm_scaled_reduced")) end
-- local x, y = 7, 7
-- if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "food/processed/", "beer_mug") end
@ -539,6 +549,44 @@ function Room:registerPlayer(entityPointer, color)
self.player[color] = entityPointer
end
function Room:getCellFromMousePos(mouseX, mouseY)
local cell = {}
cell.x = math.ceil(mouseX * gridWidth / width)
cell.y = math.ceil(mouseY * gridHeight / height)
return cell
end
function Room:attemptDelete(mouseX, mouseY)
local cell = self:getCellFromMousePos(mouseX, mouseY)
for color, player in pairs(self.player) do
if player:occupiesCell(cell) then
self.player[color] = nil
self.colorsPlayerHas[color] = false
end
end
local entities = {}
for color, entityArray in pairs(self.collideables) do
for index, entity in pairs(entityArray) do
if entity:occupiesCell(cell) then
table.remove(self.collideables[color], index)
end
end
end
for color, switches in pairs(self.switches) do
for index, switch in pairs(switches) do
if switch:occupiesCell(cell) then
print("assssss occupied scellsll")
table.remove(self.switches[color], index)
end
end
end
self:tick()
end
function Room:attemptPlace()
end
function Room:load(name)
local room = love.filesystem.read("rooms/" .. name .. ".sav")
self:deserialize(TSerial.unpack(room))
@ -614,7 +662,7 @@ function nextRoom(pos)
currentRoom:save()
currentRoom = Room:new{
name = "test",
-- name = "test",
player = {
x = newPos.x, y = newPos.y, activeColors = currentRoom:getActiveColors()
}