From e8c43c72dfbdf306ade0ddc5519c15b5c4815f05 Mon Sep 17 00:00:00 2001 From: PossiblyAxolotl Date: Fri, 22 Apr 2022 12:48:45 -0600 Subject: [PATCH] started work on menu system --- Source/Main.lua | 23 ++++++++++++++++------- Source/Map.lua | 2 +- Source/Menu.lua | 16 ++++++++++++++++ Source/levels/level1.json | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 Source/Menu.lua diff --git a/Source/Main.lua b/Source/Main.lua index 1f8e19d..ec84737 100644 --- a/Source/Main.lua +++ b/Source/Main.lua @@ -2,26 +2,35 @@ import "CoreLibs/graphics" import "CoreLibs/sprites" import "Player" import "Map" +import "Menu" + +local mode = "menu" local gfx = playdate.graphics local disp = playdate.display - local font = gfx.font.new("gfx/font") + gfx.setFont(font) gfx.setBackgroundColor(gfx.kColorBlack) local song1 = playdate.sound.sampleplayer.new("sfx/song1") song1:play(0, 1) -addMap("levels/level1.json") +gfx.setColor(gfx.kColorWhite) -addPlayer(50,50) +--addMap("levels/level1.json") + +--addPlayer(50,50) function playdate.update() + if mode == "menu" then + updateMenu() - updatePlayer() + elseif mode == "game" then + updatePlayer() - gfx.clear(gfx.kColorBlack) - gfx.sprite.update() - drawTiles() + gfx.clear(gfx.kColorBlack) + gfx.sprite.update() + drawTiles() + end end \ No newline at end of file diff --git a/Source/Map.lua b/Source/Map.lua index 8372ee3..2d3d874 100644 --- a/Source/Map.lua +++ b/Source/Map.lua @@ -2,10 +2,10 @@ local gfx = playdate.graphics local tileTable = gfx.imagetable.new("gfx/tiles") local tilemap = gfx.tilemap.new() tilemap:setImageTable(tileTable) -tilemap:setSize(100,100) function addMap(_file) local level = json.decodeFile(_file) + tilemap:setSize(level.dimensions.x,level.dimensions.x) for i = 1, #level.tiles, 1 do tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t) end diff --git a/Source/Menu.lua b/Source/Menu.lua new file mode 100644 index 0000000..570a631 --- /dev/null +++ b/Source/Menu.lua @@ -0,0 +1,16 @@ +local gfx = playdate.graphics +local controlY = 0 + +local crankY = 0 + +function updateMenu() + gfx.clear(gfx.kColorBlack) + -- input + if playdate.buttonJustPressed(playdate.kButtonUp) then + crankY -= 1 + elseif playdate.buttonJustPressed(playdate.kButtonDown) then + crankY += 1 + end + + gfx.fillRect(0,controlY + (10 * crankY),50,10) +end \ No newline at end of file diff --git a/Source/levels/level1.json b/Source/levels/level1.json index 94b4f02..23e8dd5 100644 --- a/Source/levels/level1.json +++ b/Source/levels/level1.json @@ -1 +1 @@ -{"tiles":[{"x":1,"y":1,"t":2},{"x":2,"y":1,"t":3},{"x":3,"y":1,"t":3},{"x":4,"y":1,"t":2}]} \ No newline at end of file +{"tiles":[{"x":1,"y":1,"t":2},{"x":2,"y":1,"t":3},{"x":3,"y":1,"t":3},{"x":4,"y":1,"t":2}],"dimensions":{"x":4,"y":2}} \ No newline at end of file