Compare commits
3 Commits
5a43a52884
...
342c8b245b
Author | SHA1 | Date |
---|---|---|
|
342c8b245b | |
|
6e5e200e84 | |
|
fe67abe75b |
|
@ -0,0 +1,9 @@
|
|||
love.conf = function(conf)
|
||||
conf.window.height = 480
|
||||
conf.window.width = 480
|
||||
conf.window.resizable = true
|
||||
conf.window.title = "poppy"
|
||||
|
||||
conf.modules.joystick = false
|
||||
conf.modules.physics = false
|
||||
end
|
|
@ -0,0 +1,200 @@
|
|||
local world = {}
|
||||
world.x = 304
|
||||
world.y = 304
|
||||
|
||||
buffer = {}
|
||||
buffer.pixel = {}
|
||||
buffer.pixel.fg = love.graphics.newCanvas(world.x, world.y)
|
||||
buffer.pixel.bg = love.graphics.newCanvas(world.x, world.y)
|
||||
buffer.physics = love.graphics.newCanvas(world.x, world.y)
|
||||
buffer.programming = love.graphics.newCanvas(world.x, world.y)
|
||||
|
||||
local layer = true
|
||||
|
||||
local grid = 8
|
||||
local color = {}
|
||||
local mouse = {}
|
||||
mouse.lastpos = {}
|
||||
mouse.lastpos.x = 0
|
||||
mouse.lastpos.y = 0
|
||||
local view = {}
|
||||
view.x = 0
|
||||
view.y = 0
|
||||
|
||||
local brick = love.graphics.newImage("textures/brick.png")
|
||||
local player = {}
|
||||
player.old = {}
|
||||
player.ava = love.graphics.newImage("textures/player.png")
|
||||
player.y = 20
|
||||
player.x = 20
|
||||
|
||||
function love.keyreleased(key, _)
|
||||
if key == "f" then layer = not layer end
|
||||
if key == "c" then
|
||||
love.graphics.setCanvas(buffer.physics)
|
||||
love.graphics.clear()
|
||||
love.graphics.setCanvas(buffer.pixel)
|
||||
love.graphics.clear()
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
end
|
||||
|
||||
function love.load()
|
||||
end
|
||||
function love.update(dt)
|
||||
--[[
|
||||
Keyboard input
|
||||
]]--
|
||||
-- direct view control
|
||||
if love.keyboard.isDown("left") then
|
||||
view.x = view.x + dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("right") then
|
||||
view.x = view.x - dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("up") then
|
||||
view.y = view.y + dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("down") then
|
||||
view.y = view.y - dt * 40
|
||||
end
|
||||
|
||||
--player control
|
||||
player.old.x = player.x
|
||||
player.old.y = player.y
|
||||
if love.keyboard.isDown("a") then
|
||||
player.x = player.x - dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("d") then
|
||||
player.x = player.x + dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("w") then
|
||||
player.y = player.y - dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("s") then
|
||||
player.y = player.y + dt * 40
|
||||
end
|
||||
|
||||
--[[
|
||||
Collision checking
|
||||
]]--
|
||||
|
||||
--world boundary
|
||||
--TODO replace 8 with avatar actuall values
|
||||
if player.x + 8 > world.x then player.x = world.x -8 end
|
||||
if player.x < 0 then player.x = 0 end
|
||||
if player.y + 8 > world.y then player.y = world.y -8 end
|
||||
if player.y < 0 then player.y = 0 end
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
Mouse input
|
||||
]]--
|
||||
color_lock()
|
||||
|
||||
if not love.mouse.isDown(2) and not love.mouse.isDown(1) then
|
||||
mouse.lastpos.x = nil
|
||||
mouse.lastpos.y = nil
|
||||
return
|
||||
end
|
||||
local mousex = love.mouse.getX()
|
||||
local mousey = love.mouse.getY()
|
||||
mousex = mousex - view.x
|
||||
mousey = mousey - view.y
|
||||
|
||||
if not mouse.lastpos.x or not mouse.lastpos.y then
|
||||
-- only draw one caret this time
|
||||
local thisx = round(mousex, grid)
|
||||
local thisy = round(mousey, grid)
|
||||
|
||||
if layer then
|
||||
love.graphics.setCanvas(buffer.pixel.fg)
|
||||
else
|
||||
love.graphics.setCanvas(buffer.pixel.bg)
|
||||
end
|
||||
delete_caret(thisx, thisy)
|
||||
if love.mouse.isDown(1) then
|
||||
if layer then
|
||||
love.graphics.setColor(1, 0.1, 1, 0.6)
|
||||
love.graphics.draw(brick, thisx, thisy)
|
||||
else
|
||||
love.graphics.setColor(0, 0, 1, 0.6)
|
||||
love.graphics.rectangle("fill", thisx, thisy, grid, grid)
|
||||
end
|
||||
end
|
||||
|
||||
mouse.lastpos.x = mousex
|
||||
mouse.lastpos.y = mousey
|
||||
color_unlock()
|
||||
love.graphics.setCanvas()
|
||||
return
|
||||
end
|
||||
|
||||
local granularity = 32
|
||||
for i=0,granularity,1 do
|
||||
local thisx = round((((mouse.lastpos.x - mousex) / granularity) * i + mousex),grid)
|
||||
local thisy = round((((mouse.lastpos.y - mousey) / granularity) * i + mousey),grid)
|
||||
|
||||
if layer then
|
||||
love.graphics.setCanvas(buffer.pixel.fg)
|
||||
else
|
||||
love.graphics.setCanvas(buffer.pixel.bg)
|
||||
end
|
||||
|
||||
delete_caret(thisx, thisy)
|
||||
if love.mouse.isDown(1) then -- only delete
|
||||
|
||||
if layer then
|
||||
love.graphics.setColor(1, 0.1, 1, 0.6)
|
||||
love.graphics.draw(brick, thisx, thisy)
|
||||
else
|
||||
love.graphics.setColor(0, 0, 1, 0.6)
|
||||
love.graphics.rectangle("fill", thisx, thisy, grid, grid)
|
||||
end
|
||||
end
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
-- this is supposed to delete the stuff... does not however do that :)
|
||||
--
|
||||
mouse.lastpos.x = mousex
|
||||
mouse.lastpos.y = mousey
|
||||
|
||||
love.graphics.setCanvas()
|
||||
color_unlock()
|
||||
|
||||
|
||||
--[[
|
||||
Update camera to track player
|
||||
]]--
|
||||
|
||||
end
|
||||
|
||||
function delete_caret(posx, posy)
|
||||
love.graphics.setBlendMode("replace")
|
||||
love.graphics.setColor(0,0,0,0)
|
||||
love.graphics.rectangle("fill", posx, posy, grid, grid)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
local transform = love.math.newTransform(math.floor(view.x), math.floor(view.y))
|
||||
love.graphics.draw(buffer.pixel.bg, transform)
|
||||
-- draw player
|
||||
love.graphics.draw(player.ava, math.floor(player.x) + math.floor(view.x), math.floor(player.y) + math.floor(view.y))
|
||||
love.graphics.draw(buffer.pixel.fg, transform)
|
||||
love.graphics.draw(buffer.UI)
|
||||
-- draw character at correct location here
|
||||
end
|
||||
|
||||
function round(num, thing)
|
||||
return math.floor(num / thing) * thing
|
||||
end
|
||||
|
||||
function color_lock()
|
||||
color.r, color.g, color.b, color.a = love.graphics.getColor()
|
||||
end
|
||||
|
||||
function color_unlock()
|
||||
love.graphics.setColor(color.r, color.g, color.b, color.a)
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
function draw_ui(w, h)
|
||||
buffer.UI = love.graphics.newCanvas(w, h)
|
||||
color_lock()
|
||||
love.graphics.setCanvas(buffer.UI)
|
||||
love.graphics.clear()
|
||||
love.graphics.setColor(.6, 0, .4)
|
||||
love.graphics.setLineWidth(16)
|
||||
love.graphics.line(0, 0, 0, h)
|
||||
love.graphics.line(0, 0, w, 0)
|
||||
love.graphics.line(w, 0, w, h)
|
||||
love.graphics.line(0, h, w, h)
|
||||
love.graphics.setCanvas()
|
||||
color_unlock()
|
||||
end
|
||||
love.resize = draw_ui
|
||||
|
||||
local w,h = love.window.getMode()
|
||||
draw_ui(w, h)
|
212
main.lua
212
main.lua
|
@ -1,210 +1,2 @@
|
|||
local world = {}
|
||||
world.x = 304
|
||||
world.y = 304
|
||||
|
||||
local buffer = {}
|
||||
buffer.UI = love.graphics.newCanvas(640, 480)
|
||||
buffer.pixel = {}
|
||||
buffer.pixel.fg = love.graphics.newCanvas(world.x, world.y)
|
||||
buffer.pixel.bg = love.graphics.newCanvas(world.x, world.y)
|
||||
buffer.physics = love.graphics.newCanvas(world.x, world.y)
|
||||
buffer.programming = love.graphics.newCanvas(world.x, world.y)
|
||||
|
||||
local layer = true
|
||||
|
||||
local grid = 8
|
||||
local color = {}
|
||||
local mouse = {}
|
||||
mouse.lastpos = {}
|
||||
mouse.lastpos.x = 0
|
||||
mouse.lastpos.y = 0
|
||||
local view = {}
|
||||
view.x = 0
|
||||
view.y = 0
|
||||
|
||||
local brick = love.graphics.newImage("brick.png")
|
||||
local player = {}
|
||||
player.old = {}
|
||||
player.ava = love.graphics.newImage("player.png")
|
||||
player.y = 20
|
||||
player.x = 20
|
||||
|
||||
function love.keyreleased(key, _)
|
||||
if key == "f" then layer = not layer end
|
||||
if key == "c" then
|
||||
love.graphics.setCanvas(buffer.physics)
|
||||
love.graphics.clear()
|
||||
love.graphics.setCanvas(buffer.pixel)
|
||||
love.graphics.clear()
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
end
|
||||
|
||||
function draw_ui(width, height)
|
||||
|
||||
end
|
||||
|
||||
function love.load()
|
||||
color_lock()
|
||||
love.window.setMode(480, 480)
|
||||
love.graphics.setCanvas(buffer.UI)
|
||||
love.graphics.setColor(.6, 0, .4)
|
||||
love.graphics.rectangle("fill", 0, 0, 9, 480)
|
||||
love.graphics.rectangle("fill", 0, 0, 480, 8)
|
||||
love.graphics.rectangle("fill", 472, 0, 8, 480)
|
||||
love.graphics.rectangle("fill", 0, 472, 480, 8)
|
||||
love.graphics.setCanvas()
|
||||
color_unlock()
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
--[[
|
||||
Keyboard input
|
||||
]]--
|
||||
-- direct view control
|
||||
if love.keyboard.isDown("left") then
|
||||
view.x = view.x + dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("right") then
|
||||
view.x = view.x - dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("up") then
|
||||
view.y = view.y + dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("down") then
|
||||
view.y = view.y - dt * 40
|
||||
end
|
||||
|
||||
--player control
|
||||
player.old.x = player.x
|
||||
player.old.y = player.y
|
||||
if love.keyboard.isDown("a") then
|
||||
player.x = player.x - dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("d") then
|
||||
player.x = player.x + dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("w") then
|
||||
player.y = player.y - dt * 40
|
||||
end
|
||||
if love.keyboard.isDown("s") then
|
||||
player.y = player.y + dt * 40
|
||||
end
|
||||
|
||||
--[[
|
||||
Collision checking
|
||||
]]--
|
||||
|
||||
--world boundary
|
||||
--TODO replace 8 with avatar actuall values
|
||||
if player.x + 8 > world.x then player.x = world.x -8 end
|
||||
if player.x < 0 then player.x = 0 end
|
||||
if player.y + 8 > world.y then player.y = world.y -8 end
|
||||
if player.y < 0 then player.y = 0 end
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
Mouse input
|
||||
]]--
|
||||
color_lock()
|
||||
|
||||
if not love.mouse.isDown(2) and not love.mouse.isDown(1) then
|
||||
mouse.lastpos.x = nil
|
||||
mouse.lastpos.y = nil
|
||||
return
|
||||
end
|
||||
local mousex = love.mouse.getX()
|
||||
local mousey = love.mouse.getY()
|
||||
mousex = mousex - view.x
|
||||
mousey = mousey - view.y
|
||||
|
||||
if not mouse.lastpos.x or not mouse.lastpos.y then
|
||||
-- only draw one caret this time
|
||||
local thisx = round(mousex, grid)
|
||||
local thisy = round(mousey, grid)
|
||||
|
||||
if layer then
|
||||
love.graphics.setCanvas(buffer.pixel.fg)
|
||||
else
|
||||
love.graphics.setCanvas(buffer.pixel.bg)
|
||||
end
|
||||
delete_caret(thisx, thisy)
|
||||
if love.mouse.isDown(1) then
|
||||
if layer then
|
||||
love.graphics.setColor(1, 0.1, 1, 0.6)
|
||||
love.graphics.draw(brick, thisx, thisy)
|
||||
else
|
||||
love.graphics.setColor(0, 0, 1, 0.6)
|
||||
love.graphics.rectangle("fill", thisx, thisy, grid, grid)
|
||||
end
|
||||
end
|
||||
|
||||
mouse.lastpos.x = mousex
|
||||
mouse.lastpos.y = mousey
|
||||
color_unlock()
|
||||
love.graphics.setCanvas()
|
||||
return
|
||||
end
|
||||
|
||||
local granularity = 32
|
||||
for i=0,granularity,1 do
|
||||
local thisx = round((((mouse.lastpos.x - mousex) / granularity) * i + mousex),grid)
|
||||
local thisy = round((((mouse.lastpos.y - mousey) / granularity) * i + mousey),grid)
|
||||
|
||||
if layer then
|
||||
love.graphics.setCanvas(buffer.pixel.fg)
|
||||
else
|
||||
love.graphics.setCanvas(buffer.pixel.bg)
|
||||
end
|
||||
|
||||
delete_caret(thisx, thisy)
|
||||
if love.mouse.isDown(1) then -- only delete
|
||||
|
||||
if layer then
|
||||
love.graphics.setColor(1, 0.1, 1, 0.6)
|
||||
love.graphics.draw(brick, thisx, thisy)
|
||||
else
|
||||
love.graphics.setColor(0, 0, 1, 0.6)
|
||||
love.graphics.rectangle("fill", thisx, thisy, grid, grid)
|
||||
end
|
||||
end
|
||||
love.graphics.setCanvas()
|
||||
end
|
||||
-- this is supposed to delete the stuff... does not however do that :)
|
||||
--
|
||||
mouse.lastpos.x = mousex
|
||||
mouse.lastpos.y = mousey
|
||||
|
||||
love.graphics.setCanvas()
|
||||
color_unlock()
|
||||
end
|
||||
|
||||
function delete_caret(posx, posy)
|
||||
love.graphics.setBlendMode("replace")
|
||||
love.graphics.setColor(0,0,0,0)
|
||||
love.graphics.rectangle("fill", posx, posy, grid, grid)
|
||||
love.graphics.setBlendMode("alpha")
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
local transform = love.math.newTransform(math.floor(view.x), math.floor(view.y))
|
||||
love.graphics.draw(buffer.pixel.bg, transform)
|
||||
-- draw player
|
||||
love.graphics.draw(player.ava, math.floor(player.x) + math.floor(view.x), math.floor(player.y) + math.floor(view.y))
|
||||
love.graphics.draw(buffer.pixel.fg, transform)
|
||||
love.graphics.draw(buffer.UI)
|
||||
-- draw character at correct location here
|
||||
end
|
||||
|
||||
function round(num, thing)
|
||||
return math.floor(num / thing) * thing
|
||||
end
|
||||
|
||||
function color_lock()
|
||||
color.r, color.g, color.b, color.a = love.graphics.getColor()
|
||||
end
|
||||
|
||||
function color_unlock()
|
||||
love.graphics.setColor(color.r, color.g, color.b, color.a)
|
||||
end
|
||||
dofile "lua/init.lua"
|
||||
dofile "lua/ui.lua"
|
||||
|
|
Before Width: | Height: | Size: 602 B After Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 688 B After Width: | Height: | Size: 688 B |
Loading…
Reference in New Issue