Skip to content
11 changes: 11 additions & 0 deletions _notebooks/help-system/game-over/2025-01-08-game_over-coding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
]
},
Expand Down
3 changes: 2 additions & 1 deletion assets/js/platformer/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@ class Character extends GameObject {

}

export default Character;
export default Character;

2 changes: 2 additions & 0 deletions assets/js/platformer/GameLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion assets/js/platformer/GameSetterGreece.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
2 changes: 1 addition & 1 deletion assets/js/platformer/GameSetterGreeceMini.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const assets = {
const GameSetterGreeceMini = {
tag: 'Greece Lava',
assets: assets,
objects: objects
objects: objects,
};

export default GameSetterGreeceMini;
12 changes: 6 additions & 6 deletions assets/js/platformer/GameSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/platformer/Lava.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 34 additions & 13 deletions assets/js/platformer/PlayerGreece.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Binary file added images/platformer/platforms/islandsand2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.