begun saving

This commit is contained in:
PossiblyAxolotl 2022-05-22 11:27:01 -06:00
parent 9ff93fdf2e
commit d9adc3662e
7 changed files with 63 additions and 37 deletions

3
.gitignore vendored
View file

@ -62,4 +62,5 @@ $RECYCLE.BIN/
.gitignore .gitignore
*.pdx *.pdx
.vscode .vscode
*.zip

View file

@ -1,8 +1,11 @@
import "CoreLibs/keyboard" import "CoreLibs/keyboard"
import "CoreLibs/animation"
import "CoreLibs/math" import "CoreLibs/math"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local prevtext = "" local prevtext = ""
local levelname = nil
local inverted = false
gfx.setLineWidth(5) gfx.setLineWidth(5)
local tileTable <const> = gfx.imagetable.new("gfx/tiles") local tileTable <const> = gfx.imagetable.new("gfx/tiles")
@ -15,22 +18,24 @@ local imgtiles = gfx.sprite.new(tilemapEditor)
local w, h = imgtiles:getSize() local w, h = imgtiles:getSize()
imgtiles:moveTo(w/2,h/2) imgtiles:moveTo(w/2,h/2)
local position = {x=0,y=0} local position = {x=100,y=100}
local positionLerp = {x=0,y=0} local positionLerp = {x=0,y=0}
local bool2int = {[true]=1,[false]=0} local bool2int = {[true]=1,[false]=0}
local menu = playdate.getSystemMenu() local menu = playdate.getSystemMenu()
local toolTipButton, error local toolTipButton, error
local altClrButton, error
local editor = "main" local editor = "main"
local imgSwitch = gfx.imagetable.new("gfx/switch") local imgSwitch = gfx.imagetable.new("gfx/switch")
local imgFloppy = gfx.image.new("gfx/floppy") local imgFloppy = gfx.imagetable.new("gfx/floppyT")
local imgAdd = gfx.image.new("gfx/add") local imgAdd = gfx.image.new("gfx/add")
local imgMus = gfx.image.new("gfx/music") local imgMus = gfx.image.new("gfx/music")
local imgLine = gfx.image.new("gfx/line") local imgLine = gfx.image.new("gfx/line")
local imgSpin = gfx.image.new("gfx/spin") local imgSpin = gfx.image.new("gfx/spin")
local imgCursor = gfx.image.new("gfx/cursor2") local imgCursor = gfx.image.new("gfx/cursor2")
local imgCant = gfx.image.new("gfx/nothing")
assert(imgSwitch) assert(imgSwitch)
assert(imgFloppy) assert(imgFloppy)
assert(imgAdd) assert(imgAdd)
@ -39,6 +44,10 @@ assert(imgLine)
assert(imgSpin) assert(imgSpin)
assert(imgCursor) assert(imgCursor)
local animFloppy = gfx.animation.loop.new(100, imgFloppy)
local saveTime = 0
function newProject() function newProject()
mode = "newproj" mode = "newproj"
playdate.keyboard.show("NEW LEVEL") playdate.keyboard.show("NEW LEVEL")
@ -57,9 +66,13 @@ function playdate.keyboard.keyboardWillHideCallback(ok)
editLoad() editLoad()
else else
mode = "editor" mode = "editor"
toolTipButton, error = menu:addCheckmarkMenuItem("show help",true, function(value) toolTipButton, error = menu:addMenuItem("save",false, function()
print(value) editSave()
end) end)
altClrButton, error = menu:addCheckmarkMenuItem("alt colours",inverted, function(value)
playdate.display.setInverted(value)
end)
levelname = playdate.keyboard.text:upper()
imgtiles:add() imgtiles:add()
menuButton:setTitle("save & quit") menuButton:setTitle("save & quit")
playdate.wait(0.1) playdate.wait(0.1)
@ -81,30 +94,37 @@ local tileIndex = 0.0
local curY = math.floor( tileIndex ) * 28 + 3 local curY = math.floor( tileIndex ) * 28 + 3
local curYlerp = -32 local curYlerp = -32
function editSave()
saveTime = 5
playdate.datastore.write({tiles = tiles},"levels/"..levelname)
end
function editUpdate() function editUpdate()
local change, aChange = playdate.getCrankChange() local change, aChange = playdate.getCrankChange()
tileIndex += change * 0.01 tileIndex += change * 0.01
if tileIndex > 7.9 then tileIndex = 0 end if editor == "main" then
if tileIndex < 0 then tileIndex = 7.9 end if tileIndex > 7.9 then tileIndex = 0 end
if tileIndex < 0 then tileIndex = 7.9 end
curY = math.floor( tileIndex ) * 28 +7
curY = math.floor( tileIndex ) * 28 +7
end
curYlerp = playdate.math.lerp(curYlerp, curY, 0.4) curYlerp = playdate.math.lerp(curYlerp, curY, 0.4)
positionLerp.x = playdate.math.lerp(positionLerp.x, position.x * 16, 0.5) positionLerp.x = playdate.math.lerp(positionLerp.x, position.x * 16, 0.5)
positionLerp.y = playdate.math.lerp(positionLerp.y, position.y * 16, 0.5) positionLerp.y = playdate.math.lerp(positionLerp.y, position.y * 16, 0.5)
if playdate.buttonJustPressed(playdate.kButtonA) then if playdate.buttonJustPressed(playdate.kButtonA) then
if math.floor( tileIndex ) == 1 then if editor == "main" then
playdate.display.setInverted(not playdate.display.getInverted()) if math.floor( tileIndex ) == 0 then
elseif math.floor( tileIndex ) == 3 then tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2)
tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2) tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2}
tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, 2} imgtiles = gfx.sprite.new(tilemapEditor)
imgtiles = gfx.sprite.new(tilemapEditor) w, h = imgtiles:getSize()
w, h = imgtiles:getSize() imgtiles:moveTo(w/2,h/2)
imgtiles:moveTo(w/2,h/2) end
end end
end end
@ -119,36 +139,49 @@ function editUpdate()
position.y += 1 position.y += 1
end end
if position.x + 11 < 0 then position.x = -11 end
if position.y + 7 < 0 then position.y = -7 end
gfx.clear() gfx.clear()
-- draw map -- draw map
gfx.setDrawOffset(-positionLerp.x, -positionLerp.y) gfx.setDrawOffset(-positionLerp.x, -positionLerp.y)
imgtiles:update() imgtiles:update()
imgCursor:draw((position.x + 11) * 16, (position.y + 7) * 16) imgCursor:draw((position.x + 11) * 16, (position.y + 7) * 16)
if position.y < 1 then
imgCant:drawTiled((position.x-1) * 16,-112,400,112)
end
if position.x < 1 then
imgCant:drawTiled(-176,(position.y-1) * 16,176,272)
end
-- draw ui/ -- draw ui/
gfx.setDrawOffset(0,0) gfx.setDrawOffset(0,0)
gfx.setColor(gfx.kColorBlack) gfx.setColor(gfx.kColorBlack)
gfx.fillRect(365,0,400,240) gfx.fillRect(362,0,400,240)
gfx.setColor(gfx.kColorWhite) gfx.setColor(gfx.kColorWhite)
gfx.drawLine(360,0,360,240) gfx.drawLine(360,0,360,240)
-- draw changes -- draw changes
if editor == "main" then if editor == "main" then
imgMus:draw(366, 64) imgMus:draw(366, 128)
imgAdd:draw(366,93) imgAdd:draw(366,8)
imgSwitch:getImage(bool2int[playdate.display.getInverted()] + 1):draw(366,36) imgLine:draw(366,36)
imgFloppy:draw(366,8) imgSpin:draw(366,64)
imgLine:draw(366,120)
imgSpin:draw(366,148)
end end
gfx.setColor(playdate.graphics.kColorXOR) gfx.setColor(playdate.graphics.kColorXOR)
gfx.fillRect(365,curYlerp,33,28) gfx.fillRect(365,curYlerp,33,28)
if saveTime > 0 then
saveTime -= 0.1
animFloppy:draw(2,2)
end
end end
function editClose() function editClose()
editSave()
for tile = 1, #tiles, 1 do for tile = 1, #tiles, 1 do
tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0) tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0)
end end

View file

@ -23,8 +23,6 @@ local disp <const> = playdate.display
local font <const> = gfx.font.new("gfx/big") local font <const> = gfx.font.new("gfx/big")
small = gfx.font.new("gfx/font(1)") small = gfx.font.new("gfx/font(1)")
dev = false
gfx.setFont(font) gfx.setFont(font)
gfx.setBackgroundColor(gfx.kColorBlack) gfx.setBackgroundColor(gfx.kColorBlack)
@ -71,12 +69,6 @@ playdate.ui.crankIndicator:start()
if playdate.file.exists("levels") == false then playdate.file.mkdir("levels") end if playdate.file.exists("levels") == false then playdate.file.mkdir("levels") end
function playdate.keyPressed(key)
if key == "D" then
dev = not dev
end
end
function playdate.update() function playdate.update()
if mode == "menu" then if mode == "menu" then
updateMenu() updateMenu()
@ -109,11 +101,6 @@ function playdate.update()
playdate.ui.crankIndicator:update() playdate.ui.crankIndicator:update()
end end
end end
if dev then
local ox, oy = gfx.getDrawOffset()
playdate.drawFPS(0,228)
small:drawText(math.floor( playdate.getCrankPosition() ), -ox, -oy + 218)
end
updateSaws() updateSaws()
end end
@ -122,4 +109,9 @@ function playdate.gameWillTerminate()
playdate.datastore.delete("savegame.json") playdate.datastore.delete("savegame.json")
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame") playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
end end
end
function playdate.debugDraw()
playdate.drawFPS(0,228)
small:drawText(math.floor( playdate.getCrankPosition() ), 0, 218)
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 B

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

BIN
Source/gfx/nothing.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

Binary file not shown.