Rocket-Bytes/Source/Editor.lua

102 lines
2.3 KiB
Lua
Raw Normal View History

2022-04-27 02:40:39 +00:00
import "CoreLibs/keyboard"
2022-05-20 17:01:59 +00:00
import "CoreLibs/math"
2022-04-27 02:40:39 +00:00
local gfx <const> = playdate.graphics
2022-05-08 05:40:21 +00:00
local prevtext = ""
2022-05-20 17:01:59 +00:00
gfx.setLineWidth(5)
local position = {x=0,y=0}
local bool2int = {[true]=1,[false]=0}
local imgSwitch = gfx.imagetable.new("gfx/switch")
local imgFloppy = gfx.image.new("gfx/floppy")
assert(imgSwitch)
assert(imgFloppy)
local sprSwitch = gfx.sprite.new(imgSwitch:getImage(1))
local sprFloppy = gfx.sprite.new(imgFloppy)
sprSwitch:moveTo(381,47)
sprFloppy:moveTo(381,17)
2022-04-27 02:40:39 +00:00
function newProject()
mode = "newproj"
2022-05-08 05:40:21 +00:00
playdate.keyboard.show("NEW LEVEL")
2022-04-27 02:40:39 +00:00
end
function updateNewproj()
gfx.clear()
gfx.drawText("LEVEL NAME:", 0, 105)
2022-05-08 05:40:21 +00:00
gfx.drawTextInRect(playdate.keyboard.text:upper(),0,125, 210, 80)
2022-04-27 02:40:39 +00:00
end
function playdate.keyboard.keyboardWillHideCallback(ok)
if ok == false then
page = 0
playdate.wait(0.3)
editLoad()
2022-05-20 17:01:59 +00:00
else
mode = "editor"
sprSwitch:add()
sprFloppy:add()
playdate.wait(0.1)
2022-04-27 02:40:39 +00:00
end
2022-05-08 05:40:21 +00:00
end
function playdate.keyboard.textChangedCallback()
print(#playdate.keyboard.text)
if #playdate.keyboard.text > 24 then
playdate.keyboard.text = prevtext
end
prevtext = playdate.keyboard.text
2022-05-20 17:01:59 +00:00
end
local tileIndex = 0.0
local curY = math.floor( tileIndex ) * 30 + 2
local curYlerp = -32
function editUpdate()
local change, aChange = playdate.getCrankChange()
tileIndex += change * 0.01
curY = math.floor( tileIndex ) * 30 + 2
curYlerp = playdate.math.lerp(curYlerp, curY, 0.3)
if playdate.buttonJustPressed(playdate.kButtonA) then
if math.floor( tileIndex ) == 1 then
playdate.display.setInverted(not playdate.display.getInverted())
sprSwitch:setImage(imgSwitch:getImage(bool2int[playdate.display.getInverted()] + 1))
end
end
if playdate.buttonJustPressed(playdate.kButtonLeft) then
position.x -= 1
elseif playdate.buttonJustPressed(playdate.kButtonRight) then
position.x += 1
end
-- draw map
gfx.setDrawOffset(position.x*16,position.y*16)
-- draw ui
gfx.setDrawOffset(0,0)
gfx.sprite.update()
gfx.setColor(gfx.kColorWhite)
gfx.drawLine(360,0,360,240)
gfx.setColor(playdate.graphics.kColorXOR)
gfx.fillRect(365,curYlerp,33,30)
end
function editClose()
sprSwitch:remove()
sprFloppy:remove()
2022-04-27 02:40:39 +00:00
end