-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Yareaj/dev
Support for custom maps
- Loading branch information
Showing
8 changed files
with
199 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Sokoban Worlds</title> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="icon" type="image/x-icon" href="assets/player/head.png"> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/addons/p5.sound.min.js"></script> | ||
<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="globalVariables.js"></script> | ||
|
||
<!-- Import the distribution of functions --> | ||
<script src="functions/objects.js"></script> | ||
<script src="functions/functions.js"></script> | ||
<script src="functions/mapRenders.js"></script> | ||
|
||
<!-- Retrieve the level processor --> | ||
<script src="custom.js"></script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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 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); | ||
} | ||
|
||
function draw() { | ||
image(backgroundImage, 0, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Reset a level's canvas | ||
function mapReload() { | ||
// Reset the level's mechanics | ||
levelMap = null; | ||
playerQuad = null; | ||
mapData2dArray = null; | ||
|
||
// Reset control variables | ||
placedTargets = 0; | ||
stepsTaken = 0; | ||
levelPass = false; | ||
successAudio = true; | ||
|
||
// Reset object's variebles | ||
boxesQuadrilles = []; | ||
targetQuadrilles = []; | ||
renderBlocks = [ targetQuadrilles, boxesQuadrilles ]; | ||
|
||
// Hide the buttons | ||
menuButton.hide() | ||
nextButton.hide() | ||
|
||
// Reload the level | ||
setup(); | ||
} | ||
|
||
// 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.length; rowExpl++) { | ||
// Go through each cell and replace it with the needed properties for the builder | ||
for (let cellExpl=0; cellExpl<processedMap[rowExpl].length; cellExpl++) { | ||
processedMap[rowExpl][cellExpl] = processedMap[rowExpl][cellExpl].replace(/./, `${processedMap[rowExpl][cellExpl]}|${rowExpl}|${cellExpl}`); | ||
} | ||
}; | ||
|
||
// Loop to replace the array data into a quadrille builder! | ||
for (let rowExpl=0; rowExpl<processedMap.length; rowExpl++) { | ||
// Go through each cell and replace it with the block! | ||
for (let cellExpl=0; cellExpl<processedMap[rowExpl].length; cellExpl++) { | ||
const cellData = processedMap[rowExpl][cellExpl].split('|'); | ||
processedMap[rowExpl][cellExpl] = [ cellData[0], [ parseInt(cellData[1]), parseInt(cellData[2]) ] ]; | ||
} | ||
}; | ||
|
||
return processedMap; | ||
} | ||
|
||
// Render all of the quadrilles into the canvas | ||
function renderFullMapQuadrilles() { | ||
for (let rowIt=0; rowIt<mapData2dArray.length; rowIt++) { | ||
for (let cellIt=0; cellIt<mapData2dArray[rowIt].length; cellIt++) { | ||
const cellData = mapData2dArray[rowIt][cellIt]; | ||
|
||
// Set the player starting coordinates into the map | ||
if (cellData[0] == '@') { | ||
playerPos.row = cellData[1][0]; | ||
playerPos.col = cellData[1][1]; | ||
} else if (cellData[0] == '+') { | ||
// Player position definiton | ||
playerPos.row = cellData[1][0]; | ||
playerPos.col = cellData[1][1]; | ||
// Create the target | ||
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].toReversed() ] ); | ||
} else if (cellData[0] == '$') { | ||
boxesQuadrilles.push( [ createQuadrille([ images.blocks.box ]), cellData[1].toReversed() ] ); | ||
} else if (cellData[0] == '*') { | ||
boxesQuadrilles.push( [ createQuadrille([ images.blocks.boxSecured ]), cellData[1].toReversed() ] ); | ||
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].toReversed() ] ); | ||
} else if (cellData[0] == '.') { | ||
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].toReversed() ] ); | ||
} | ||
|
||
// Set all cells but walls to be the background color | ||
if (cellData[0] == '#') { | ||
levelMap._memory2D[rowIt][cellIt] = images.blocks.wall; | ||
} else { | ||
levelMap._memory2D[rowIt][cellIt] = color('#2f4f4f'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters