chroma_solstice/main.lua

183 lines
4.3 KiB
Lua
Raw Normal View History

2015-03-15 13:54:47 -04:00
love.graphics.setDefaultFilter("linear", "nearest")
2015-03-25 01:38:53 -04:00
local utf8 = require("utf8")
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"
require "libs/TSerial"
2015-03-15 16:25:00 -04:00
require "_debug_helpers"
2015-03-14 05:36:02 -04:00
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 "sprite_manager"
2015-03-25 01:38:53 -04:00
require "level_editor/editor"
2015-03-11 20:11:29 -04:00
function love.load()
globalAssetProperties = TSerial.unpack(love.filesystem.read("assets.prop") or "{}")
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-25 01:38:53 -04:00
_initLevelEditor()
processSprites()
2015-03-11 20:11:29 -04:00
2015-03-12 03:27:27 -04:00
gameCanvas = love.graphics.newCanvas()
2015-03-25 01:38:53 -04:00
sideBarCanvas = love.graphics.newCanvas(sideBarBox.w, sideBarBox.h)
2015-03-12 03:27:27 -04:00
finalCanvas = love.graphics.newCanvas()
2015-03-25 01:38:53 -04:00
2015-03-11 20:11:29 -04:00
inputTimer = Timer.new()
2015-03-11 21:41:02 -04:00
currentRoom = Room:new{
2015-03-25 01:38:53 -04:00
name = "test"
2015-03-11 21:41:02 -04:00
}
2015-03-25 01:38:53 -04:00
response = ""
2015-03-11 20:11:29 -04:00
end
function love.update(dt)
Input:handler(dt)
currentRoom:update(dt)
2015-03-14 05:36:02 -04:00
2015-03-25 01:38:53 -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
love.graphics.setCanvas(gameCanvas)
2026-08-06 23:54:49 -04:00
love.graphics.clear()
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)
2026-08-06 23:54:49 -04:00
love.graphics.clear()
2015-03-12 03:27:27 -04:00
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-25 01:38:53 -04:00
love.graphics.setCanvas(sideBarCanvas)
2026-08-06 23:54:49 -04:00
love.graphics.clear()
2015-03-25 01:38:53 -04:00
editorDraw()
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-25 01:38:53 -04:00
love.graphics.draw(sideBarCanvas, sideBarBox.x, sideBarBox.y)
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-25 01:38:53 -04:00
-- if key == "w" then
-- worldSha = worldSha + 1
-- end
-- if key == "s" then
-- worldSha = worldSha - 1
-- end
if key == "return" then
response = ""
editorCompleteResponse()
elseif key == "backspace" then
local byteoffset = utf8.offset(response, -1)
if byteoffset then
-- remove the last UTF-8 character.
-- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(response, 1, -2).
response = string.sub(response, 1, byteoffset - 1)
editorTextHandler(response)
end
2015-03-14 05:36:02 -04:00
end
2015-03-25 01:38:53 -04:00
end
function love.mousepressed(x, y, button)
2026-08-06 23:54:49 -04:00
if button == 2 then
currentRoom:attemptDelete(x, y, selectedColor)
2015-03-14 05:36:02 -04:00
end
2015-03-25 01:38:53 -04:00
editorMouseHandler(x, y, button)
end
function love.textinput(t)
response = response .. t
editorTextHandler(response)
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-17 01:59:14 -04:00
love.filesystem.createDirectory("rooms")
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-25 01:38:53 -04:00
--font
font = love.graphics.newFont("font/LCD_Solid.ttf", 16)
love.graphics.setFont(font)
--sidebar
sideBarBox = {x = width, y = 0, w = love.graphics.getWidth() - width, h = height}
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
2026-08-06 23:54:49 -04:00
static = love.audio.newSource((staticWave:generateSoundData()))
2015-03-12 04:05:39 -04:00
static:setLooping(true)
static:setVolume(.15)
static:play()
end
2015-03-11 20:11:29 -04:00