xxxxxxxxxx
178
// 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 captions = [];
let num = 0;
let buttonX = 500;
let buttonY = 400;
// let distanceToButton = 0.0;
let gameState = "START";
let score = 0;
let bgHue = 0;
let alp = 0;
// let bg;
// let bgHue = 0;
function preload(){
for (let i = 0; i < 5; i++){
img[i]=
loadImage("data/merlinDog"+ i + ".png");
captions = loadStrings('data/captions.txt')
}
}
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();
}
// if(mouseIsPressed) {
// gameState = "GAMEON";
// }
}
function start() {
textAlign(CENTER);
textFont('Times New Roman');
fill('white');
textSize(25)
text("Frame Count: " + frameCount, width/2,75);
textSize(30)
text("SCORE: " + score,width/2,150);
// text("START", width/2,150);
// textSize(30);
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(25)
text("Frame Count: " + frameCount, width/2,75);
textSize(30)
text("SCORE: " + score,width/2,150);
fill(255, alp);
text(captions[num], width/2, height/2);
// text("GameState: " + gameState, width/2,100);
////
image(img[num],buttonX, buttonY, width/2, height/2)
//tint (bgHue,255 )
// dist(buttonX,buttonY,mouseX,mouseY);
// if(distanceToButton <100){ // moves the button when true
// if(mouse){
// }
if(frameCount>=1000){ // ends the game when this is true
gameState = "GAMEOVER";
}
// function mousePressed(){
// //when mousePressed, a random image appears.
// num = floor(random(3));
}
function gameOver(){
background(141, 60, 68);
fill('white');
text("Frame Count: " + frameCount, width/2,75);
textSize(30)
text("SCORE: " + score,width/2,150);
// textSize(16);
// text("SCORE: " + score,width/2,20);
// text("Frame Count: " + frameCount, width/2,60);
// text("GameState: " + gameState, width/2,100);
textSize(50);
text("You Did It!", width/2,height/2);
textSize(30)
text("Play Again!", width/2,height/1.5);
if(mouseIsPressed){
frameCount = 0;
gameState = "START";
}
}
function mouseClicked(){
if (gameState == "GAMEON"){
buttonX = random(width);
buttonY = random(height);
score += 1;
num = floor(random(5));
if (alp == 0){
alp = 100;
}
}
}