xxxxxxxxxx
214
let gameState = "start";
var clicks = 0;
var currentDollars = 0;
var totalDollars = 0;
var countButtonClicks = 0;
circleWidth = 20;
circleHeight = 25;
let cloud1;
let cloud2;
function preload() {
instructionsFont = loadFont("beanbagFont.ttf");
gameFont = loadFont("gemunuLibreFont.ttf");
popSound = loadSound("poppingSound.wav");
collectSound = loadSound("collect.mp3");
gamePic = loadImage("clouds.jpg");
endPic = loadImage("endBackground.jpg");
}
function setup() {
createCanvas(windowWidth, windowHeight);
cloud1 = new Cloud(10, 120);
cloud2 = new Cloud(240, 150);
inflateButton = createButton("INFLATE");
collectButton = createButton("COLLECT");
replayButton = createButton("REPLAY");
inflateButton.style("color:orange");
collectButton.style("color:orange");
inflateButton.position(250, 400);
inflateButton.mousePressed(inflate);
collectButton.position(350, 400);
collectButton.mousePressed(collect);
replayButton.position(250, 250);
replayButton.hide();
inflateButton.hide();
collectButton.hide();
restartGame();
// if (restartGame() == "true") {
// button = createButton("inflate");
// button.position(100, 100);
// button.mousePressed(inflate);
// button = createButton("collect");
// button.position(100, 150);
// button.mousePressed(collect);
// }
}
function draw() {
// background(230);
// ellipse(width / 2, 200, circleWidth, circleHeight);
// updateEarned();
// if (countButtonClicks > 8) {
// background(170);
// text("You have earned $" + totalDollars, 20, 20);
// }
if (gameState == "start") {
drawInstructions();
} else if (gameState == "playing") {
drawGame();
} else if (gameState == "end") {
drawEndScreen();
}
}
function drawGame() {
background(188, 220, 239);
//image(gamePic, 0, 0, windowWidth, windowHeight);
cloud1.moveX();
cloud1.display();
cloud2.moveX();
cloud2.display();
noFill();
//stroke("black");
fill(250, 237, 153);
ellipse(width / 2, 250, circleWidth, circleHeight);
updateEarned();
replayButton.hide();
inflateButton.show();
collectButton.show();
if (countButtonClicks > 8) {
gameState = "end";
collectButton.hide();
inflateButton.hide();
}
}
function drawEndScreen() {
background(190);
image(endPic, 0, 0, windowWidth, windowHeight);
textSize(16);
text("You have earned $" + totalDollars, 250, 200);
replayButton.show();
replayButton.position(280, 280);
replayButton.mousePressed(function () {
gameState = "start";
clicks = 0;
currentDollars = 0;
totalDollars = 0;
countButtonClicks = 0;
countButtonClicks = 0;
});
}
function inflate() {
circleWidth += 10;
circleHeight += 15;
clicks++;
currentDollars = currentDollars + 1.75;
if (circleWidth > random(50, 130)) {
popSound.play();
circleWidth = 0;
circleHeight = 0;
currentDollars = 0;
clicks = 0;
}
}
function collect() {
collectSound.play();
circleWidth = 20;
circleHeight = 25;
clicks = 0;
totalDollars = currentDollars + totalDollars;
currentDollars = 0;
countButtonClicks++;
}
function updateEarned() {
stroke('black');
fill('black');
textFont(gameFont);
textSize(16);
text("Total Earned = $" + totalDollars, 20, 20);
text("Current Earned = $" + currentDollars, 20, 45);
text("Total Pumps = " + clicks, 20, 70);
}
function drawInstructions() {
background(188, 220, 239);
let instructions =
"On the screen, you will be presented with an inflatable balloon. To inflate it, press the “Inflate” button. The further you manage to inflate the balloon without it bursting, the more $ you will earn. You can click “Collect” to bank the money at any stage. However, take care to not over-inflate balloons to the point of bursting. Every time you burst a balloon, you will receive no money for that particular balloon. There are 8 balloons to get through, all with varying burst points. This means that different balloons will burst at different stages, so you must tackle each balloon differently.";
textFont(instructionsFont);
textSize(20);
text("Instructions", 250, 30);
textSize(14);
textFont("Georgia");
textLeading(30);
text(instructions, 30, 60, 550, 500);
text("Click on the screen to begin!", 230, 350);
}
function mousePressed() {
print(gameState);
if (gameState == "start") {
gameState = "playing";
}
// else if (gameState == "playing") {
// gameState = "end";
// } else if (gameState == "end") {
// restartGame();
// }
return false;
}
function restartGame() {
gameState = "start";
}
class Cloud {
constructor(startX, startY) {
this.x = startX;
this.y = startY;
this.colour = color(400, 400, 400);
}
moveX() {
this.x += 1;
if (this.x > width) {
this.x = 0;
}
}
display() {
noStroke();
fill(this.colour);
ellipse(this.x, this.y, 100, 50);
ellipse(this.x + 50, this.y + 20, 100, 50);
ellipse(this.x - 40, this.y + 15, 100, 50);
}
}