basic stuff w movemet n collision done

This commit is contained in:
0x81c 2015-03-12 04:05:39 -04:00
parent 03112bb0fb
commit bffa27ec01
4 changed files with 25 additions and 15 deletions

View file

@ -6,6 +6,7 @@ function Entity:initialize(t)
self.color = Color:new(t.color) self.color = Color:new(t.color)
self.collision = t.collision --either "none", "moveable", "unmoveable" self.collision = t.collision --either "none", "moveable", "unmoveable"
self.sprite = t.sprite self.sprite = t.sprite
self.shaAmount = t.sha or 1
end end
function Entity:atGridPos(x, y) function Entity:atGridPos(x, y)
@ -31,7 +32,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:sha(), p.y + self:sha(), 0, drawScale, drawScale)
end end
function Entity:isAlignedWithPlayerMovement(axis, pos) function Entity:isAlignedWithPlayerMovement(axis, pos)
@ -53,6 +54,7 @@ function Entity:move(axis, direction)
self[axis] = self[axis] + direction self[axis] = self[axis] + direction
end end
function Entity:push(direction)
function Entity:sha()
return math.random(-self.shaAmount, self.shaAmount) * .5
end end

View file

@ -1,5 +1,6 @@
class = require "libs/middleclass" class = require "libs/middleclass"
Timer = require "libs/hump/timer" Timer = require "libs/hump/timer"
sfxr = require "libs/sfxrlua/sfxr"
require "input" require "input"
require "color" require "color"
require "room" require "room"
@ -9,6 +10,7 @@ require "debug_helpers"
function love.load() function love.load()
_initDefaults() _initDefaults()
_initGridVars() _initGridVars()
_initSounds()
loadSprites() loadSprites()
gameCanvas = love.graphics.newCanvas() gameCanvas = love.graphics.newCanvas()
@ -59,10 +61,11 @@ function love.draw()
love.graphics.draw(gameCanvas, 0, 0) love.graphics.draw(gameCanvas, 0, 0)
love.graphics.setCanvas() love.graphics.setCanvas()
pixelate:send("seed", math.random()) love.graphics.setBlendMode("alpha")
pixelate:send("zoom", .2) love.graphics.setColor(255, 255, 255, 255)
love.graphics.setShader(pixelate)
love.graphics.draw(finalCanvas, 0, 0) love.graphics.draw(finalCanvas, 0, 0)
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
end end
function love.keypressed(key) function love.keypressed(key)
@ -96,6 +99,18 @@ function _initGridVars()
drawScale = width / gridWidth / 16 drawScale = width / gridWidth / 16
end end
function _initSounds()
staticWave = sfxr.newSound()
staticWave.wavetype = 3
staticWave.frequency.start = .1
staticWave.envelope.release = 0
staticWave.envelope.sustain = 1
staticWave.envelope.decay = 0
static = love.audio.newSource(staticWave:generateSoundData())
static:setLooping(true)
static:setVolume(.15)
static:play()
end
function createCanvases() function createCanvases()
end end

View file

@ -19,10 +19,3 @@ end
function Player:update() function Player:update()
end end
function Player:draw()
love.graphics.setColor(self.color:set())
local p = self:getDrawPos()
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
end

View file

@ -23,14 +23,14 @@ function Room:initialize(t)
self.activeColors[color] = true self.activeColors[color] = true
end end
for i=0, 20 do for i=0, 50 do
local c = randomColor() local c = randomColor()
local x, y = math.random(1, gridWidth), math.random(1, gridHeight) local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
self.collideables[c]["b: " .. x .. ", " .. y] = Box:new(x, y, c) self.collideables[c]["b: " .. x .. ", " .. y] = Box:new(x, y, c)
end end
for i=0, 20 do for i=0, 50 do
local c = randomColor() local c = randomColor()
local x, y = math.random(1, gridWidth), math.random(1, gridHeight) local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
self.collideables[c]["w: " .. x .. ", " .. y] = Wall:new(x, y, c) self.collideables[c]["w: " .. x .. ", " .. y] = Wall:new(x, y, c)