player done, old way

This commit is contained in:
0x81c 2015-03-15 15:34:17 -04:00
parent 687939b269
commit 1156564fa2
4 changed files with 184 additions and 103 deletions

View file

@ -1,8 +1,8 @@
Input = {} Input = {}
Input.playermovekeys = { up = "up", down = "down", left = "left", right = "right" } Input.playermovekeys = { up = "up", down = "down", left = "left", right = "right" }
Input.playerswitchkeys = { ["1"] = "1", ["2"] = "2", ["3"] = "3", ["4"] = "4" } Input.playerswitchkeys = { ["1"] = "1", ["2"] = "2", ["3"] = "3"}
Input.colorfromkey = {"red", "green", "blue", "white"} Input.colorfromkey = {"red", "green", "blue"}
function Input:handler() function Input:handler()

View file

@ -7,15 +7,14 @@ Player.static.sounds = {
switchSuccess = love.audio.newSource("sounds/switch_success.wav") switchSuccess = love.audio.newSource("sounds/switch_success.wav")
} }
function Player:initialize(x, y, activeColors) function Player:initialize(x, y, color)
Entity.initialize(self, { Entity.initialize(self, {
x = x, x = x,
y = y, y = y,
color = "white", color = color,
collision = "none", --player can't push other player collision = "none", --player can't push other player
sprite = playerSprite sprite = playerSprite
}) })
self.activeColors = activeColors or {"red", "green", "blue"}
end end
function Player:setActiveColors(colorArray) function Player:setActiveColors(colorArray)
@ -40,11 +39,3 @@ function Player:playSwitchSound(success)
sound:stop() sound:stop()
sound:play() sound:play()
end end
function Player:draw()
for _, color in ipairs(self.activeColors) do
love.graphics.setColor(gColor[color]:set())
local p = self:getDrawPos()
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
end
end

241
room.lua
View file

@ -14,23 +14,26 @@ function Room:initialize(t)
self.colorsPlayerHas = {"red", "green", "blue"} self.colorsPlayerHas = {"red", "green", "blue"}
self.exits = t.exits self.exits = t.exits
self.name = t.name self.name = t.name
self.player = Player:new(t.player.x, t.player.y, t.player.activeColors) self.player = {}
self.switches = { red = {}, green = {}, blue = {} } self.switches = { red = {}, green = {}, blue = {} }
self.switchMatrices = {} self.switchMatrices = {}
self.collideables = { red = {}, green = {}, blue = {} } self.collideables = { red = {}, green = {}, blue = {} }
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ... self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...
for _, color in ipairs(t.player.activeColors) do
self.player[color] = Player:new(t.player.x, t.player.y, color)
end
self.doors = {} self.doors = {}
self.activeColors = { self.activeColors = {}
red = true, green = true, blue = true for _, color in ipairs(t.player.activeColors) do self.activeColors[color] = true end
}
-- for color, coords in pairs(t.player) do -- for color, coords in pairs(t.player) do
-- self.player[color] = Player:new(coords.x, coords.y, color) -- self.player[color] = Player:new(coords.x, coords.y, color)
-- self.activeColors[color] = true -- self.activeColors[color] = true
-- end -- end
for i=1, 5 do for i=1, 30 do
local x, y = randomPosition() local x, y = randomPosition()
local door = Door:new(x, y, self.colorsPlayerHas) local door = Door:new(x, y, self.colorsPlayerHas)
table.insert(self.doors, door) table.insert(self.doors, door)
@ -65,9 +68,9 @@ function Room:initialize(t)
local x, y = 7, 7 local x, y = 7, 7
if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "food/processed/", "beer_mug") end if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "food/processed/", "beer_mug") end
self.collideables[color]["fpp"] = Artifact:new(6, 6, color)
end end
-- self.collideables["green"]["fpp"] = Artifact:new(6, 6, "green")
for color, entities in pairs(self.collideables) do for color, entities in pairs(self.collideables) do
self.collidableMatrices[color] = self:createEntityMatrix(entities) self.collidableMatrices[color] = self:createEntityMatrix(entities)
@ -76,12 +79,16 @@ end
function Room:update(dt) function Room:update(dt)
self.player:update(dt) for color, player in pairs(self.player) do
player:update(dt)
end
end end
function Room:draw() function Room:draw()
self.player:draw()
for color, player in pairs(self.player) do
player:draw()
end
for color, entityArray in pairs(self.collideables) do for color, entityArray in pairs(self.collideables) do
for _, entity in pairs(entityArray) do for _, entity in pairs(entityArray) do
entity:draw() entity:draw()
@ -134,50 +141,40 @@ function Room:getCellInMatrix(matrix, cell)
end end
function Room:movePlayer(key) function Room:movePlayer(key)
local activeColors = self.player:getActiveColors()
local pos = self.player:getGridPos()
local x, y = pos.x, pos.y
local dir = {x = 0, y = 0}
local axis
if key == "up" then local moved = false
dir.y, axis = -1, "y"
elseif key == "down" then
dir.y, axis = 1, "y"
elseif key == "left" then
dir.x, axis = -1, "x"
elseif key == "right" then
dir.x, axis = 1, "x"
end
local move = true for _, color in pairs(self:getActiveColors()) do
local entitiesToPush = { local entitiesToPush, entitiesToPull = {}, {}
red = {}, local pos = self.player[color]:getGridPos()
green = {}, local x, y = pos.x, pos.y
blue = {} local dir = {x = 0, y = 0}
} local axis
local entitiesToPull = {
red = {},
green = {},
blue = {}
}
-- PUSHHHHHHHHHHHHHHHHHHHHHH--------------------- if key == "up" then
dir.y, axis = -1, "y"
elseif key == "down" then
dir.y, axis = 1, "y"
elseif key == "left" then
dir.x, axis = -1, "x"
elseif key == "right" then
dir.x, axis = 1, "x"
end
local initialTargetCell = { local move = true
x = pos.x + dir.x, y = pos.y + dir.y -- PUSHHHHHHHHHHHHHHHHHHHHHH---------------------
} -- this is for reference for each color as we change the targetCells table
if not self:isInBounds(initialTargetCell) then local initialTargetCell = {
move = true x = pos.x + dir.x, y = pos.y + dir.y
elseif self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell) and self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell):canPassOver() then } -- this is for reference for each color as we change the targetCells table
move = true
else if not self:isInBounds(initialTargetCell) then
local targetCells move = true
elseif self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell) and self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell):canPassOver() 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... targetCells = {initialTargetCell} -- ...we start with our attempted movement...
local doneSearching local doneSearching
while not doneSearching do while not doneSearching do
@ -188,10 +185,10 @@ function Room:movePlayer(key)
local entity = self:getCellInMatrix(self.collidableMatrices[color], cell) local entity = self:getCellInMatrix(self.collidableMatrices[color], cell)
if entity then if entity then
--something is here!! --something is here!!
if not entitiesToPush[color][entity] then --if the entity hasnt been found already if not entitiesToPush[entity] then --if the entity hasnt been found already
if entity:canMove() then if entity:canMove() then
local projectedCells = entity:getOccupiedCells(dir) -- we project the movement here local projectedCells = entity:getOccupiedCells(dir) -- we project the movement here
entitiesToPush[color][entity] = entity entitiesToPush[entity] = entity
for _, projectedCell in ipairs(projectedCells) do for _, projectedCell in ipairs(projectedCells) do
table.insert(nextTargetCells, projectedCell) table.insert(nextTargetCells, projectedCell)
end end
@ -220,20 +217,16 @@ function Room:movePlayer(key)
targetCells = nextTargetCells targetCells = nextTargetCells
end end
--let's get out of this loop b/c if we can't move one color we can't move at all --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 end
end
---PULL CHEC ---PULL CHEC
local initialTargetCell = {x = pos.x - dir.x, y = pos.y - dir.y} local initialTargetCell = {x = pos.x - dir.x, y = pos.y - dir.y}
local targetCells local targetCells
local pull = {} local pull = {}
--so the way this worx is....
for _, color in pairs(activeColors) do
--for each color... --for each color...
targetCells = {initialTargetCell} -- ...we start with our attempted movement... targetCells = {initialTargetCell} -- ...we start with our attempted movement...
local doneSearching local doneSearching
@ -245,10 +238,10 @@ function Room:movePlayer(key)
local entity = self:getCellInMatrix(self.collidableMatrices[color], cell) local entity = self:getCellInMatrix(self.collidableMatrices[color], cell)
if entity then if entity then
--something is here!! --something is here!!
if not entitiesToPull[color][entity] then --if the entity hasnt been found already if not entitiesToPull[entity] then --if the entity hasnt been found already
if entity:canMove() then if entity:canMove() then
local projectedCells = entity:getOccupiedCells(dir) -- we project the movement here local projectedCells = entity:getOccupiedCells(dir) -- we project the movement here
entitiesToPull[color][entity] = entity entitiesToPull[entity] = entity
for _, projectedCell in ipairs(projectedCells) do for _, projectedCell in ipairs(projectedCells) do
table.insert(nextTargetCells, projectedCell) table.insert(nextTargetCells, projectedCell)
end end
@ -262,7 +255,6 @@ function Room:movePlayer(key)
table.insert(emptyCells, cell) table.insert(emptyCells, cell)
end end
else else
pull[color] = true
--we are out of bounds now --we are out of bounds now
doneSearching = true doneSearching = true
end end
@ -270,58 +262,96 @@ function Room:movePlayer(key)
--if every projected cell is empty then we can do the move --if every projected cell is empty then we can do the move
if #emptyCells == #targetCells then if #emptyCells == #targetCells then
pull[color] = true
doneSearching = true doneSearching = true
end end
targetCells = nextTargetCells targetCells = nextTargetCells
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
if move then
for _, entity in pairs(entitiesToPush) do
if move then
for color, entities in pairs(entitiesToPush) do
for _, entity in pairs(entities) do
entity:move(axis, dir[axis]) entity:move(axis, dir[axis])
end end
end for _, entity in pairs(entitiesToPull) do
for color, entities in pairs(entitiesToPull) do entity:move(axis, dir[axis])
if pull[color] then
for _, entity in pairs(entities) do
entity:move(axis, dir[axis])
end
end end
self.player[color]:move(axis, dir[axis])
moved = true
end end
self.player:move(axis, dir[axis])
end
if moved then
self:tick() self:tick()
end end
end end
function Room:switchPlayerColor(color) function Room:switchPlayerColor(color)
local colors local canSwitch
if color == "white" then colors = {"red", "green", "blue"} else colors = {color} end
local canSwitch = true if self:onlyColorIsActive(color) then
local playerPos = self.player:getGridPos() canSwitch = false
else
for _, color in ipairs(colors) do for _, c in pairs(self:getPossibleColors()) do
if self:getCellInMatrix(self.collidableMatrices[color], playerPos) then if c == color then
canSwitch = false self:setActiveColor(c, true)
else
self:setActiveColor(c, false)
end
end end
end end
if canSwitch then
self.player:setActiveColors(colors) self.player[color]:playSwitchSound(canSwitch)
end
self.player:playSwitchSound(canSwitch)
end end
function Room:setActiveColor(color, bool) function Room:setActiveColor(color, bool)
self.activeColors[color] = bool self.activeColors[color] = bool
end end
function Room:getActiveColors()
local colors = {}
for color, active in pairs(self.activeColors) do
if active then
table.insert(colors, color)
end
end
return colors
end
function Room:getInactiveColors()
local colors = {}
for color, active in pairs(self.activeColors) do
if not active then
table.insert(colors, color)
end
end
return colors
end
function Room:getPossibleColors()
local colors = {}
for _, color in ipairs(self.colorsPlayerHas) do
table.insert(colors, color)
print(color)
end
return colors
end
function Room:onlyColorIsActive(color)
local activeColors = self:getActiveColors()
if #activeColors == 1 and activeColors[1] == color then
return true
else
return false
end
end
function Room:tick() function Room:tick()
for color, entityArray in pairs(self.collideables) do for color, entityArray in pairs(self.collideables) do
for _, entity in pairs(entityArray) do for _, entity in pairs(entityArray) do
@ -335,9 +365,37 @@ 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()
local join = {}
for _, inactiveColor in ipairs(self:getInactiveColors()) do
local overlapping = 0
local activeColors = self:getActiveColors()
local inactivePos = self:getPlayerPos(inactiveColor)
for _, activeColor in ipairs(activeColors) do
local activePos = self:getPlayerPos(activeColor)
if activePos.x == inactivePos.x and activePos.y == inactivePos.y then
overlapping = overlapping + 1
end
end
if overlapping == #activeColors then
table.insert(join, inactiveColor)
end
end
for _, color in ipairs(join) do
self:setActiveColor(color, true)
end
end
function Room:getPlayerPos(color)
return self.player[color]:getGridPos()
end
function Room:switchCheck() function Room:switchCheck()
local doorsToUnlock = {} local doorsToUnlock = {}
for color, switchArray in pairs(self.switches) do for color, switchArray in pairs(self.switches) do
@ -367,8 +425,11 @@ function Room:isInBounds(cell)
end end
function Room:nextRoomCheck() function Room:nextRoomCheck()
if not self:isInBounds(self.player:getGridPos()) then for _, color in ipairs(self:getActiveColors()) do
nextRoom(self.player:getGridPos()) if not self:isInBounds(self.player[color]:getGridPos()) then
nextRoom(self.player[color]:getGridPos())
return
end
end end
end end
@ -391,7 +452,7 @@ function nextRoom(pos)
currentRoom = Room:new{ currentRoom = Room:new{
player = { player = {
x = newPos.x, y = newPos.y, activeColors = currentRoom.player:getActiveColors() x = newPos.x, y = newPos.y, activeColors = currentRoom:getActiveColors()
} }
} }
end end

View file

@ -29,3 +29,32 @@ wiggle = love.graphics.newShader[[
*/ */
} }
]] ]]
glow = love.graphics.newShader[[
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
vec4 pixel_me = Texel(texture, texture_coords );
if (pixel_me.rgb != vec3(0,0,0))
return pixel_me;
int samples = 5;
float intensity = 60;
float radius = .1;
for (int i = 1; i < samples; i++ ) {
vec4 pixel_left = Texel(texture, texture_coords + vec2(-radius * i, 0));
vec4 pixel_right = Texel(texture, texture_coords + vec2(radius * i, 0));
vec4 pixel_top = Texel(texture, texture_coords + vec2(0, radius * i));
vec4 pixel_bottom = Texel(texture, texture_coords + vec2(0, -radius * i));
vec4 pixel_top_left = Texel(texture, texture_coords + vec2(-radius * i, radius * i));
vec4 pixel_top_right = Texel(texture, texture_coords + vec2(radius * i, radius * i));
vec4 pixel_bottom_left = Texel(texture, texture_coords + vec2(-radius * i, -radius * i));
vec4 pixel_bottom_right = Texel(texture, texture_coords + vec2(radius * i, -radius * i));
pixel_me += (pixel_left + pixel_right + pixel_top + pixel_bottom + pixel_bottom_right + pixel_bottom_left + pixel_top_right + pixel_top_left) / (intensity * i);
intensity -= 2.5;
}
return pixel_me;
}
]]