automatically gets bouif pull = true then

This commit is contained in:
0x81c 2015-03-15 18:45:24 -04:00
parent 747a7b7b58
commit 214758388e
14 changed files with 143 additions and 81 deletions

View file

@ -14,6 +14,5 @@ function printMatrix(matrix)
end
function randomPosition()
print("hfhfhhdh")
return math.random(1, gridWidth), math.random(1, gridHeight)
end

BIN
art/test_object.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

View file

@ -8,6 +8,6 @@ function Artifact:initialize(x, y, color)
y = y,
color = color,
collision = "unmoveable",
sprite = artifactSprite
sprite = sprites.artifact
})
end

View file

@ -8,6 +8,7 @@ function Ass:initialize(x, y, color, folder, name)
x = x,
y = y,
color = color,
cellShape = spriteCells["mac_smaller"],
collision = "moveable", --player can't push other player
sprite = spr
})

View file

@ -6,11 +6,12 @@ function Box:initialize(x, y, color)
Entity.initialize(self, {
x = x,
y = y,
name = "box",
sizeX = 1,
sizeY = 1,
color = color,
collision = "moveable",
sprite = boxSprite[color]
sprite = sprites.box[color]
})
end

View file

@ -8,7 +8,7 @@ function Door:initialize(x, y, colors)
y = y,
color = "white",
collision = "unmoveable",
sprite = doorSprite["white"] --doesn't matter for now which we put here b/c, we override the draw function neway
sprite = sprites.door["green"] --doesn't matter for now which we put here b/c, we override the draw function neway
})
self.locked = true
@ -24,17 +24,17 @@ function Door:draw()
if active then
love.graphics.setColor(gColor[color]:set())
local p = self:getDrawPos()
love.graphics.draw(doorSprite[color], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
love.graphics.draw(sprites.door[color], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
end
end
love.graphics.setColor(gColor.white:set())
local p = self:getDrawPos()
love.graphics.draw(doorSprite["white"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
love.graphics.draw(sprites.door["white"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
else
for color, active in pairs(self.colors) do
love.graphics.setColor(gColor[color]:set())
local p = self:getDrawPos()
love.graphics.draw(doorSprite["unlocked"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
love.graphics.draw(sprites.door["unlocked"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
end
end
end

View file

@ -2,6 +2,7 @@ Entity = class("Entity")
function Entity:initialize(t)
self.x, self.y = t.x, t.y
self.name = t.name
self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()}
self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16}
self.cellShape = t.cellShape or self:cellShapeFromBox(self.size)
@ -52,10 +53,8 @@ function Entity:cellShapeFromBox(box)
for i = 1, box.w do
for j = 1, box.h do
table.insert(cells, {x = i, y = j})
io.write(" boop: " .. i .. ", " .. j)
end
end
io.write("\n")
return cells
end

View file

@ -11,13 +11,14 @@ require "input"
require "color"
require "room"
require "shaders"
require "sprite_manager"
function love.load()
_initDefaults()
_initGridVars()
_initSounds()
_initGlobalColors()
loadSprites()
processSprites()
gameCanvas = love.graphics.newCanvas()
finalCanvas = love.graphics.newCanvas()
@ -130,59 +131,4 @@ function _initSounds()
static:setVolume(.15)
static:play()
end
function createCanvases()
end
function loadSprites()
playerSprite = love.graphics.newImage("art/player.png")
wallSprite = love.graphics.newImage("art/static_wall.png")
boxSprite = {
red = love.graphics.newImage("art/wall_r.png"),
green = love.graphics.newImage("art/wall_g.png"),
blue = love.graphics.newImage("art/wall_b.png")
}
doorSprite = {
white = love.graphics.newImage("art/door_locked_w.png"),
red = love.graphics.newImage("art/door_locked_r.png"),
green = love.graphics.newImage("art/door_locked_g.png"),
blue = love.graphics.newImage("art/door_locked_b.png"),
unlocked = love.graphics.newImage("art/door_unlocked.png")
}
switchSprite = {
red = love.graphics.newImage("art/switch_r.png"),
green = love.graphics.newImage("art/switch_g.png"),
blue = love.graphics.newImage("art/switch_b.png")
}
waterSprite = {
red = love.graphics.newImage("art/nature/processed/water_r.png"),
green = love.graphics.newImage("art/nature/processed/water_g.png"),
blue = love.graphics.newImage("art/nature/processed/water_b.png")
}
npcSprites = {
}
-- local artPieceJsonString
-- for line in io.lines("art/museum/to_process/art.json") do
-- artPieceJsonString = line
-- end
-- artPieceSpritesTable = json.decode(artPieceJsonString)
-- print(artPieceSpritesTable["saturn_son"]["red"])
-- print(artSpriteJson)
-- -- sets the default input file as test.lua
-- io.input(artSpriteJson)
-- -- prints the first line of the file
-- artSpriteJsonString = io.read()
-- -- closes the open file
-- io.close(artSpriteJson)
-- artSpriteTable = json.decode(artSpriteJsonString)
-- print(artSpriteTable)
artifactSprite = love.graphics.newImage("art/process/cone.png")
end

View file

@ -6,6 +6,6 @@ function npc:initialize(x, y, color, name)
y = y,
color = color,
collision = "none", --player can't push other player
sprite = npcSprites[name][color]
sprite = sprites.npc[name][color]
})
end

View file

@ -13,7 +13,7 @@ function Player:initialize(x, y, color)
y = y,
color = color,
collision = "none", --player can't push other player
sprite = playerSprite
sprite = sprites.player
})
end

View file

@ -33,15 +33,15 @@ function Room:initialize(t)
-- self.activeColors[color] = true
-- end
-- for i=1, 30 do
-- local x, y = randomPosition()
-- local door = Door:new(x, y, self.colorsPlayerHas)
-- table.insert(self.doors, door)
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
-- self.collideables[color]["w: " .. x .. ", " .. y] = door
-- end
-- end
for color, active in pairs(self.activeColors) do
self.collideables[color]["w: " .. x .. ", " .. y] = Wall:new(x, y, color)
end
end
for i=0, 5 do
local x, y = randomPosition()
@ -226,7 +226,7 @@ function Room:movePlayer(key)
local targetCells
local pull = {}
local pull
--for each color...
targetCells = {initialTargetCell} -- ...we start with our attempted movement...
local doneSearching
@ -246,7 +246,7 @@ function Room:movePlayer(key)
table.insert(nextTargetCells, projectedCell)
end
else
pull[color] = false
pull = false
doneSearching = true
end
end
@ -262,6 +262,7 @@ function Room:movePlayer(key)
--if every projected cell is empty then we can do the move
if #emptyCells == #targetCells then
pull = true
doneSearching = true
end
@ -272,8 +273,10 @@ function Room:movePlayer(key)
for _, entity in pairs(entitiesToPush) do
entity:move(axis, dir[axis])
end
for _, entity in pairs(entitiesToPull) do
entity:move(axis, dir[axis])
if pull == true then
for _, entity in pairs(entitiesToPull) do
entity:move(axis, dir[axis])
end
end
self.player[color]:move(axis, dir[axis])
moved = true

112
sprite_manager.lua Normal file
View file

@ -0,0 +1,112 @@
sprites = {
player = love.graphics.newImage("art/player.png"),
wall = love.graphics.newImage("art/static_wall.png"),
box = {
red = love.graphics.newImage("art/wall_r.png"),
green = love.graphics.newImage("art/wall_g.png"),
blue = love.graphics.newImage("art/wall_b.png")
},
door = {
white = love.graphics.newImage("art/door_locked_w.png"),
red = love.graphics.newImage("art/door_locked_r.png"),
green = love.graphics.newImage("art/door_locked_g.png"),
blue = love.graphics.newImage("art/door_locked_b.png"),
unlocked = love.graphics.newImage("art/door_unlocked.png")
},
switch = {
red = love.graphics.newImage("art/switch_r.png"),
green = love.graphics.newImage("art/switch_g.png"),
blue = love.graphics.newImage("art/switch_b.png")
},
water = {
red = love.graphics.newImage("art/nature/processed/water_r.png"),
green = love.graphics.newImage("art/nature/processed/water_g.png"),
blue = love.graphics.newImage("art/nature/processed/water_b.png")
},
mac_smaller = love.graphics.newImage("art/tech/processed/mac_smaller_r.png"),
test_object = love.graphics.newImage("art/test_object.png"),
npcs = {
},
artifact = love.graphics.newImage("art/process/cone.png"),
}
spriteCells = {}
function processSprites()
getCellsFromSprite(sprites.player)
for name, spriteObj in pairs(sprites) do
print(name)
if type(spriteObj) == "table" then
spriteCells[name] = {}
--this is multicolored so...
for color, sprite in pairs(spriteObj) do
spriteCells[color] = getCellsFromSprite(sprite)
end
else
--assume it's an image obj
spriteCells[name] = getCellsFromSprite(spriteObj)
end
end
end
function getCellsFromSprite(sprite)
local w, h = sprite:getWidth(), sprite:getHeight()
local box = {w = w / 16, h = h / 16}
local boxCells = cellShapeFromBox(box)
if box.w < 1 or box.h < 1 then
return boxCells
end
local img = sprite:getData()
local cellsToRemove = {}
local stop
for _, cell in pairs(boxCells) do
local startPixel = {x = (cell.x - 1) * 16, y = (cell.y - 1) * 16}
local endPixel = {x = (cell.x * 16) - 1, y = (cell.y * 16) - 1}
local empty = true
for i = startPixel.x, endPixel.x do
for j = startPixel.y, endPixel.y do
local r, g, b, a = img:getPixel(i, j)
if a > 0 and (r > 0 or g > 0 or b > 0) then
--this cell has color so
empty = false
end
end
end
if empty then
print("empty @ ", cell.x, cell.y)
cellsToRemove[cell] = cell --references boxCells cell so comparison should wor_
end
end
local i = 1
while i <= #boxCells do
if boxCells[i] == cellsToRemove[boxCells[i]] then
table.remove(boxCells, i)
else
i = i + 1
end
end
shallowTablePrint(boxCells)
return boxCells
end
function cellShapeFromBox(box)
local cells = {}
for i = 1, box.w do
for j = 1, box.h do
table.insert(cells, {x = i, y = j})
end
end
return cells
end

View file

@ -15,7 +15,7 @@ function Switch:initialize(x, y, color)
y = y,
color = color,
collision = "none", --switches are floor elements that can't be pushed or bloc movement!!
sprite = Switch.sprites[color]
sprite = sprites.switch[color]
})
self.activated = false

View file

@ -9,8 +9,9 @@ function Wall:initialize(x, y, color)
sizeX = 1,
sizeY = 1,
color = color,
cellShape = spriteCells.test_object,
collision = "unmoveable",
sprite = wallSprite
sprite = sprites.test_object
})
end