some changes, idr, hehe sorry
This commit is contained in:
parent
c668dc513b
commit
b553d3f664
5 changed files with 116 additions and 48 deletions
|
|
@ -12,3 +12,8 @@ function printMatrix(matrix)
|
||||||
io.write("\n")
|
io.write("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function randomPosition()
|
||||||
|
print("hfhfhhdh")
|
||||||
|
return math.random(1, gridWidth), math.random(1, gridHeight)
|
||||||
|
end
|
||||||
|
|
@ -8,6 +8,12 @@ function Entity:initialize(t)
|
||||||
self.collision = t.collision --"none", "moveable", "unmoveable"
|
self.collision = t.collision --"none", "moveable", "unmoveable"
|
||||||
self.sprite = t.sprite
|
self.sprite = t.sprite
|
||||||
self.shaAmount = t.sha or 1
|
self.shaAmount = t.sha or 1
|
||||||
|
|
||||||
|
self.drawOffset = {x = 0, y = 0}
|
||||||
|
if self.size.w < 1 or self.size.h < 1 then
|
||||||
|
self.drawOffset.x = (drawScale * 16 * self.size.w) / 2
|
||||||
|
self.drawOffset.y = (drawScale * 16 * self.size.h) / 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:getCollision()
|
function Entity:getCollision()
|
||||||
|
|
@ -70,7 +76,7 @@ end
|
||||||
function Entity:draw()
|
function Entity:draw()
|
||||||
love.graphics.setColor(self.color:set())
|
love.graphics.setColor(self.color:set())
|
||||||
local p = self:getDrawPos()
|
local p = self:getDrawPos()
|
||||||
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
|
love.graphics.draw(self.sprite, p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:canMove()
|
function Entity:canMove()
|
||||||
|
|
|
||||||
5
main.lua
5
main.lua
|
|
@ -133,6 +133,11 @@ function loadSprites()
|
||||||
green = love.graphics.newImage("art/wall_g.png"),
|
green = love.graphics.newImage("art/wall_g.png"),
|
||||||
blue = love.graphics.newImage("art/wall_b.png")
|
blue = love.graphics.newImage("art/wall_b.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 = {
|
waterSprite = {
|
||||||
red = love.graphics.newImage("art/nature/processed/water_r.png"),
|
red = love.graphics.newImage("art/nature/processed/water_r.png"),
|
||||||
green = love.graphics.newImage("art/nature/processed/water_g.png"),
|
green = love.graphics.newImage("art/nature/processed/water_g.png"),
|
||||||
|
|
|
||||||
53
room.lua
53
room.lua
|
|
@ -7,16 +7,14 @@ require "artifact"
|
||||||
require "npc"
|
require "npc"
|
||||||
require "art"
|
require "art"
|
||||||
require "assorted"
|
require "assorted"
|
||||||
|
require "switch"
|
||||||
|
|
||||||
function Room:initialize(t)
|
function Room:initialize(t)
|
||||||
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 = Player:new(t.player.x, t.player.y, t.player.activeColors)
|
||||||
self.collideables = {
|
self.switches = { red = {}, green = {}, blue = {} }
|
||||||
red = {},
|
self.collideables = { red = {}, green = {}, blue = {} }
|
||||||
green = {},
|
|
||||||
blue = {}
|
|
||||||
}
|
|
||||||
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...}
|
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...}
|
||||||
|
|
||||||
self.activeColors = {
|
self.activeColors = {
|
||||||
|
|
@ -44,6 +42,13 @@ function Room:initialize(t)
|
||||||
end
|
end
|
||||||
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
|
for color, active in pairs(self.activeColors) do
|
||||||
local x, y = 6, 3
|
local x, y = 6, 3
|
||||||
-- if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "animals/processed/", "me_rach") end
|
-- if active then self.collideables[color]["n: " .. x .. ", " .. y] = Ass:new(x, y, color, "animals/processed/", "me_rach") end
|
||||||
|
|
@ -77,6 +82,11 @@ function Room:draw()
|
||||||
entity:draw()
|
entity:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for color, switchArray in pairs(self.switches) do
|
||||||
|
for _, switch in pairs(switchArray) do
|
||||||
|
switch:draw()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:createCollideablesMatrix(collideables)
|
function Room:createCollideablesMatrix(collideables)
|
||||||
|
|
@ -128,7 +138,7 @@ function Room:movePlayer(key)
|
||||||
dir.x, axis = 1, "x"
|
dir.x, axis = 1, "x"
|
||||||
end
|
end
|
||||||
|
|
||||||
local move
|
local move = true
|
||||||
local entitiesToPush = {
|
local entitiesToPush = {
|
||||||
red = {},
|
red = {},
|
||||||
green = {},
|
green = {},
|
||||||
|
|
@ -146,7 +156,9 @@ function Room:movePlayer(key)
|
||||||
x = pos.x + dir.x, y = pos.y + dir.y
|
x = pos.x + dir.x, y = pos.y + dir.y
|
||||||
} -- this is for reference for each color as we change the targetCells table
|
} -- this is for reference for each color as we change the targetCells table
|
||||||
|
|
||||||
local move = true
|
if not self:isInBounds(initialTargetCell) then
|
||||||
|
move = true
|
||||||
|
else
|
||||||
local targetCells
|
local targetCells
|
||||||
|
|
||||||
--so the way this worx is....
|
--so the way this worx is....
|
||||||
|
|
@ -196,6 +208,7 @@ function Room:movePlayer(key)
|
||||||
--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
|
if move == false then break end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
---PULL CHEC
|
---PULL CHEC
|
||||||
|
|
@ -309,9 +322,31 @@ function Room:isInBounds(cell)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:nextRoomCheck()
|
function Room:nextRoomCheck()
|
||||||
|
if not self:isInBounds(self.player:getGridPos()) then
|
||||||
|
nextRoom(self.player:getGridPos())
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function nextRoom()
|
function nextRoom(pos)
|
||||||
|
local exit
|
||||||
|
local newPos = {x = pos.x, y = pos.y}
|
||||||
|
if pos.x > gridWidth then
|
||||||
|
exit = "right"
|
||||||
|
newPos.x = 1
|
||||||
|
elseif pos.x < 1 then
|
||||||
|
exit = "left"
|
||||||
|
newPos.x = gridWidth
|
||||||
|
elseif pos.y > gridHeight then
|
||||||
|
exit = "bottom"
|
||||||
|
newPos.y = 1
|
||||||
|
elseif pos.y < 1 then
|
||||||
|
exit = "top"
|
||||||
|
newPos.y = gridHeight
|
||||||
|
end
|
||||||
|
|
||||||
|
currentRoom = Room:new{
|
||||||
|
player = {
|
||||||
|
x = newPos.x, y = newPos.y, activeColors = currentRoom.player:getActiveColors()
|
||||||
|
}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
17
switch.lua
Normal file
17
switch.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
require "entity"
|
||||||
|
|
||||||
|
Switch = class("Switch", Entity)
|
||||||
|
|
||||||
|
function Switch:initialize(x, y, color)
|
||||||
|
print("hey!!", x, y, color)
|
||||||
|
print(color)
|
||||||
|
Entity.initialize(self, {
|
||||||
|
x = x,
|
||||||
|
y = y,
|
||||||
|
sizeX = 1,
|
||||||
|
sizeY = 1,
|
||||||
|
color = color,
|
||||||
|
collision = "none", --switches are floor elements that can't be pushed or bloc movement!!
|
||||||
|
sprite = switchSprite[color]
|
||||||
|
})
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue