xxxxxxxxxx
62
//=============================================GAME FUNCTIONS============================================
//Global Variables:
let platforms = [];
let Hunger = 300;
//========================================================================================================
function startGame() {
image(Game_BG, width/2, height/2);
drawPlatforms();
drawHungerBar();
fill("white");
text(mouseX+","+mouseY, width/2, 50);
}
//========================================================================================================
//This function draws all the necessary platforms on the Game Screen for Luffy to hop around:
function drawPlatforms() {
//Borders
new Platform(0, 0, width, 10);
new Platform(0, 0, 10, height);
new Platform(0, height-10, width, 10);
new Platform(width-10, 0, 10, height);
//Luffy's Platforms (in order from bottom to top, left to right) - in total 8 platforms
//Incrementing height of 115 pixels
append(platforms, new Platform(0, 675, 220, 10));
append(platforms, new Platform(795, 560, -150, 10));
append(platforms, new Platform(275, 560, 250, 10));
append(platforms, new Platform(0, 445, 200, 10));
append(platforms, new Platform(275, 360, 150, 10));
append(platforms, new Platform(490, 245, 130, 10));
append(platforms, new Platform(0, 245, 175, 10));
append(platforms, new Platform(795, 130, -100, 10));
}
//========================================================================================================
//This function draws Luffy's Depleting Hunger Bar:
function drawHungerBar() {
// print(Hunger);
//Hunger Bar Background
fill("yellow");
rect(20, 20, 300, 25, 4);
//Luffy's Hunger Meter:
fill("red");
rect(20, 20, Hunger, 25, 4);
//Since the depletion rate doesn't let Hunger = 0 exactly, if it reaches somewhere in this range of [0, 0.4) to account for all difficulties, then Hunger is absorbed to 0 and the user loses.
if(Hunger >= 0 && Hunger < 0.4) {
Hunger = 0;
text("GAMEOVER", width/2, height/2);
//Will edit this in the future but for now this will do.
//Maybe change screens to lose screen!
}
else {
Hunger = Hunger - (0.1*Difficulty);
}
}