From b1456065c4164db4f1fc07119d478709ee441b31 Mon Sep 17 00:00:00 2001 From: Yareaj Date: Mon, 29 May 2023 01:19:55 -0500 Subject: [PATCH 1/3] Reorganized functions' files --- functions/functions.js | 83 +++--------------------------------- functions/levelHandler.js | 34 +-------------- functions/mapRenders.js | 88 +++++++++++++++++++++++++++++++++++++++ functions/movement.js | 22 ++++++++++ 4 files changed, 118 insertions(+), 109 deletions(-) create mode 100644 functions/mapRenders.js diff --git a/functions/functions.js b/functions/functions.js index 4374cec..45d34a5 100644 --- a/functions/functions.js +++ b/functions/functions.js @@ -1,53 +1,3 @@ -// Actions based upon the key pressed -function keyPressed() { - // Prevent keys to take effects upon level pass - if (levelPass) { - return; - } - - if (keyCode === UP_ARROW || key === 'w') { - playerMove('up'); - } else if (keyCode === DOWN_ARROW || key === 's') { - playerMove('down'); - } else if (keyCode === LEFT_ARROW || key === 'a') { - playerMove('left'); - } else if (keyCode === RIGHT_ARROW || key === 'd') { - playerMove('right'); - } else if (key === 'm') { - toMenu(); - } else if (key === 'r') { - loadLevelString(); - } -} - -// Function to process a string into a map -function processMap(mapString) { - let processedMap = []; - - mapString.forEach(row => { - processedMap.push(row.split('')); - }); - - // Loop to replace the map outline into something we can use! - for (let rowExpl=0; rowExpl { + processedMap.push(row.split('')); + }); + + // Loop to replace the map outline into something we can use! + for (let rowExpl=0; rowExpl Date: Mon, 29 May 2023 01:20:26 -0500 Subject: [PATCH 2/3] Custom level handling barebones --- custom.html | 25 +++++++++++++++++++++++++ custom.js | 35 +++++++++++++++++++++++++++++++++++ index.js | 12 ++++++------ play.html | 1 + 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 custom.html create mode 100644 custom.js diff --git a/custom.html b/custom.html new file mode 100644 index 0000000..ec96194 --- /dev/null +++ b/custom.html @@ -0,0 +1,25 @@ + + + + Sokoban Worlds + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/custom.js b/custom.js new file mode 100644 index 0000000..3b61b3d --- /dev/null +++ b/custom.js @@ -0,0 +1,35 @@ +let submitButton, textArea; + +function preload() { + // Load assets for render + backgroundImage = loadImage('./assets/images/menuBg.png'); + levelButtonStyles = loadJSON('./assets/json/levelButtonStyles.json'); + // Load buttons' fonts + loadFont('./assets/fonts/Fredoka-Medium.ttf'); +} + +function setup() { + createCanvas(500, 500); + submitButton = createButton('Submit'); + textArea = createElement('textarea'); + + // Apply styles to the menu buttons + applyStyles(submitButton, levelButtonStyles); + + // Apply styles to the text area + textArea.style('width', `${width-50}px`); + textArea.style('height', `${height/3}px`); + textArea.style('resize', 'none'); + textArea.attribute('placeholder', 'Insert the menu data'); + textArea.attribute('required', true); + textArea.position(30, height/1.97); + + // Position the submit button on the screen + submitButton.position(width/2.4, (height/1.95)+(height/3)+20); + + submitButton.mousePressed(obtainLevelData); +} + +function draw() { + image(backgroundImage, 0, 0); +} \ No newline at end of file diff --git a/index.js b/index.js index 0d4110d..f3a6e4d 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,7 @@ function setup() { createCanvas(500, 500); customLevelButton = createButton('Custom Level'); levelListButton = createButton('Play'); -} - -function draw() { - image(backgroundImage, 0, 0); - + // Apply styles to the menu buttons applyStyles(levelListButton, menuButtonStyles); applyStyles(customLevelButton, menuButtonStyles); @@ -27,5 +23,9 @@ function draw() { // Add listeners for button actions levelListButton.mousePressed(initiateLevelPlay); - customLevelButton.mousePressed(customLevelLoad); + customLevelButton.mousePressed(toCustom); +} + +function draw() { + image(backgroundImage, 0, 0); } \ No newline at end of file diff --git a/play.html b/play.html index b385ae6..2a7d3bb 100644 --- a/play.html +++ b/play.html @@ -18,6 +18,7 @@ + From edbe96f6f56043032b4f7d60697553539e74812c Mon Sep 17 00:00:00 2001 From: Yareaj Date: Mon, 29 May 2023 02:08:47 -0500 Subject: [PATCH 3/3] Custom map! --- custom.js | 3 +-- functions/functions.js | 8 +++++++- functions/levelHandler.js | 11 +++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/custom.js b/custom.js index 3b61b3d..e3f7d0a 100644 --- a/custom.js +++ b/custom.js @@ -20,13 +20,12 @@ function setup() { textArea.style('width', `${width-50}px`); textArea.style('height', `${height/3}px`); textArea.style('resize', 'none'); - textArea.attribute('placeholder', 'Insert the menu data'); + textArea.attribute('placeholder', 'Insert the custom level data'); textArea.attribute('required', true); textArea.position(30, height/1.97); // Position the submit button on the screen submitButton.position(width/2.4, (height/1.95)+(height/3)+20); - submitButton.mousePressed(obtainLevelData); } diff --git a/functions/functions.js b/functions/functions.js index 45d34a5..f2c025e 100644 --- a/functions/functions.js +++ b/functions/functions.js @@ -33,5 +33,11 @@ function toCustom() { } function obtainLevelData() { - console.log(textArea.value()); + customLevelString = textArea.value(); + + if (!customLevelString) { + return alert('Please insert level data'); + } + localStorage.setItem("mapId", customLevelString); + initiateLevelPlay(); } \ No newline at end of file diff --git a/functions/levelHandler.js b/functions/levelHandler.js index 2e7afc9..1bed4cd 100644 --- a/functions/levelHandler.js +++ b/functions/levelHandler.js @@ -28,9 +28,16 @@ function preload() { loadFont('./assets/fonts/Fredoka-Medium.ttf'); loadFont('./assets/fonts/Fredoka-Regular.ttf'); - // Import the map string into the global variable - mapOutline = loadStrings(`./assets/levels/level${levelId}.txt`); + const referrer = document.referrer.split('/') + const lastReference = referrer[referrer.length-1]; + // Import the map string into the global variable + if (lastReference == 'custom.html') { + mapOutline = localStorage.getItem("mapId").split('\n'); + } else { + mapOutline = loadStrings(`./assets/levels/level${levelId}.txt`); + } + // Load the buttonStyles JSON file buttonStyles = loadJSON('./assets/json/levelButtonStyles.json'); }