/* COMP 125 Lab 12: Start-Play-GameOver
Modify this sketch so that clicking the mouse will step you through three different screens in a sequence (start, play, gameOver)
You will need to add some if() statements to the mousePressed() function to control navigation.
Also, you will need to add some simple graphics (a background, a simple picture, some text ...) to each screen function (scroll down)
*/
// boolean "flag" variables (global) var start = true; // the game will begin on the "start" screen var play = false; var gameOver = false;
clickX = 0; // track the mouse click location clickY = 0;
function setup() { createCanvas(640, 480); }
function draw() { //Leave this draw() function alone if (start){
// only if true AND the other flags are false
startScreen(); } else if (play){
// only if true AND the other flags are false
playScreen(); } else if (gameOver){
// only if true AND the other flags are false
gameOverScreen(); } }
function mousePressed(){ // don't change this one either! clickX = mouseX; // grab the X location of the mouse clickY = mouseY; // grab the Y location of the mouse }
function startScreen(){ // 1. add code here to display something on screen background(50); textSize(20); fill(255, 0, 0); text('To begin playing, click mouse',60,80); // 2. add a conditional statement that switches to the play screen
/******* if you want to use the mouse click to control things, you can check the location of clickX and clickY against another location, e.g.: if(dist(clickX, clickY, width/2, height/2) < 100){
//set the start, play, and gameOver flags to EITHER true or false
// reset clickX and clickY to 0 }
*******/ }
function playScreen(){ // 1. add code here to display something on screen // 2. add a conditional statement to move to game over state }
function gameOverScreen(){ // 1. add code here to display something on screen // 2. add a conditional statement to move back to either play or start
}
добавить логики ветвления c к функции mousePressed (), чтобы щелчки мыши переводили холст с одного экрана на другой. Подумайте, как использовать операторы if () и else if () и те логические «флаговые» переменные в верхней части эскиза (8 баллов). Как мне это сделать?