From 286871ca2175edd4967a1262920018f2235548c4 Mon Sep 17 00:00:00 2001 From: 0x81c Date: Sat, 14 Mar 2015 06:18:04 -0400 Subject: [PATCH] rewritten --- artifact.lua | 5 +---- input.lua | 4 ++-- main.lua | 2 +- player.lua | 2 -- room.lua | 17 +++++++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/artifact.lua b/artifact.lua index 21aff5b..75692fc 100644 --- a/artifact.lua +++ b/artifact.lua @@ -3,14 +3,11 @@ require "entity" Artifact = class("Artifact", Entity) function Artifact:initialize(x, y, color) - print(artifactSprite:getWidth(), artifactSprite:getHeight()) Entity.initialize(self, { x = x, y = y, - sizeX = artifactSprite:getWidth() / 16, - sizeY = artifactSprite:getHeight() / 16, color = color, - collision = "unmoveable", --player can't push other player + collision = "unmoveable", sprite = artifactSprite }) end \ No newline at end of file diff --git a/input.lua b/input.lua index 1b003c4..eeb1cf4 100644 --- a/input.lua +++ b/input.lua @@ -1,8 +1,8 @@ Input = {} Input.playermovekeys = { up = "up", down = "down", left = "left", right = "right" } -Input.playerswitchkeys = { ["1"] = "1", ["2"] = "2", ["3"] = "3" } -Input.colorfromkey = {"red", "green", "blue"} +Input.playerswitchkeys = { ["1"] = "1", ["2"] = "2", ["3"] = "3", ["4"] = "4" } +Input.colorfromkey = {"red", "green", "blue", "white"} function Input:handler() diff --git a/main.lua b/main.lua index 1e557d9..32e4f81 100644 --- a/main.lua +++ b/main.lua @@ -77,7 +77,7 @@ function love.keypressed(key) currentRoom:movePlayer(key) elseif Input.isPlayerSwitch(key) then local c = Input.playerColor(key) - currentRoom:switchPlayer(c) + currentRoom:switchPlayerColor(c) end if key == "w" then worldSha = worldSha + 1 diff --git a/player.lua b/player.lua index 77d05a1..e9591b4 100644 --- a/player.lua +++ b/player.lua @@ -3,7 +3,6 @@ require "entity" Player = class("Player", Entity) function Player:initialize(x, y, color) - Entity.initialize(self, { x = x, y = y, @@ -13,7 +12,6 @@ function Player:initialize(x, y, color) collision = "none", --player can't push other player sprite = playerSprite }) - end function Player:update() diff --git a/room.lua b/room.lua index f14a963..9cec648 100644 --- a/room.lua +++ b/room.lua @@ -66,7 +66,9 @@ end function Room:draw() for color, player in pairs(self.player) do - player:draw() + if self.activeColors[color] then + player:draw() + end end for color, entityArray in pairs(self.collideables) do for _, entity in pairs(entityArray) do @@ -79,12 +81,15 @@ function Room:movePlayer(key) end -function Room:switchPlayer(colorToActivate) - for color, active in pairs(self.activeColors) do - if color == colorToActivate then - self:setActiveColor(color, true) +function Room:switchPlayerColor(color) + print(color) + for c, active in pairs(self.activeColors) do + if color == "white" then + self:setActiveColor(c, true) + elseif c == color then + self:setActiveColor(c, true) else - self:setActiveColor(color, false) + self:setActiveColor(c, false) end end end