import "CoreLibs/keyboard" import "CoreLibs/math" local gfx = playdate.graphics local prevtext = "" 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) function newProject() mode = "newproj" playdate.keyboard.show("NEW LEVEL") end function updateNewproj() gfx.clear() gfx.drawText("LEVEL NAME:", 0, 105) gfx.drawTextInRect(playdate.keyboard.text:upper(),0,125, 210, 80) end function playdate.keyboard.keyboardWillHideCallback(ok) if ok == false then page = 0 playdate.wait(0.3) editLoad() else mode = "editor" sprSwitch:add() sprFloppy:add() playdate.wait(0.1) end end function playdate.keyboard.textChangedCallback() print(#playdate.keyboard.text) if #playdate.keyboard.text > 24 then playdate.keyboard.text = prevtext end prevtext = playdate.keyboard.text 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() end