function love.handlers.collision(focus, pos)
end
-
-function love.handlers.collision(collider, tile)
-end
local handlers = require('handlers')
local conf = require('conf')
local assets = require('assets')
+local message = require('message')
local player_module = require('player')
local control = require('control')
local render = require('render')
player = player_module.player
+local test_text = nil
+
function love.load()
love.setDeprecationOutput(false)
- love.graphics.setFont(assets.get_font('Cuneiform36'))
love.audio.play(assets.get_source('intro'))
render.activate_map('side_scroll')
player = assets.get_object('Player')
player_module.init_controls(player, render.map.active_map)
+
+ test_text = love.graphics.newText(assets.get_font('Cuneiform36'), IntroMessage)
+ message.send(test_text, { frame = false })
end
function love.update(dt)
w = render.map.active_map.tilewidth * render.map.scale,
h = render.map.active_map.tileheight * render.map.scale,
}
+ local last_color = { love.graphics.getColor() }
love.graphics.stencil(
function()
render.map.active_map:draw(render.map.active_map.topleft.x, render.map.active_map.topleft.y, render.map.scale)
- last_color = { love.graphics.getColor() }
- love.graphics.setColor(render.color.dark)
- love.graphics.print(IntroMessage, math.floor((conf.window.width/16) * 1), math.floor((conf.window.height/16) * 1))
love.graphics.setColor(last_color)
+ message.draw()
end
--- /dev/null
+-- message.lua
+
+local message = {}
+
+-- Try to queue a message for display.
+-- For now, only allow showing one message at a time.
+function message.send(textItem, opts)
+ if message.active_message then
+ else
+ message.active_message = { item = textItem, opts = opts }
+ end
+end
+
+function message.draw()
+ if not message.active_message then
+ return
+ end
+
+ local textItem, opts = message.active_message.item, message.active_message.opts
+ local x, y = opts.x, opts.y
+ local width, height = textItem:getDimensions()
+ local last_color = { love.graphics.getColor() }
+ local tile = render.viewport.tile
+ local halftile = utils.shallow_copy(tile)
+
+ halftile.w = halftile.w / 2
+ halftile.h = halftile.h / 2
+
+ -- If a position is not provided,
+ -- find a nice position for it
+ if (not x) or (not y) then
+ x = render.viewport.ox + halftile.w
+ y = render.viewport.oy + halftile.h
+ width = render.viewport.ex - render.viewport.ox - (2 * tile.w) - halftile.w
+ end
+
+ if opts.frame then
+ love.graphics.setColor(render.color.dark_trans60)
+ love.graphics.rectangle('fill',
+ x, y,
+ x + width + tile.w,
+ y + height + tile.h)
+ love.graphics.setColor(render.color.really_dark)
+ love.graphics.rectangle('line',
+ x, y,
+ x + width + tile.w,
+ y + height + tile.h)
+ else
+ -- No more tasteful framing offsets
+ halftile.w = 0
+ halftile.h = 0
+ end
+
+ -- A tasteful offset
+ love.graphics.setColor(render.color.really_dark)
+ love.graphics.draw(textItem, x + halftile.w, y + halftile.h)
+ love.graphics.setColor(last_color)
+end
+
+
+return message
-- Map is translated to correct position so the right section is drawn
lg.push()
lg.origin()
-
+
--[[
This snippet comes from 'monolifed' on the Love2D forums,
- however it was more or less exactly the same code I was already writing
- to implement the same parallax scrolling. I found his before
+ however it was more or less exactly the same code I was already writing
+ to implement the same parallax scrolling. I found his before
testing and polishing mine
https://love2d.org/forums/viewtopic.php?p=238378#p238378
- previous code commented below the new.
+ previous code commented below the new.
]]
tx, ty = tx or 0, ty or 0
- for _, layer in ipairs(self.layers) do
+ for k, layer in ipairs(self.layers) do
if layer.visible and layer.opacity > 0 then
local px, py = layer.parallaxx or 1, layer.parallaxy or 1
px, py = math.floor(tx * px), math.floor(ty * py)
function Map.drawLayer(_, layer)
local r,g,b,a = lg.getColor()
-- if the layer has a tintcolor set
- if layer.tintcolor then
+ if layer.tintcolor then
r, g, b, a = unpack(layer.tintcolor)
a = a or 255 -- alpha may not be specified
lg.setColor(r/255, g/255, b/255, a/255) -- Tiled uses 0-255
if layer.repeaty then
local x = imagewidth
local y = imageheight
- while y < self.height * self.tileheight do
+ while y < self.height * self.tileheight do
lg.draw(layer.image, x, y)
-- if we are *also* repeating on X
- if layer.repeatx then
+ if layer.repeatx then
x = x + imagewidth
- while x < self.width * self.tilewidth do
+ while x < self.width * self.tilewidth do
lg.draw(layer.image, x, y)
x = x + imagewidth
end
-- if we're repeating on X alone...
elseif layer.repeatx then
local x = imagewidth
- while x < self.width * self.tilewidth do
+ while x < self.width * self.tilewidth do
lg.draw(layer.image, x, layer.y)
x = x + imagewidth
end
render.color = {}
-- wrapping a function that returns multiple values in {} packs
-- them into a single struct
-render.color.dark = { love.math.colorFromBytes(54, 54, 54) }
-render.color.light = { love.math.colorFromBytes(229, 229, 229) }
+render.color.really_dark = { love.math.colorFromBytes(2, 2, 2, 255) }
+render.color.dark = { love.math.colorFromBytes(54, 54, 54, 255) }
+render.color.light = { love.math.colorFromBytes(229, 229, 229, 255) }
+
+render.color.dark_trans60 = utils.shallow_copy(render.color.dark)
+render.color.dark_trans60[4] = 0.6
-- Map rendering info
render.map = {}
oy = 0,
ex = conf.window.width,
ey = conf.window.height,
+ tile = {},
}
function render.activate_map(new_map_name)
new_viewport.ex = (conf.window.width) - (tile.w) - (backwidth)
new_viewport.ey = (conf.window.height) - (tile.h) - (backheight)
+ new_viewport.tile = utils.shallow_copy(tile)
+
return new_viewport
end
function utils.shallow_dump(delim, ...)
for vark,varv in pairs({...}) do
print(delim..vark..':')
- for k,v in pairs(varv) do
+ if type(varv) == 'table' then
+ for k,v in pairs(varv) do
+ print('\t'..k..':', v)
+ end
+ elseif type(varv) ~= 'userdata' then
print('\t'..k..':', v)
end
end