Skip to content

Commit

Permalink
Merge pull request #10 from Yareaj/dev
Browse files Browse the repository at this point in the history
Adding sample levels to the game
  • Loading branch information
Yareaj authored May 29, 2023
2 parents a0aabb2 + e6bf678 commit ad1e8cd
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 55 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ A JavaScript implementation of the 🎮 [Sokoban](https://en.wikipedia.org/wiki/

### Credits
- [Forbidden](./assets/sounds/forbidden.wav), [success](./assets/sounds/success.wav) sound effects created using [sfxr.me](https://sfxr.me/)
- [Level Up](./assets/sounds/levelUp.wav) sound effect was taken from [freesound.org](https://freesound.org/people/EVRetro/sounds/535840/)
- [Footstep](./assets/sounds/levelUp.wav) sound effect was taken from [freesound.org](https://freesound.org/people/EVRetro/sounds/501102/)
- [Level Up](https://freesound.org/people/EVRetro/sounds/535840/), [Footstep](https://freesound.org/people/EVRetro/sounds/501102/) and [Level Alert](https://freesound.org/people/EVRetro/sounds/495004/) sound effets were created by [EVRetro](https://freesound.org/people/EVRetro)
- All of the game's image assets were retrieved from [Kenney.nl](https://kenney.nl/assets/sokoban)
- The original level processor and map format was based on [csixteen](https://github.com/csixteen/sokoban)'s implementation of Sokoban (`Thanks for the help Pedro :)`)
- The idea of implementing the [Sokoban Level Format](http://sokobano.de/wiki/index.php?title=Level_format), as well as taking the Fredoka font was implemented based on [krzysu](https://github.com/krzysu/elm-sokoban-player)'s implementation of Sokoban
- The idea of implementing the [Sokoban Level Format](http://sokobano.de/wiki/index.php?title=Level_format), as well as taking the Fredoka font was implemented based on [krzysu](https://github.com/krzysu/elm-sokoban-player)'s implementation of Sokoban
- The [Fredoka fonts](./assets/fonts/) were taken from [Google Fonts](https://fonts.google.com/specimen/Fredoka)
- Levels were taken from the public [Sokoban Levels](https://www.sourcecode.se/sokoban/levels) list as depicted:
- Levels 1 - 10 taken or adapted from the `Boxxle 2` collection done by Thinking Rabbit.
13 changes: 3 additions & 10 deletions assets/levels/level0.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
##########
# #
# @ #
# $ $ #
# . #
#### #
# $ #. #
# # #
# . # #
##########
#####
#@$.#
#####
18 changes: 8 additions & 10 deletions assets/levels/level1.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
##########
# #
# @ . #
# $ #
# #
##### ####
# # #
# $ # #
# . # #
##########
#####
# #####
# $ # #
# #$# #
###$ #
# ####
# @...#
#######
9 changes: 9 additions & 0 deletions assets/levels/level10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#######
# $. #
#. .$.#
#$.*. #
# $*$ #
# . #
# $*$ #
# * @#
#######
13 changes: 7 additions & 6 deletions assets/levels/level2.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
##########
# .$ #
# $## ## #
# .@ $ #
# .# #
##########
#######
# . ##
# $ $ #
#. * .#
# $ $ #
## . @#
#######
19 changes: 9 additions & 10 deletions assets/levels/level3.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
##########
# #
# @ #
# $ $ #
# . #
#### #
# $ #. #
# # #
# . # #
##########
#########
# @#
# $.$.$ #
# .$.$. #
# $.*.$ #
# .$.$. #
# $.$.$ #
# #
#########
9 changes: 9 additions & 0 deletions assets/levels/level4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#####
# #
### . #
# . #####
# ##$## @ #
# . $ #
###$ #####
# #
#####
9 changes: 9 additions & 0 deletions assets/levels/level5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#######
# . #
# $*$.#
# .. #
#$$*$$#
# .. #
#.$*$ #
# . @#
#######
8 changes: 8 additions & 0 deletions assets/levels/level6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
######
# @ #
#### $ #
# *..*$ #
# $*..* #
# $ ####
# #
######
7 changes: 7 additions & 0 deletions assets/levels/level7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
######
# # .#
# $ .#
#@ $.#
# $$.#
# ###
####
7 changes: 7 additions & 0 deletions assets/levels/level8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
########
# @ #
##$ $ $ #
# $ # $ #
# $ # ##
#......#
########
9 changes: 9 additions & 0 deletions assets/levels/level9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#######
# #
# $.$ #
# .$. #
#*$.$*#
# .$. #
# .$ #
# @ #
#######
Binary file added assets/sounds/levelAlert.wav
Binary file not shown.
21 changes: 18 additions & 3 deletions functions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function keyPressed() {
playerMove('left');
} else if (keyCode === RIGHT_ARROW || key === 'd') {
playerMove('right');
} else if (key === 'm') {
toMenu();
} else if (key === 'r') {
loadLevelString();
}
}

Expand All @@ -37,19 +41,30 @@ function processMap(mapString) {
// 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]) ] ]
processedMap[rowExpl][cellExpl] = [ cellData[0], [ parseInt(cellData[1]), parseInt(cellData[2]) ] ];
}
};

return processedMap;
}

// Change the level ID
function increaseId() {
levelId = levelId + 1;
}

// Load the new map into the global variable mapOutline
function loadLevelString() {
levelId = levelId + 1;
// Use callback to reload the map once the string has been processed
mapOutline = loadStrings(`./assets/levels/level${levelId || 1}.txt`, mapReload);
mapOutline = loadStrings(`./assets/levels/level${levelId}.txt`, mapReload);
levelPass = false;
sounds.levelAlert.play();
}

// Go to next level!
function nextLevel() {
increaseId();
loadLevelString();
}

function mapReload() {
Expand Down
21 changes: 13 additions & 8 deletions functions/levelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function preload() {
success: loadSound('./assets/sounds/success.wav'),
forbidden: loadSound('./assets/sounds/forbidden.wav'),
levelUp: loadSound('./assets/sounds/levelUp.wav'),
powerUp: loadSound('./assets/sounds/powerUp.wav')
powerUp: loadSound('./assets/sounds/powerUp.wav'),
levelAlert: loadSound('./assets/sounds/levelAlert.wav')
}

// Import the button's fonts into the project
Expand All @@ -44,7 +45,7 @@ function setup() {
background('#2f4f4f');

// Define the level's map dimensions
levelMap = createQuadrille(rows, columns);
levelMap = createQuadrille(columns, rows);

// Creates an independent quadrille for the player
playerQuad = createQuadrille([ images.player.up ]);
Expand All @@ -66,14 +67,14 @@ function setup() {
playerPos.row = cellData[1][0];
playerPos.col = cellData[1][1];
// Create the target
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].reverse() ] );
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].toReversed() ] );
} else if (cellData[0] == '$') {
boxesQuadrilles.push( [ createQuadrille([ images.blocks.box ]), cellData[1].reverse() ] );
boxesQuadrilles.push( [ createQuadrille([ images.blocks.box ]), cellData[1].toReversed() ] );
} else if (cellData[0] == '*') {
boxesQuadrilles.push( [ createQuadrille([ images.blocks.box ]), cellData[1].reverse() ] );
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].reverse() ] );
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].reverse() ] );
targetQuadrilles.push( [ createQuadrille([ images.blocks.boxTarget ]), cellData[1].toReversed() ] );
}

// Set all cells but walls to be the background color
Expand All @@ -88,7 +89,7 @@ function setup() {
nextButton = createButton('Next');
nextButton.position((width/2)+textWidth('Menu')-textWidth('Next'), (height/2));
nextButton.hide();
nextButton.mousePressed(loadLevelString);
nextButton.mousePressed(nextLevel);

menuButton = createButton('Menu');
menuButton.position((width/2)-textWidth('Menu')-textWidth('Next')-20, (height/2));
Expand Down Expand Up @@ -127,6 +128,10 @@ function draw() {
const xCordSteps = ((width+(Quadrille.CELL_LENGTH/2))/2)-(textWidth('Steps'));
text(`Steps: ${stepsTaken}`, xCordSteps, Quadrille.CELL_LENGTH/1.5);

// Add a level indicator top left corner
textSize(10);
text(`Level ${levelId}`, 5, 10);

// Stop game execution upon finishing the level and create the buttons
if (levelPass) {
// Create screening
Expand Down
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
let head;
/**
* Some sources to include upon the credits
* https://allbestfonts.com/ (fonts)
* https://fonts.google.com/specimen/Fredoka
*/

function preload() {
head = loadImage('./assets/player/head.png');
Expand Down

0 comments on commit ad1e8cd

Please sign in to comment.