saws now move

This commit is contained in:
PossiblyAxolotl 2022-06-11 21:08:20 -06:00
parent 8f75bc27e6
commit 4ff84eb6ba
13 changed files with 69 additions and 27 deletions

View file

@ -12,6 +12,7 @@ local tileTable <const> = gfx.imagetable.new("gfx/tiles")
local tilemapEditor = gfx.tilemap.new()
tilemapEditor:setImageTable(tileTable)
local tiles = {}
local sawblades = {}
tilemapEditor:setSize(1000,1000)
local imgtiles = gfx.sprite.new(tilemapEditor)
@ -23,6 +24,8 @@ local menu = playdate.getSystemMenu()
local toolTipButton
local altClrButton
local pos1 = {x,y}
local editor = "main"
local imgFloppy = gfx.imagetable.new("gfx/floppyT")
@ -38,8 +41,9 @@ local imgExit = gfx.image.new("gfx/exit")
local imgEye = gfx.image.new("gfx/eye")
local imgPlayer = gfx.image.new("gfx/rocket")
local imgPlayerExit = gfx.image.new("gfx/bigrocket")
local imgB = gfx.image.new("gfx/bButton")
local imgExitMen = gfx.image.new("gfx/leave")
local imgSaw = gfx.imagetable.new("gfx/sawblades")
local imgTarget = gfx.image.new("gfx/target")
assert(imgFloppy)
assert(imgAdd)
assert(imgMus)
@ -51,7 +55,8 @@ assert(imgRocket)
assert(imgEye)
assert(imgPlayer)
assert(imgPlayerExit)
assert(imgB)
assert(imgSaw)
assert(imgTarget)
local animFloppy = gfx.animation.loop.new(100, imgFloppy)
@ -77,18 +82,20 @@ end
function editLoadName(name)
song:stop()
mode = "editor"
playdate.wait(0.1)
local data = json.decodeFile("levels/"..name)
playdate.wait(0.1)
powers = data.fuel
sawblades = data.saws
playerPos = {x = data.rocket.x, y = data.rocket.y}
exitPos = {x = data.bigrocket.x, y = data.bigrocket.y}
position = {x = (data.rocket.x + 6) / 16, y = (data.rocket.y + 4)/16}
playdate.wait(0.1)
levelname = name:match("(.+)%..+$")
inverted = data.inverted
playdate.display.setInverted(data.inverted)
saveTime = 0
mode = "editor"
playdate.wait(0.1)
-- loading tiles
@ -119,16 +126,17 @@ function playdate.keyboard.keyboardWillHideCallback(ok)
editLoad()
else
song:stop()
mode = "editor"
playdate.wait(0.1)
position = {x=89,y=93}
playerPos = {x=1562,y=1564}
exitPos = {x = 1616, y = 1536}
for tile = 1, #tiles, 1 do
tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0)
end
inverted = false
playdate.display.setInverted(false)
saveTime = 0
song:stop()
mode = "editor"
playdate.wait(0.1)
altClrButton, error = menu:addCheckmarkMenuItem("alt colours",false, function(value)
playdate.display.setInverted(value)
inverted = value
@ -161,9 +169,11 @@ local curYlerp = -32
function editSave()
playdate.datastore.delete("levels/"..levelname..".json")
saveTime = 5
playdate.datastore.write({tiles = tiles, inverted = inverted, rocket=playerPos, bigrocket=exitPos, fuel = powers,saws={},rotators={}},"levels/"..levelname)
playdate.datastore.write({tiles = tiles, inverted = inverted, rocket=playerPos, bigrocket=exitPos, fuel = powers,saws=sawblades,rotators={}},"levels/"..levelname)
end
local traveltime = 1
function editUpdate()
--print(math.floor( tileIndex ) )
local change, aChange = playdate.getCrankChange()
@ -180,6 +190,10 @@ function editUpdate()
if tileIndex > #tileTable then tileIndex = 0 end
curY = (math.floor( tileIndex ) % 8) * 28 +7
elseif editor == "pos2Saw" then
traveltime += change * 0.01
if traveltime < 0.2 then traveltime = 0.2 end
traveltime = tonumber(string.format("%.2f", traveltime))
end
curYlerp = playdate.math.lerp(curYlerp, curY, 0.4)
@ -187,7 +201,12 @@ function editUpdate()
positionLerp.y = playdate.math.lerp(positionLerp.y, position.y * 16, 0.5)
if playdate.buttonJustPressed(playdate.kButtonA) then
if editor == "tiles" then
if editor == "pos2Saw" then
sawblades[#sawblades+1] = {start={x=pos1.x,y=pos1.y},ends = {x=(position.x + 11) * 16,y=(position.y + 7) * 16}, speed = traveltime}
editor = "main"
printTable(sawblades[#sawblades])
tileIndex = 2
elseif editor == "tiles" then
if math.floor( tileIndex ) == 0 then
editor = "main"
else
@ -205,6 +224,10 @@ function editUpdate()
editor = "tiles"
elseif math.floor(tileIndex) == 1 then
powers[#powers+1] = {x=((position.x + 11) * 16)-7, y=((position.y + 7) * 16)-5}
elseif math.floor(tileIndex) == 2 then
pos1.x,pos1.y=((position.x + 11) * 16), ((position.y + 7) * 16)
tileIndex = 0
editor = "pos2Saw"
elseif math.floor(tileIndex) == 4 then
playerPos = {x = ((position.x + 11) * 16) - 6, y = ((position.y + 7) * 16) - 4}
elseif math.floor(tileIndex) == 5 then
@ -224,6 +247,10 @@ function editUpdate()
break
end
end
elseif editor == "pos2Saw" then
pos1 = nil
tileIndex = 2
editor = "main"
elseif editor == "main" then
--[[if math.floor( tileIndex ) == 0 then
tilemapEditor:setTileAtPosition(position.x+12,position.y+8,0)
@ -241,6 +268,12 @@ function editUpdate()
break
end
end
elseif math.floor( tileIndex ) == 2 then
for saw= 1, #sawblades, 1 do
if sawblades[saw].start.x == (position.x + 11) * 16 and sawblades[saw].start.y == (position.y + 7) * 16 then
table.remove(sawblades, saw)
end
end
end
elseif editor == "view" then
editor = "main"
@ -271,6 +304,16 @@ function editUpdate()
imgPlayerExit:draw(exitPos.x, exitPos.y)
imgPlayer:draw(playerPos.x,playerPos.y)
for saw = 1, #sawblades, 1 do
local b = sawblades[saw]
imgSaw[1]:draw(b.start.x,b.start.y)
imgTarget:draw(b.ends.x,b.ends.y)
if editor == "main" and math.floor( tileIndex ) == 2 then
playdate.graphics.setLineWidth(2)
gfx.drawLine(b.start.x+8,b.start.y+8,b.ends.x+8,b.ends.y+8)
end
end
for power = 1, #powers, 1 do
imgSquare:draw(powers[power].x,powers[power].y)
end
@ -289,9 +332,12 @@ function editUpdate()
if position.x < 1 then
imgCant:drawTiled(-176,(position.y-1) * 16,176,272)
end
if editor == "pos2Saw" then
imgSaw[1]:draw(pos1.x,pos1.y)
end
-- draw ui/
if editor ~= "view" then
gfx.setLineWidth(5)
gfx.setDrawOffset(0,0)
gfx.setColor(gfx.kColorBlack)
gfx.fillRect(362,0,400,240)
@ -311,6 +357,8 @@ function editUpdate()
tileTable[6+ind]:draw(373,153)
tileTable[7+ind]:draw(373,181)
tileTable[8+ind]:draw(373,209)
elseif editor == "pos2Saw" then
gfx.drawText("SELECT TARGET POSITION \nTRAVEL TIME: "..traveltime,0,0)
elseif editor == "main" then
imgMus:draw(366, 176)
imgAdd:draw(366,8)
@ -353,9 +401,10 @@ end
function editClose()
for tile = 1, #tiles, 1 do
tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0)
tiles[tile] = nil
end
tiles = {}
powers = {}
sawblades = {}
editor = "main"
tileIndex = 0
playdate.display.setInverted(false)

View file

@ -55,6 +55,7 @@ menuButton, error = menu:addMenuItem("game menu", function()
if mode =="game" or mode == "play" then
killPlayer()
removeMap()
killBlades()
end
totalEnergy = 0
showEnergy = false

View file

@ -14,13 +14,11 @@ function addMapSave(_file)
end
function addMap(_file, rs)
killBlades()
killPlayer()
removeMap()
next = nil
if rs then deaths = 0 end
if #tiles > 0 then
for i = 1, #tiles, 1 do
tiles[i]:remove()
end
end
local level = json.decodeFile(_file)
local width = 0
local height = 0

View file

@ -100,12 +100,13 @@ local function playerWin()
totalEnergy = 0
showEnergy = false
energy = 0
killBlades()
killPlayer()
removeMap()
if mode == "game" and next then
playdate.datastore.delete("savegame")
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
next = nil
killBlades()
killPlayer()
addMapSave(map)
else
mainMenuCreation()

View file

@ -18,8 +18,8 @@ local fuels = {}
function loadBlades(_blades)
for i = 1, #_blades,1 do
local b = _blades[i]
b.start = playdate.geometry.point.new(b.start.x,b.start.y)
b.ends = playdate.geometry.point.new(b.ends.x,b.ends.y)
b.start = playdate.geometry.point.new(b.start.x+8,b.start.y+8)
b.ends = playdate.geometry.point.new(b.ends.x+8,b.ends.y+8)
b.saw = gfx.sprite.new(loopSaws:image())
b.saw:moveTo(b.start)
b.saw:setCollideRect(0,0,16,16)

View file

@ -13,9 +13,7 @@
"rotators": [
{"x":1368,"y":1624,"speed":-0.5,"arms":1,"armlen":4}
],
"saws": [
{"speed":2,"start":{"x":1560,"y":1640},"ends":{"x":1560,"y":1720}}
],
"saws": [],
"tiles": [
{
"t":2,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 B

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 484 B

After

Width:  |  Height:  |  Size: 467 B