added main menu button

This commit is contained in:
PossiblyAxolotl 2022-04-23 00:54:45 -06:00
parent c9368c4031
commit e4959d6236
5 changed files with 17 additions and 6 deletions

View file

@ -4,7 +4,7 @@ import "Player"
import "Map" import "Map"
import "Menu" import "Menu"
local mode = "menu" mode = "menu"
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
local disp <const> = playdate.display local disp <const> = playdate.display
@ -26,9 +26,12 @@ else
end end
createMenu(mainmenu) createMenu(mainmenu)
--addMap("levels/level1.json") local menu = playdate.getSystemMenu()
local menuItem, error = menu:addMenuItem("Main Menu", function()
createMenu(mainmenu)
end)
--addPlayer(50,50) addMap("levels/level.json")
function playdate.update() function playdate.update()
if mode == "menu" then if mode == "menu" then

View file

@ -5,12 +5,16 @@ tilemap:setImageTable(tileTable)
function addMap(_file) function addMap(_file)
local level = json.decodeFile(_file) local level = json.decodeFile(_file)
tilemap:setSize(level.dimensions.x,level.dimensions.x) tilemap:setSize(level.dimensions.x,level.dimensions.y)
for i = 1, #level.tiles, 1 do for i = 1, #level.tiles, 1 do
tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t) tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t)
end end
addPlayer(level.rocket.x,level.rocket.y)
gfx.sprite.addWallSprites(tilemap, {0,1}) gfx.sprite.addWallSprites(tilemap, {0,1})
mode = "game"
end end
function drawTiles() function drawTiles()

View file

@ -11,6 +11,8 @@ local imgCursor = gfx.image.new("gfx/cursor")
assert(imgCursor) assert(imgCursor)
function createMenu(items) function createMenu(items)
killPlayer()
mode = "menu"
controlX = -80 controlX = -80
index = 0 index = 0
menuitems = {} menuitems = {}

View file

@ -26,6 +26,7 @@ function killPlayer()
exists = false exists = false
active = false active = false
sprRocket:remove() sprRocket:remove()
gfx.setDrawOffset(0,0)
end end
local function die() local function die()
@ -37,8 +38,8 @@ end
function updatePlayer() function updatePlayer()
if active == true then if active == true then
if playdate.buttonIsPressed(playdate.kButtonUp) then if playdate.buttonIsPressed(playdate.kButtonUp) then
velocity.x = velocity.x + math.sin(math.rad(playdate.getCrankPosition())) velocity.x = velocity.x + math.sin(math.rad(playdate.getCrankPosition())) /2
velocity.y = velocity.y - math.cos(math.rad(playdate.getCrankPosition())) velocity.y = velocity.y - math.cos(math.rad(playdate.getCrankPosition())) /2
end end
sprRocket:moveBy(velocity.x,velocity.y) sprRocket:moveBy(velocity.x,velocity.y)

1
Source/levels/level.json Normal file
View file

@ -0,0 +1 @@
{"dimensions":{"x":22,"y":17},"rocket":{"x":70.4,"y":125.6},"tiles":[{"t":2,"x":2,"y":1},{"t":2,"x":14,"y":1},{"t":2,"x":14,"y":5},{"t":2,"x":22,"y":5},{"t":2,"x":8,"y":6},{"t":2,"x":2,"y":12},{"t":2,"x":8,"y":12},{"t":2,"x":11,"y":12},{"t":2,"x":14,"y":12},{"t":2,"x":8,"y":17},{"t":2,"x":22,"y":17},{"t":3,"x":3,"y":1},{"t":3,"x":4,"y":1},{"t":3,"x":5,"y":1},{"t":3,"x":6,"y":1},{"t":3,"x":7,"y":1},{"t":3,"x":8,"y":1},{"t":3,"x":9,"y":1},{"t":3,"x":10,"y":1},{"t":3,"x":11,"y":1},{"t":3,"x":12,"y":1},{"t":3,"x":13,"y":1},{"t":3,"x":15,"y":5},{"t":3,"x":16,"y":5},{"t":3,"x":17,"y":5},{"t":3,"x":18,"y":5},{"t":3,"x":19,"y":5},{"t":3,"x":20,"y":5},{"t":3,"x":21,"y":5},{"t":3,"x":3,"y":12},{"t":3,"x":4,"y":12},{"t":3,"x":5,"y":12},{"t":3,"x":6,"y":12},{"t":3,"x":7,"y":12},{"t":3,"x":9,"y":12},{"t":3,"x":10,"y":12},{"t":3,"x":9,"y":17},{"t":3,"x":10,"y":17},{"t":3,"x":11,"y":17},{"t":3,"x":12,"y":17},{"t":3,"x":13,"y":17},{"t":3,"x":14,"y":17},{"t":3,"x":15,"y":17},{"t":3,"x":16,"y":17},{"t":3,"x":17,"y":17},{"t":3,"x":18,"y":17},{"t":3,"x":19,"y":17},{"t":3,"x":20,"y":17},{"t":3,"x":21,"y":17},{"t":4,"x":2,"y":2},{"t":4,"x":14,"y":2},{"t":4,"x":2,"y":3},{"t":4,"x":14,"y":3},{"t":4,"x":2,"y":4},{"t":4,"x":14,"y":4},{"t":4,"x":2,"y":5},{"t":4,"x":2,"y":6},{"t":4,"x":14,"y":6},{"t":4,"x":22,"y":6},{"t":4,"x":2,"y":7},{"t":4,"x":8,"y":7},{"t":4,"x":14,"y":7},{"t":4,"x":22,"y":7},{"t":4,"x":2,"y":8},{"t":4,"x":8,"y":8},{"t":4,"x":14,"y":8},{"t":4,"x":22,"y":8},{"t":4,"x":2,"y":9},{"t":4,"x":8,"y":9},{"t":4,"x":14,"y":9},{"t":4,"x":22,"y":9},{"t":4,"x":2,"y":10},{"t":4,"x":8,"y":10},{"t":4,"x":14,"y":10},{"t":4,"x":22,"y":10},{"t":4,"x":2,"y":11},{"t":4,"x":8,"y":11},{"t":4,"x":14,"y":11},{"t":4,"x":22,"y":11},{"t":4,"x":22,"y":12},{"t":4,"x":8,"y":13},{"t":4,"x":22,"y":13},{"t":4,"x":8,"y":14},{"t":4,"x":22,"y":14},{"t":4,"x":8,"y":15},{"t":4,"x":22,"y":15},{"t":4,"x":8,"y":16},{"t":4,"x":22,"y":16}]}