xxxxxxxxxx
121
// let img;
// // Load the image.
// function preload(){
// img = loadImage('merlinDog0.png');
// }
// function setup() {
// createCanvas(windowWidth, windowWidth);
// }
// function draw(){
// //background(50);
// // Draw the image.
// image(img, 0, 0);
// }
let img = [];
let num = 0;
let buttonX = 500;
let buttonY = 400;
let distanceToButton = 0.0;
let gameState = "START";
let score = 0;
let bgHue = 0;
// let bg;
// let bgHue = 0;
function preload() {
for (let i = 0; i < 3; i++) {
img[i] = loadImage("data/merlinDog" + i + ".png");
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
// mousePressed
// colorMode(HSB, 360, 100, 100, 100);
colorMode(HSL);
}
function draw() {
background(bgHue + 267, 1000, 50);
// background(bgHue, 100, 100, 10);
// tint(bgHue, 100, 50, 10);
imageMode(CENTER);
// image()
// image(bg, width/2, height/2, bg.width, bg.height, 0, 0, bg.width, bg.height)
//start game
if (gameState == "START") {
start();
}
if (gameState == "GAMEON") {
gameOn();
}
if (gameState == "GAMEOVER") {
gameOver();
}
}
function start() {
textAlign(CENTER);
textFont("Times New Roman");
fill("white");
textSize(16);
text("SCORE: " + score, width / 2, 20);
text("Frame Count: " + frameCount, width / 2, 60);
text("GameState: " + gameState, width / 2, 100);
textSize(22);
textFont("Bold");
text("Can you keep up with Merlin The Magician?", width / 2, height / 2);
text("Click to find out!", width / 2, height / 1.75);
if (mouseIsPressed) {
gameState = "GAMEON";
}
} // end start
function gameOn() {
// background(267, 100, 50);
textFont("Courier New" + "Bold");
fill("white");
textSize(16);
text("SCORE: " + score, width / 2, 20);
text("Frame Count: " + frameCount, width / 2, 60);
text("GameState: " + gameState, width / 2, 100);
image(img[4], buttonX, buttonY, width / 2, height / 2);
if (mouseIsPressed) {
buttonX = random(width);
buttonY = random(height);
score += 1;
num = floor(random(5));
}
if (frameCount >= 1000) {
// ends the game when this is true
gameState = "GAMEOVER";
}
}
function gameOver() {
background(353, 94, 73);
fill("white");
textSize(16);
text("SCORE: " + score, width / 2, 20);
text("Frame Count: " + frameCount, width / 2, 60);
text("GameState: " + gameState, width / 2, 100);
text("GAME OVER", width / 2, height / 2);
text("Try Again!", width / 2, height / 1.5);
if (mouseIsPressed) {
frameCount = 0;
gameState = "START";
}
}