/////////////////////////////////////////////// // 40 Seconds // // By:Wun Richard Hui // // 991 444 823 // /////////////////////////////////////////////// // Player clicks on as many squares // // as they can in 40seconds. // /////////////////////////////////////////////// /////////////////////////// //Random object variables// /////////////////////////// int rectX= 200; int rectY=200; /////////////////////////// //Random color variables // /////////////////////////// int randomR=200; int randomG=0; int randomB=20; /////////////////////////// // Score variable // /////////////////////////// int score = 1; /////////////////////////// // Time Variable // /////////////////////////// float time = 40; ////////////////////////////////////////////// // Basic setup // ////////////////////////////////////////////// // No cursor, larger canvas // ////////////////////////////////////////////// void setup() { noCursor(); size (600, 600); rectMode(CENTER); noStroke(); } void draw() { drawBkgd(); drawTarget(); drawRound(); drawPlayer(); title(); timer(); } ////////////////////////////////////////////// // Timer in the bottom // ////////////////////////////////////////////// void timer() { ////timer bar////////////////////////////////////////////////// fill(0, 80); rect( width/2, height, time*15, height/10); ////timer text///////////////////////////////////////////////// text(time, width/2.5, height); time -= (0.016666); ////gameover trigger/////////////////////////////////////////// if (time<=0.09) { gameOver(); } } ////////////////////////////////////////////// // GameOver Scene // ////////////////////////////////////////////// void gameOver() { //////////Gameover Screen Art////////////////////////////////// fill(0); rect(width/2, height/2, width, height); fill(randomB, randomG, randomR); rect(width/2, height/3, width, height/2); fill(randomB, randomG, randomR); rect(width/2, height, width, height/2); ////////////Score text///////////////////////////////////////// fill(randomR, randomB, randomG); textSize(50); text("Your Score: "+(score-1), width/3, height/(1.4)); } /////////////////////////////////////////////////////////////// /////////////////////////////////////////////// // Game UI // /////////////////////////////////////////////// void drawRound() { //Top bar////////////////////////////////////////////////////// fill(200, 90); rect(0, 0, width*2, height/5); //Round text/////////////////////////////////////////////////// fill(randomB, randomR, randomG); textSize(40); text ("ROUND "+(score-1), 20, 40); } /////////////////////////////////////////////// // Game Object // /////////////////////////////////////////////// void drawTarget() { fill(randomG, randomB, randomR); ///Target grows smaller as round increase/////////////////////// rect(rectX, rectY, width/(score), height/(score)); } /////////////////////////////////////////////// // Player Interaction // /////////////////////////////////////////////// void mousePressed() { if (mouseX<rectX+width/(score) && mouseX>rectX-width/(score)&& mouseY<rectY+width/(score) && mouseY>rectY-width/(score)) { score= score+1; //Move the object when player clicks on it////////////////////// rectX= (int) random(1, 11)*50; rectY= (int) random(1, 11)*50; //Give new colors when player clicks on it////////////////////// randomR = (int) random (0, 255); randomG = (int) random (0, 255); randomB = (int) random (0, 255); } } //////////////////////////////////////////////// // Game Instructions // //////////////////////////////////////////////// void title() { fill(255); text("Click the Square!", (width/3)*score, (height-50)*score); } //////////////////////////////////////////////// // Background // //////////////////////////////////////////////// void drawBkgd() { fill(randomR, randomG, randomB); rect(width/2, height/2, 600, 600); } //////////////////////////////////////////////// // Player // //////////////////////////////////////////////// void drawPlayer() { fill(randomG, randomB, randomR); rect(mouseX, mouseY, 20, 20); } //////////////////////////////////////////////// ////////////////////END///////////////////////// //////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////// // References // ///////////////////////////////////////////////////////////////////////////////////////////////// //Score Count // //http://www-acad.sheridanc.on.ca/PROG14998/lab-02/lab_02_62/index.html // //mouse click collision detection // //http://www-acad.sheridanc.on.ca/PROG14998/2015/interactive-toy/interactive_toy_18/index.html // //Timer // //http://www-acad.sheridanc.on.ca/PROG14998/lab-02/lab_02_20/index.html // /////////////////////////////////////////////////////////////////////////////////////////////////