Skip to content

Commit

Permalink
Added menu handler!
Browse files Browse the repository at this point in the history
  • Loading branch information
Yareaj committed May 29, 2023
1 parent 4f2414f commit fb26a92
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
13 changes: 12 additions & 1 deletion functions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ function mapReload() {
setup();
}

// Go to the menu
function toMenu() {
window.location.href = "./menu.html";
window.location.href = "./index.html";
}

// Go to the level player!
function initiateLevelPlay() {
window.location.href = "./play.html";
}

// Go to the custom landing page!
function customLevelLoad() {
console.log('Here relies the custom level loader!');
}
2 changes: 1 addition & 1 deletion functions/levelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function preload() {
mapOutline = loadStrings(`./assets/levels/level${levelId}.txt`);

// Load the buttonStyles JSON file
buttonStyles = loadJSON('./assets/json/buttonStyles.json');
buttonStyles = loadJSON('./assets/json/levelButtonStyles.json');
}

function setup() {
Expand Down
9 changes: 2 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@

<!-- Retrieve the variables used across the whole project -->
<script src="globalVariables.js"></script>

<!-- Import the distribution of functions -->
<script src="functions/objects.js"></script>
<script src="functions/movement.js"></script>
<script src="functions/functions.js"></script>

<!-- Retrieve the level processor -->
<script src="functions/levelHandler.js"></script>
<script src="functions/objects.js"></script>
<script src="index.js"></script>
</head>
</html>
31 changes: 20 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
let head;
let backgroundImage, customLevelButton, levelListButton;

function preload() {
head = loadImage('./assets/player/head.png');
loadFont('./assets/fonts/Fredoka-Medium.ttf');
// Load assets for render
backgroundImage = loadImage('./assets/images/menuBg.png');
menuButtonStyles = loadJSON('./assets/json/menuButtonStyles.json');
// Load buttons' fonts
loadFont('./assets/fonts/Fredoka-Bold.ttf');
}

function setup() {
createCanvas(500, 500);
customLevelButton = createButton('Custom Level');
levelListButton = createButton('Play');
}

function draw() {
background('#6f6f');
image(head, 0, 0);
image(backgroundImage, 0, 0);

textFont('Fredoka-Medium');
textSize(40);
fill('#000');
const w = textWidth('Sokoban Worlds');
text(w, 100, 300);
text('Sokoban Worlds', 80, 100);
// Apply styles to the menu buttons
applyStyles(levelListButton, menuButtonStyles);
applyStyles(customLevelButton, menuButtonStyles);

// Position the buttons on the screen
levelListButton.position(width/2.4, height/1.93);
customLevelButton.position(width/3.6, height/1.5);

// Add listeners for button actions
levelListButton.mousePressed(initiateLevelPlay);
customLevelButton.mousePressed(customLevelLoad);
}
10 changes: 8 additions & 2 deletions menu.html → play.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
<script src="https://cdn.jsdelivr.net/gh/objetos/p5.quadrille.js/p5.quadrille.min.js"></script>

<!-- Retrieve the variables used across the whole project -->
<script src="index.js"></script>
<script src="globalVariables.js"></script>

<h1>Welcome to the menu boys</h1>
<!-- Import the distribution of functions -->
<script src="functions/objects.js"></script>
<script src="functions/movement.js"></script>
<script src="functions/functions.js"></script>

<!-- Retrieve the level processor -->
<script src="functions/levelHandler.js"></script>
</head>
</html>

0 comments on commit fb26a92

Please sign in to comment.