chroma_solstice/main.lua

185 lines
4.6 KiB
Lua
Raw Normal View History

2015-03-11 20:11:29 -04:00
class = require "libs/middleclass"
Timer = require "libs/hump/timer"
2015-03-12 04:05:39 -04:00
sfxr = require "libs/sfxrlua/sfxr"
2015-03-14 05:36:02 -04:00
json = require "libs/json4lua/json/json"
require "_helpers"
2015-03-12 03:04:09 -04:00
require "input"
2015-03-11 20:11:29 -04:00
require "color"
require "room"
2015-03-12 03:27:27 -04:00
require "shaders"
require "_debug_helpers"
2015-03-11 20:11:29 -04:00
function love.load()
2015-03-11 21:41:02 -04:00
_initDefaults()
2015-03-11 20:11:29 -04:00
_initGridVars()
2015-03-12 04:05:39 -04:00
_initSounds()
2015-03-15 07:08:35 -04:00
_initGlobalColors()
2015-03-11 20:11:29 -04:00
loadSprites()
2015-03-12 03:27:27 -04:00
gameCanvas = love.graphics.newCanvas()
finalCanvas = love.graphics.newCanvas()
2015-03-11 20:11:29 -04:00
inputTimer = Timer.new()
2015-03-11 21:41:02 -04:00
currentRoom = Room:new{
player = {
x = 5, y = 5, activeColors = {"red", "green", "blue"}
2015-03-11 21:41:02 -04:00
}
}
2015-03-11 20:11:29 -04:00
end
function love.update(dt)
Input:handler()
2015-03-11 21:41:02 -04:00
currentRoom:update()
2015-03-14 05:36:02 -04:00
if love.keyboard.isDown("w") then worldSha = worldSha + 1 end
if love.keyboard.isDown("s") then worldSha = worldSha - 1 end
2015-03-11 20:11:29 -04:00
end
function love.draw()
2015-03-12 03:27:27 -04:00
gameCanvas:clear()
finalCanvas:clear()
love.graphics.setCanvas(gameCanvas)
2015-03-11 21:41:02 -04:00
love.graphics.setBlendMode("screen")
currentRoom:draw()
2015-03-12 03:27:27 -04:00
love.graphics.setCanvas(finalCanvas)
local scaleCoefficient = .93
local samples = 7
love.graphics.push()
for i = 1, samples do
local c = 65 / (i * 1.75)
love.graphics.setColor(c, c, c)
love.graphics.scale(scaleCoefficient, scaleCoefficient)
love.graphics.translate((width / 2 - (width * scaleCoefficient) / 2) + 2, (width / 2 - (height * scaleCoefficient) / 2) + 2)
love.graphics.draw(gameCanvas, 0, 0)
end
love.graphics.pop()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(gameCanvas, 0, 0)
love.graphics.setCanvas()
2015-03-12 04:05:39 -04:00
love.graphics.setBlendMode("alpha")
love.graphics.setColor(255, 255, 255, 255)
2015-03-12 03:27:27 -04:00
love.graphics.draw(finalCanvas, 0, 0)
2015-03-12 04:05:39 -04:00
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
2015-03-11 20:11:29 -04:00
end
2015-03-12 03:04:09 -04:00
function love.keypressed(key)
if Input.isPlayerMove(key) then
currentRoom:movePlayer(key)
elseif Input.isPlayerSwitch(key) then
local c = Input.playerColor(key)
2015-03-14 06:18:04 -04:00
currentRoom:switchPlayerColor(c)
2015-03-12 03:04:09 -04:00
end
2015-03-14 05:36:02 -04:00
if key == "w" then
worldSha = worldSha + 1
end
if key == "s" then
worldSha = worldSha - 1
end
2015-03-12 03:04:09 -04:00
end
2015-03-11 21:41:02 -04:00
function _initDefaults()
2015-03-12 03:04:09 -04:00
--set filter
2015-03-11 20:11:29 -04:00
love.graphics.setDefaultFilter("linear", "nearest")
2015-03-12 03:04:09 -04:00
--set global width / height variables
2015-03-11 20:11:29 -04:00
width = love.graphics.getWidth()
height = love.graphics.getHeight()
if width > height then
width = height
else
height = width
end
2015-03-12 03:04:09 -04:00
--set randomseed
math.randomseed(os.time())
2015-03-11 20:11:29 -04:00
end
function _initGridVars()
gridWidth, gridHeight = 11, 11
drawScale = width / gridWidth / 16
2015-03-14 05:36:02 -04:00
worldSha = 1
2015-03-11 20:11:29 -04:00
end
2015-03-15 07:08:35 -04:00
function _initGlobalColors()
gColor = {}
gColor.red, gColor.green, gColor.blue, gColor.white = Color:new("red"), Color:new("green"), Color:new("blue"), Color:new("white")
end
2015-03-12 04:05:39 -04:00
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
2015-03-11 20:11:29 -04:00
function createCanvases()
end
function loadSprites()
playerSprite = love.graphics.newImage("art/player.png")
2015-03-12 03:04:09 -04:00
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")
}
2015-03-15 07:08:35 -04:00
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")
}
2015-03-15 05:26:47 -04:00
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")
}
2015-03-14 05:36:02 -04:00
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)
2015-03-12 05:13:04 -04:00
artifactSprite = love.graphics.newImage("art/process/cone.png")
2015-03-11 20:11:29 -04:00
end