From e4959d623688daa2ef578f22ba44ab3e31921447 Mon Sep 17 00:00:00 2001 From: PossiblyAxolotl Date: Sat, 23 Apr 2022 00:54:45 -0600 Subject: [PATCH] added main menu button --- Source/Main.lua | 9 ++++++--- Source/Map.lua | 6 +++++- Source/Menu.lua | 2 ++ Source/Player.lua | 5 +++-- Source/levels/level.json | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Source/levels/level.json diff --git a/Source/Main.lua b/Source/Main.lua index 4e2cba9..7efcea1 100644 --- a/Source/Main.lua +++ b/Source/Main.lua @@ -4,7 +4,7 @@ import "Player" import "Map" import "Menu" -local mode = "menu" +mode = "menu" local gfx = playdate.graphics local disp = playdate.display @@ -26,9 +26,12 @@ else end 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() if mode == "menu" then diff --git a/Source/Map.lua b/Source/Map.lua index 2d3d874..5080254 100644 --- a/Source/Map.lua +++ b/Source/Map.lua @@ -5,12 +5,16 @@ tilemap:setImageTable(tileTable) function addMap(_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 tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t) end + addPlayer(level.rocket.x,level.rocket.y) + gfx.sprite.addWallSprites(tilemap, {0,1}) + + mode = "game" end function drawTiles() diff --git a/Source/Menu.lua b/Source/Menu.lua index 6424075..f89ef08 100644 --- a/Source/Menu.lua +++ b/Source/Menu.lua @@ -11,6 +11,8 @@ local imgCursor = gfx.image.new("gfx/cursor") assert(imgCursor) function createMenu(items) + killPlayer() + mode = "menu" controlX = -80 index = 0 menuitems = {} diff --git a/Source/Player.lua b/Source/Player.lua index 975d76a..d630eed 100644 --- a/Source/Player.lua +++ b/Source/Player.lua @@ -26,6 +26,7 @@ function killPlayer() exists = false active = false sprRocket:remove() + gfx.setDrawOffset(0,0) end local function die() @@ -37,8 +38,8 @@ end function updatePlayer() if active == true then if playdate.buttonIsPressed(playdate.kButtonUp) then - velocity.x = velocity.x + math.sin(math.rad(playdate.getCrankPosition())) - velocity.y = velocity.y - math.cos(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())) /2 end sprRocket:moveBy(velocity.x,velocity.y) diff --git a/Source/levels/level.json b/Source/levels/level.json new file mode 100644 index 0000000..dbfdc41 --- /dev/null +++ b/Source/levels/level.json @@ -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}]} \ No newline at end of file