some changes, idr, hehe sorry

This commit is contained in:
0x81c 2015-03-15 05:26:47 -04:00
parent c668dc513b
commit b553d3f664
5 changed files with 116 additions and 48 deletions

View file

@ -12,3 +12,8 @@ function printMatrix(matrix)
io.write("\n")
end
end
function randomPosition()
print("hfhfhhdh")
return math.random(1, gridWidth), math.random(1, gridHeight)
end

View file

@ -8,6 +8,12 @@ function Entity:initialize(t)
self.collision = t.collision --"none", "moveable", "unmoveable"
self.sprite = t.sprite
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
function Entity:getCollision()
@ -70,7 +76,7 @@ end
function Entity:draw()
love.graphics.setColor(self.color:set())
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
function Entity:canMove()

View file

@ -133,6 +133,11 @@ function loadSprites()
green = love.graphics.newImage("art/wall_g.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 = {
red = love.graphics.newImage("art/nature/processed/water_r.png"),
green = love.graphics.newImage("art/nature/processed/water_g.png"),

View file

@ -7,16 +7,14 @@ require "artifact"
require "npc"
require "art"
require "assorted"
require "switch"
function Room:initialize(t)
self.exits = t.exits
self.name = t.name
self.player = Player:new(t.player.x, t.player.y, t.player.activeColors)
self.collideables = {
red = {},
green = {},
blue = {}
}
self.switches = { red = {}, green = {}, blue = {} }
self.collideables = { red = {}, green = {}, blue = {} }
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...}
self.activeColors = {
@ -44,6 +42,13 @@ function Room:initialize(t)
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
local x, y = 6, 3
-- 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()
end
end
for color, switchArray in pairs(self.switches) do
for _, switch in pairs(switchArray) do
switch:draw()
end
end
end
function Room:createCollideablesMatrix(collideables)
@ -128,7 +138,7 @@ function Room:movePlayer(key)
dir.x, axis = 1, "x"
end
local move
local move = true
local entitiesToPush = {
red = {},
green = {},
@ -146,7 +156,9 @@ function Room:movePlayer(key)
x = pos.x + dir.x, y = pos.y + dir.y
} -- 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
--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
if move == false then break end
end
end
---PULL CHEC
@ -309,9 +322,31 @@ function Room:isInBounds(cell)
end
function Room:nextRoomCheck()
if not self:isInBounds(self.player:getGridPos()) then
nextRoom(self.player:getGridPos())
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

17
switch.lua Normal file
View 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