Skip to content

Commit

Permalink
can create a menu that pauses the gameplay
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomhausen committed Feb 24, 2024
1 parent bb15534 commit 294fe44
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
39 changes: 39 additions & 0 deletions menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

namespace miniMenu{


function createMenuAndPauseGame(items: miniMenu.MenuItem[]): miniMenu.MenuSprite{
let img = image.screenImage().clone();
game.pushScene();
scene.setBackgroundImage(img)
let myMenu = miniMenu.createMenuFromArray(items);
myMenu.onButtonPressed(controller.A, function (selection: string, selectedIndex: number) {
myMenu.close();
game.popScene();
})
return myMenu
}

/**
* Creates and returns a menu from an array of menu items passed in. Can toggle if the game is paused or not
*/
//% blockId=createPauseableMenu
//% block="create menu from $items where pause is $isPaused"
//% blockSetVariable=myMenu
//% items.shadow=lists_create_with
//% items.defl=mini_menu_create_menu_item
//% group="Create"
//% weight=99

export function createPauseableMenu(isPaused: boolean, items: miniMenu.MenuItem[]): miniMenu.MenuSprite{
let myMenu: miniMenu.MenuSprite;
if (isPaused){
myMenu = createMenuAndPauseGame(items);
}
else{
myMenu = createMenuFromArray(items);
}
return myMenu
}

}
8 changes: 2 additions & 6 deletions pxt.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
{
"name": "with music",
"name": "Menu Extension",
"description": "",
"dependencies": {
"device": "*",
"arcade-mini-menu": "github:riknoll/arcade-mini-menu#96cf1014271246d15b85368b45f298bd8c6609c4"
},
"files": [
"main.blocks",
"main.ts",
"README.md",
"assets.json",
"main.py",
"tilemap.g.jres",
"tilemap.g.ts"
"menu.ts"
],
"testFiles": [
"test.ts"
Expand Down

0 comments on commit 294fe44

Please sign in to comment.