automatically gets bouif pull = true then
This commit is contained in:
parent
747a7b7b58
commit
214758388e
14 changed files with 143 additions and 81 deletions
|
|
@ -14,6 +14,5 @@ function printMatrix(matrix)
|
||||||
end
|
end
|
||||||
|
|
||||||
function randomPosition()
|
function randomPosition()
|
||||||
print("hfhfhhdh")
|
|
||||||
return math.random(1, gridWidth), math.random(1, gridHeight)
|
return math.random(1, gridWidth), math.random(1, gridHeight)
|
||||||
end
|
end
|
||||||
BIN
art/test_object.png
Normal file
BIN
art/test_object.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 948 B |
|
|
@ -8,6 +8,6 @@ function Artifact:initialize(x, y, color)
|
||||||
y = y,
|
y = y,
|
||||||
color = color,
|
color = color,
|
||||||
collision = "unmoveable",
|
collision = "unmoveable",
|
||||||
sprite = artifactSprite
|
sprite = sprites.artifact
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
@ -8,6 +8,7 @@ function Ass:initialize(x, y, color, folder, name)
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
color = color,
|
color = color,
|
||||||
|
cellShape = spriteCells["mac_smaller"],
|
||||||
collision = "moveable", --player can't push other player
|
collision = "moveable", --player can't push other player
|
||||||
sprite = spr
|
sprite = spr
|
||||||
})
|
})
|
||||||
|
|
|
||||||
3
box.lua
3
box.lua
|
|
@ -6,11 +6,12 @@ function Box:initialize(x, y, color)
|
||||||
Entity.initialize(self, {
|
Entity.initialize(self, {
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
|
name = "box",
|
||||||
sizeX = 1,
|
sizeX = 1,
|
||||||
sizeY = 1,
|
sizeY = 1,
|
||||||
color = color,
|
color = color,
|
||||||
collision = "moveable",
|
collision = "moveable",
|
||||||
sprite = boxSprite[color]
|
sprite = sprites.box[color]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
8
door.lua
8
door.lua
|
|
@ -8,7 +8,7 @@ function Door:initialize(x, y, colors)
|
||||||
y = y,
|
y = y,
|
||||||
color = "white",
|
color = "white",
|
||||||
collision = "unmoveable",
|
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
|
self.locked = true
|
||||||
|
|
||||||
|
|
@ -24,17 +24,17 @@ function Door:draw()
|
||||||
if active then
|
if active then
|
||||||
love.graphics.setColor(gColor[color]:set())
|
love.graphics.setColor(gColor[color]:set())
|
||||||
local p = self:getDrawPos()
|
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
|
||||||
end
|
end
|
||||||
love.graphics.setColor(gColor.white:set())
|
love.graphics.setColor(gColor.white:set())
|
||||||
local p = self:getDrawPos()
|
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
|
else
|
||||||
for color, active in pairs(self.colors) do
|
for color, active in pairs(self.colors) do
|
||||||
love.graphics.setColor(gColor[color]:set())
|
love.graphics.setColor(gColor[color]:set())
|
||||||
local p = self:getDrawPos()
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ Entity = class("Entity")
|
||||||
|
|
||||||
function Entity:initialize(t)
|
function Entity:initialize(t)
|
||||||
self.x, self.y = t.x, t.y
|
self.x, self.y = t.x, t.y
|
||||||
|
self.name = t.name
|
||||||
self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()}
|
self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()}
|
||||||
self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16}
|
self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16}
|
||||||
self.cellShape = t.cellShape or self:cellShapeFromBox(self.size)
|
self.cellShape = t.cellShape or self:cellShapeFromBox(self.size)
|
||||||
|
|
@ -52,10 +53,8 @@ function Entity:cellShapeFromBox(box)
|
||||||
for i = 1, box.w do
|
for i = 1, box.w do
|
||||||
for j = 1, box.h do
|
for j = 1, box.h do
|
||||||
table.insert(cells, {x = i, y = j})
|
table.insert(cells, {x = i, y = j})
|
||||||
io.write(" boop: " .. i .. ", " .. j)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
io.write("\n")
|
|
||||||
return cells
|
return cells
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
58
main.lua
58
main.lua
|
|
@ -11,13 +11,14 @@ require "input"
|
||||||
require "color"
|
require "color"
|
||||||
require "room"
|
require "room"
|
||||||
require "shaders"
|
require "shaders"
|
||||||
|
require "sprite_manager"
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
_initDefaults()
|
_initDefaults()
|
||||||
_initGridVars()
|
_initGridVars()
|
||||||
_initSounds()
|
_initSounds()
|
||||||
_initGlobalColors()
|
_initGlobalColors()
|
||||||
loadSprites()
|
processSprites()
|
||||||
|
|
||||||
gameCanvas = love.graphics.newCanvas()
|
gameCanvas = love.graphics.newCanvas()
|
||||||
finalCanvas = love.graphics.newCanvas()
|
finalCanvas = love.graphics.newCanvas()
|
||||||
|
|
@ -130,59 +131,4 @@ function _initSounds()
|
||||||
static:setVolume(.15)
|
static:setVolume(.15)
|
||||||
static:play()
|
static:play()
|
||||||
end
|
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
|
|
||||||
2
npc.lua
2
npc.lua
|
|
@ -6,6 +6,6 @@ function npc:initialize(x, y, color, name)
|
||||||
y = y,
|
y = y,
|
||||||
color = color,
|
color = color,
|
||||||
collision = "none", --player can't push other player
|
collision = "none", --player can't push other player
|
||||||
sprite = npcSprites[name][color]
|
sprite = sprites.npc[name][color]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
@ -13,7 +13,7 @@ function Player:initialize(x, y, color)
|
||||||
y = y,
|
y = y,
|
||||||
color = color,
|
color = color,
|
||||||
collision = "none", --player can't push other player
|
collision = "none", --player can't push other player
|
||||||
sprite = playerSprite
|
sprite = sprites.player
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
19
room.lua
19
room.lua
|
|
@ -33,15 +33,15 @@ function Room:initialize(t)
|
||||||
-- self.activeColors[color] = true
|
-- self.activeColors[color] = true
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
-- for i=1, 30 do
|
for i=1, 1 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)
|
||||||
|
|
||||||
-- for color, active in pairs(self.activeColors) do
|
for color, active in pairs(self.activeColors) do
|
||||||
-- self.collideables[color]["w: " .. x .. ", " .. y] = door
|
self.collideables[color]["w: " .. x .. ", " .. y] = Wall:new(x, y, color)
|
||||||
-- end
|
end
|
||||||
-- end
|
end
|
||||||
|
|
||||||
for i=0, 5 do
|
for i=0, 5 do
|
||||||
local x, y = randomPosition()
|
local x, y = randomPosition()
|
||||||
|
|
@ -226,7 +226,7 @@ function Room:movePlayer(key)
|
||||||
|
|
||||||
local targetCells
|
local targetCells
|
||||||
|
|
||||||
local pull = {}
|
local pull
|
||||||
--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
|
||||||
|
|
@ -246,7 +246,7 @@ function Room:movePlayer(key)
|
||||||
table.insert(nextTargetCells, projectedCell)
|
table.insert(nextTargetCells, projectedCell)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
pull[color] = false
|
pull = false
|
||||||
doneSearching = true
|
doneSearching = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -262,6 +262,7 @@ 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 = true
|
||||||
doneSearching = true
|
doneSearching = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -272,9 +273,11 @@ function Room:movePlayer(key)
|
||||||
for _, entity in pairs(entitiesToPush) do
|
for _, entity in pairs(entitiesToPush) do
|
||||||
entity:move(axis, dir[axis])
|
entity:move(axis, dir[axis])
|
||||||
end
|
end
|
||||||
|
if pull == true then
|
||||||
for _, entity in pairs(entitiesToPull) do
|
for _, entity in pairs(entitiesToPull) do
|
||||||
entity:move(axis, dir[axis])
|
entity:move(axis, dir[axis])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
self.player[color]:move(axis, dir[axis])
|
self.player[color]:move(axis, dir[axis])
|
||||||
moved = true
|
moved = true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
112
sprite_manager.lua
Normal file
112
sprite_manager.lua
Normal 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
|
||||||
|
|
@ -15,7 +15,7 @@ function Switch:initialize(x, y, color)
|
||||||
y = y,
|
y = y,
|
||||||
color = color,
|
color = color,
|
||||||
collision = "none", --switches are floor elements that can't be pushed or bloc movement!!
|
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
|
self.activated = false
|
||||||
|
|
|
||||||
3
wall.lua
3
wall.lua
|
|
@ -9,8 +9,9 @@ function Wall:initialize(x, y, color)
|
||||||
sizeX = 1,
|
sizeX = 1,
|
||||||
sizeY = 1,
|
sizeY = 1,
|
||||||
color = color,
|
color = color,
|
||||||
|
cellShape = spriteCells.test_object,
|
||||||
collision = "unmoveable",
|
collision = "unmoveable",
|
||||||
sprite = wallSprite
|
sprite = sprites.test_object
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue