diff --git a/_notebooks/help-system/game-over/2025-01-08-game_over-coding.ipynb b/_notebooks/help-system/game-over/2025-01-08-game_over-coding.ipynb index 8fcd4639..19b38812 100644 --- a/_notebooks/help-system/game-over/2025-01-08-game_over-coding.ipynb +++ b/_notebooks/help-system/game-over/2025-01-08-game_over-coding.ipynb @@ -145,6 +145,17 @@ "```" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Changes/Ideas\n", + "\n", + "Instead of checking the level transition every frame you can optimize this so it will only run when reaching the finish\n", + "of a level allowing for less code being ran and allowing future changes to how levels end giving coders room to\n", + "add requirements needed to finish levels" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/_notebooks/help-system/game-over/2025-01-08-game_over-intro.ipynb b/_notebooks/help-system/game-over/2025-01-08-game_over-intro.ipynb index b6f58f8c..bb621f10 100644 --- a/_notebooks/help-system/game-over/2025-01-08-game_over-intro.ipynb +++ b/_notebooks/help-system/game-over/2025-01-08-game_over-intro.ipynb @@ -29,20 +29,20 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "vscode": { - "languageId": "markdown" + "languageId": "javascript" } }, - "outputs": [], "source": [ "### Summary of GameSetterEnd.js\n", "\n", "The `GameSetterEnd.js` file handles the end-of-game logic, including transitioning between levels and resetting the game environment.\n", "\n", - "- **Transitioning between levels**: This involves destroying current game objects and loading new ones. The transition process is managed by the `transitionToLevel` function.\n", + "- **Transitioning between levels**: This involves destroying current game objects and loading new ones. The \n", + "transition process is managed by the `transitionToLevel` function.\n", + "```js\n", "\n", " async transitionToLevel(newLevel) {\n", " this.inTransition = true;\n", @@ -65,11 +65,11 @@ "\n", " this.inTransition = false;\n", " }\n", - "\n", + "```\n", " The above code sets the game in transition mode, destroys existing game objects to clear the current level, checks if the new level is different from the current one, clears any claimed coins, loads the new level, updates the current level, updates properties like the invert setting, triggers a resize event to redraw canvas elements, and then ends the transition mode.\n", "\n", "- **Resetting game variables**: This prepares the game for a new session by resetting variables and properties. The reset process is managed by checking the completion status of the current level.\n", - "\n", + "```js\n", " if (currentLevel) {\n", " // run the isComplete callback function\n", " if (currentLevel.isComplete && currentLevel.isComplete()) {\n", @@ -81,7 +81,7 @@ " } \n", " }\n", " }\n", - "\n", + "```\n", " The above code checks if the current level is complete by running the `isComplete` callback function. If the current level is complete and the next level index is within bounds, it transitions to the next level using the `transitionToLevel` function.\n" ] }, diff --git a/assets/js/platformer/Character.js b/assets/js/platformer/Character.js index 7bc6b7c8..3a964a31 100644 --- a/assets/js/platformer/Character.js +++ b/assets/js/platformer/Character.js @@ -169,4 +169,5 @@ class Character extends GameObject { } -export default Character; \ No newline at end of file +export default Character; + diff --git a/assets/js/platformer/GameLevel.js b/assets/js/platformer/GameLevel.js index 7a0f6e44..b0a6c692 100644 --- a/assets/js/platformer/GameLevel.js +++ b/assets/js/platformer/GameLevel.js @@ -26,6 +26,8 @@ class GameLevel { // The gameObjects property is an array of the game objects for this level. this.gameObjects = this.levelObjects?.objects || []; // Each GameLevel instance is stored in the GameEnv.levels array. + this.subLvl = levelObject?.subLevel; + GameEnv.levels.push(this); } diff --git a/assets/js/platformer/GameSetterGreece.js b/assets/js/platformer/GameSetterGreece.js index 897f7ee3..98ffd854 100644 --- a/assets/js/platformer/GameSetterGreece.js +++ b/assets/js/platformer/GameSetterGreece.js @@ -42,7 +42,7 @@ const assets = { grass: { src: "/images/platformer/platforms/grass.png" }, lava: { src: "/images/platformer/platforms/lava.jpg" }, sandstone: { src: "/images/platformer/platforms/sandstone.png" }, - island: { src: "/images/platformer/platforms/island.png" }, + island: { src: "/images/platformer/platforms/islandsand2.png" }, }, backgrounds: { greece: { src: "/images/platformer/backgrounds/fort_platformer.png" }, diff --git a/assets/js/platformer/GameSetterGreeceMini.js b/assets/js/platformer/GameSetterGreeceMini.js index 550d910f..5b4137d1 100644 --- a/assets/js/platformer/GameSetterGreeceMini.js +++ b/assets/js/platformer/GameSetterGreeceMini.js @@ -145,7 +145,7 @@ const assets = { const GameSetterGreeceMini = { tag: 'Greece Lava', assets: assets, - objects: objects + objects: objects, }; export default GameSetterGreeceMini; \ No newline at end of file diff --git a/assets/js/platformer/GameSetup.js b/assets/js/platformer/GameSetup.js index 879e1a39..629b1049 100644 --- a/assets/js/platformer/GameSetup.js +++ b/assets/js/platformer/GameSetup.js @@ -220,26 +220,26 @@ const GameSetup = { // Initialize Game Levels - function GameLevelSetup(GameSetter, path, callback, passive = false) { + function GameLevelSetup(GameSetter, path, callback, subLevel = false, passive = false) { var gameObjects = new GameSet(GameSetter.assets, GameSetter.objects, path); - return new GameLevel({ tag: GameSetter.tag, callback: callback, objects: gameObjects.getGameObjects(), passive: passive }); + return new GameLevel({ tag: GameSetter.tag, callback: callback, objects: gameObjects.getGameObjects(), subLevel: subLevel, passive: passive }); } // Start Game - GameLevelSetup(GameSetterStart, this.path, this.homeScreenCallback, true); + GameLevelSetup(GameSetterStart, this.path, this.homeScreenCallback, false, true); // Game Levels added to the Game ... GameLevelSetup(GameSetterHills, this.path, this.playerOffScreenCallBack); GameLevelSetup(GameSetterGreece, this.path, this.playerOffScreenCallBack); - GameLevelSetup(GameSetterGreeceMini, this.path, this.playerOffScreenCallBack); + GameLevelSetup(GameSetterGreeceMini, this.path, this.playerOffScreenCallBack,true); GameLevelSetup(GameSetterWater, this.path, this.playerOffScreenCallBack); GameLevelSetup(GameSetterQuidditch, this.path, this.playerOffScreenCallBack); - GameLevelSetup(GameSetterHogwarts, this.path, this.playerOffScreenCallBack); + GameLevelSetup(GameSetterHogwarts, this.path, this.playerOffScreenCallBack, true); GameLevelSetup(GameSetterWinter, this.path, this.playerOffScreenCallBack); GameLevelSetup(GameSetterWinterIce, this.path, this.playerOffScreenCallBack); GameLevelSetup(GameSetterSkibidi, this.path, this.playerOffScreenCallBack); GameLevelSetup(GameSetterBoss, this.path, this.playerOffScreenCallBack); // End Game - GameLevelSetup(GameSetterEnd, this.path, this.gameOverCallBack, true); + GameLevelSetup(GameSetterEnd, this.path, this.gameOverCallBack, false, true); } } diff --git a/assets/js/platformer/Lava.js b/assets/js/platformer/Lava.js index 78d3ef3e..b8311ec6 100644 --- a/assets/js/platformer/Lava.js +++ b/assets/js/platformer/Lava.js @@ -8,7 +8,7 @@ export class Lava extends GameObject { this.islandX = xPercentage * GameEnv.innerWidth; this.islandY = yPercentage * GameEnv.innerHeight; // Initialize islandY with a pixel value this.initialDelay = 5000; // 5 seconds delay - this.risingSpeed = 200; // Adjust the rising speed as needed + this.risingSpeed = 0; // Adjust the rising speed as needed this.lastUpdateTime = Date.now(); // Initialize last update time to current time this.timeUntilRise = this.initialDelay; // Time until lava rises this.timerElement = document.createElement('div'); // Create a timer element diff --git a/assets/js/platformer/PlayerGreece.js b/assets/js/platformer/PlayerGreece.js index c00200d8..24aaa9b0 100644 --- a/assets/js/platformer/PlayerGreece.js +++ b/assets/js/platformer/PlayerGreece.js @@ -39,11 +39,11 @@ export class PlayerGreece extends PlayerBase { updateJump() { let jumpHeightFactor; if (GameEnv.difficulty === "easy") { - jumpHeightFactor = 0.45; + jumpHeightFactor = 0.25; } else if (GameEnv.difficulty === "normal") { - jumpHeightFactor = 0.35; + jumpHeightFactor = 0.20; } else { - jumpHeightFactor = 0.30; + jumpHeightFactor = 0.15; } this.setY(this.y - (this.bottom * jumpHeightFactor)); } @@ -106,24 +106,18 @@ export class PlayerGreece extends PlayerBase { break; case "finishline": console.log("finish line checks") - console.log(GameEnv.gameObjects) - var collectedCoin - if (collectedCoin == false){ - for (let obj of GameEnv.gameObjects) { - console.log(obj.jsonifiedElement.id) + for (let obj of GameEnv.gameObjects) { if (obj.jsonifiedElement.id === "coin") { - collectedCoin = false console.log("coin not collected not advancing to next lvl") return; } } - } - collectedCoin = true console.log("player has item to exit lvl") + //FindNextLevelID(this.jsonifiedElement.tag)//the input is the current level tag + // Transition to the next level when touching the flag - const index = GameEnv.levels.findIndex(level => level.tag === "Water") + const index = FindNextLevelID(this.jsonifiedElement.tag)//the input is the current level tag GameControl.transitionToLevel(GameEnv.levels[index]); - //above code were you transition levels is broken and crashes the game when ran break; case "cerberus": // Note: Goomba.js and Player.js could be refactored // 1. Player jumps on goomba, interaction with Goomba.js @@ -199,4 +193,31 @@ export class PlayerGreece extends PlayerBase { } } } + + +function FindNextLevelID(currentLvlTag) { + let nextLvlIndex = 1;// this is a default value if the level tag is not found + let NextLvl = null + for(let i = 0; i < GameEnv.levels.length; i++){ + if(GameEnv.levels[i].tag == currentLvlTag){ + function checkLoop(){ + if(i + 1 < GameEnv.levels.length){ + NextLvl = GameEnv.levels[i + 1]; + //console.log(NextLvl) + //console.log(NextLvl.subLvl) + + if(NextLvl.subLvl == false){ + nextLvlIndex = i + 1; + }else{ + i++; + checkLoop() + } + } + } + checkLoop() + } + } + return nextLvlIndex //retuens the index of the next level wich is a number value +} + export default PlayerGreece; \ No newline at end of file diff --git a/images/platformer/platforms/islandsand2.png b/images/platformer/platforms/islandsand2.png new file mode 100644 index 00000000..d6ecd62e Binary files /dev/null and b/images/platformer/platforms/islandsand2.png differ