앞서나가는 사냥꾼님의 이글루입니다

kshpbo830.egloos.com

포토로그



2019_1 Interactive Video Week 16_FINAL












This is a kind of sorting game. The player has to sort objects with arrow key according to the recipe. 
There are three stages, and they have each rule and recipe. 
The player send ingredients included in the recipe to the bowl with left key, and inedible things to the trash can with right key. Also, from stage 2, new rule will be added. If the object is edible, but unnecessary, the player should send it to box with down arrow key.

There is a time limit, so player should hurry to do tasks. If the player exceeds the time, or have three mistakes, game will be over. When the player gets a certain score in time, player wins.


code:

PImage background;
PImage clock;
PImage lifeImg;
PImage O;
PImage X;
PImage ui;
PImage ui2;
PImage ready;
PImage start;
PImage stageClear;
PImage gameOver;
PImage menu_background;
PImage title;
PImage stage1_icon;
PImage stage2_icon;
PImage stage3_icon;
PImage againbutton;
PImage againbutton_pushed;
PImage background_stage1;
PImage result;
PImage result_clear;
PImage result_fail;
PImage selectbutton;
PImage selectbutton_pushed;
PImage startbutton;
PImage startbutton_pushed;
PImage howtoplay1;
PImage howtoplay2;
PImage nextbutton;
PImage nextbutton_pushed;
PImage recipe;
PImage menuback;
PImage menuback_pushed;
PImage backbutton;
PImage backbutton_pushed;

PImage[] objectList = new PImage[26];

int[] stage1_bowlList = {0, 1, 6, 7, 8, 9};
int[] stage1_rotList = {4, 5, 12, 13, 16, 17};

int[] stage2_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage2_rotList = {4, 5, 12, 13, 14, 15, 16, 17};
int[] stage2_boxList = {2, 3, 18, 19, 20, 21, 22, 23};

int[] stage3_bowlList = {0, 6, 7, 8, 24, 19, 11};
int[] stage3_rotList = {4, 5, 12, 13, 14, 15, 16, 17, 25};
int[] stage3_boxList = {1, 2, 3, 9, 10, 18, 20, 21, 22, 23};

int left = 30;
int score = 0;
int life = 3; 
int time = 0; 

int answer;
int bowlObject;
int rotObject;
int boxObject;

int bowlNum = 5; 
int rotNum = 5;
int boxNum = 5;

float stage = 0;
float mode = 0;
/* 
 mode 0: title
 mode 1: menu
 mode 2.1: level 1
 mode 2.2: level 2
 mode 2.3: level 3
 mode 3.1 : result-clear
 mode 3.2 : result-fail
 */

float clockRotate = 0; 
float objectY = 0;
float objectX = 640;
float shadow = 300;
float readyY = -3000;
float startY = -3000;
float gameOverY = -3000;
float stageClearY = -3000;
float timeEnd = 0;

float check = 0; // 0:none, 1:correct, 2:incorrect

boolean game = false;
boolean howtoplay = true;
boolean showRecipe = false;
boolean gameEnd = false;

PFont font1;

void setup() {
  imageMode(CENTER);
  size(1280, 720);
  background = loadImage("background.png");
  clock = loadImage("clock.png");
  lifeImg = loadImage("life.png");
  ui = loadImage("ui.png");
  ui2 = loadImage("ui2.png");
  O = loadImage("O.png");
  X = loadImage("X.png");
  ready = loadImage("ready.png");
  start = loadImage("start.png");
  gameOver = loadImage("gameover.png");
  stageClear = loadImage("stageclear.png");
  menu_background = loadImage("menu.png");
  title = loadImage("title.png");
  stage1_icon = loadImage("stage1.png");
  stage2_icon = loadImage("stage2.png");
  stage3_icon = loadImage("stage3.png");
  againbutton = loadImage("againbutton.png");
  againbutton_pushed = loadImage("againbutton_pushed.png");
  background_stage1 = loadImage("background_stage1.png");
  result = loadImage("result.png");
  result_clear = loadImage("result_clear.png");
  result_fail = loadImage("result_fail.png");
  selectbutton = loadImage("selectbutton.png");
  selectbutton_pushed = loadImage("selectbutton_pushed.png");
  startbutton = loadImage("startbutton.png");
  startbutton_pushed = loadImage("startbutton_pushed.png");
  howtoplay1 = loadImage("howtoplay1.png");
  howtoplay2 = loadImage("howtoplay2.png");
  nextbutton = loadImage("nextbutton.png");
  nextbutton_pushed = loadImage("nextbutton_pushed.png");
  recipe = loadImage("recipe.png");
  menuback = loadImage("menuback.png");
  menuback_pushed = loadImage("menuback_pushed.png");
  backbutton = loadImage("backbutton.png");
  backbutton_pushed = loadImage("backbutton_pushed.png");

  for (int i=0; i<26; i++) {
    String objectlist = (i) + ".png";
    objectList[i] = loadImage(objectlist);
  }

  font1 = loadFont("NanumSquareOTFR-48.vlw");
  textFont(font1, 48);

  answer = int(random(2)); //choose answer 0bowl 1rot 2box
  bowlObject = int(random(bowlNum)); //choose object
  rotObject = int(random(rotNum));
  boxObject = int(random(boxNum));
}

void draw() {
  imageMode(CENTER);

  //-------title-------------------------
  if (mode == 0) {
    image(title, width/2, height/2);

    fill(255);
    image(startbutton, width/1.32, height/1.27);

    if (mousePressed) {
      if (mouseX>width/1.64 && mouseX<width/1.1 && mouseY>height/1.41 && mouseY<height/1.16) {
        image(startbutton_pushed, width/1.32, height/1.27);
      }
    }
  }

  //------------------------menu-------------------
  if (mode == 1) { //menu
    image(menu_background, width/2, height/2);

    image(stage1_icon, width/4.5, height/2.05);
    image(stage2_icon, width/2, height/2);
    image(stage3_icon, width/1.28, height/2);

    if (mouseY>height/3 && mouseY<height/1.5) {
      if (mouseX>width/7 && mouseX<width/3.3) { //stage 1 icon
        pushMatrix(); //mouseover effect
        translate(width/4.5, height/2.05);
        scale(1.2);
        image(stage1_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage2_icon, width/2, height/2);
          image(stage3_icon, width/1.28, height/2);

          pushMatrix(); //mouse click effect
          translate(width/4.5, height/2.05);
          scale(0.95);
          image(stage1_icon, 0, 0);
          popMatrix();
        }
      } else if (mouseX>width/2.4 && mouseX<width/1.7) { //stage 2 icon
        pushMatrix(); //mouseover effect
        translate(width/2, height/2);
        scale(1.2);
        image(stage2_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage1_icon, width/4.5, height/2.05);
          image(stage3_icon, width/1.28, height/2);

          pushMatrix(); //mouse click effect
          translate(width/2, height/2);
          scale(0.95);
          image(stage2_icon, 0, 0);
          popMatrix();
        }
      } else if (mouseX>width/1.45 && mouseX<width/1.15) { //stage 3 icon
        pushMatrix(); //mouseover effect
        translate(width/1.28, height/2);
        scale(1.2);
        image(stage3_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage1_icon, width/4.5, height/2.05);
          image(stage2_icon, width/2, height/2);

          pushMatrix(); //mouse click effect
          translate(width/1.28, height/2);
          scale(0.95);
          image(stage3_icon, 0, 0);
          popMatrix();
        }
      }
    }
    image(menuback, width/1.04, height/14); //button: back to title
    if (mousePressed) {
      if (mouseX>width/1.075 && mouseX<width/1.007 && mouseY>height/50 && mouseY<height/8) {
        image(menuback_pushed, width/1.04, height/14);
      }
    }
  }

  //---------------game----------------

  if (mode == 2.1) {
    stage = 2.1;
    left = 25;
    bowlNum = 6;
    rotNum = 6;
    draw_stage1();
  }

  if (mode == 2.2) {
    stage = 2.2;
    left = 25;
    bowlNum = 8; 
    rotNum = 8;
    boxNum = 8;
    draw_stage2();
  }
  if (mode == 2.3) {
    stage = 2.3;
    left = 30;
    bowlNum = 7; 
    rotNum = 9;
    boxNum = 10;
    draw_stage3();
  }

  //------------result-----------------------

  if (mode>3 && mode<4) {
    if (mode<2.3) {
      howtoplay = true;
      showRecipe = false;
    } else if (mode>2.2) {
      showRecipe = true;
    }
    clockRotate = 0; 
    objectY = 0;
    objectX = 640;
    shadow = 300;
    readyY = -3000;
    startY = -3000;
    gameOverY = -3000;
    stageClearY = -3000;

    image(result, width/2, height/2);
    image(againbutton, width/1.325, height/1.28);
    image(selectbutton, width/1.325, height/1.28);
    if (mousePressed) {
      if (mouseY>height/1.39 && mouseY<height/1.19) {
        if (mouseX>width/1.65 && mouseX<width/1.34) {
          image(againbutton_pushed, width/1.325, height/1.28);
        } else if (mouseX>width/1.31 && mouseX<width/1.11) {
          image(selectbutton_pushed, width/1.325, height/1.28);
        }
      }
    }
    if (mode == 3.1) {
      image(result_clear, width/1.325, height/2.4);
    } else if (mode == 3.2) {
      image(result_fail, width/1.32, height/2.4);
    }
  }
}

void keyReleased() {
  if (mode>2 && mode<3 && game == true) {
    if (mode == 2.1) {
      if (check == 1) { //correct answer
        answer = int(random(2)); //only bowl or trash can
        bowlObject = int(random(bowlNum)); 
        rotObject = int(random(rotNum));
        objectY = 0;
        score += 1;
        check = 0;
        objectX = width/2;
        shadow = 300;
      } else if (check == 2) { //worng answer
        answer = int(random(2)); //only bowl or trash can
        bowlObject = int(random(bowlNum)); 
        rotObject = int(random(rotNum));
        objectY = 0;
        life -= 1;
        check = 0;
        objectX = width/2;
        shadow = 300;
      }
    }
    if (check == 1) { //correct answer
      answer = int(random(3));
      bowlObject = int(random(bowlNum)); 
      rotObject = int(random(rotNum));
      boxObject = int(random(boxNum));
      objectY = 0;
      score += 1;
      check = 0;
      objectX = width/2;
      shadow = 300;
    } else if (check == 2) { //worng answer
      answer = int(random(3));
      bowlObject = int(random(bowlNum)); 
      rotObject = int(random(rotNum));
      boxObject = int(random(boxNum));
      objectY = 0;
      life -= 1;
      check = 0;
      objectX = width/2;
      shadow = 300;
    }
  }

  if (score == left) {
    timeEnd = millis();
  }

  if (life == 0 || millis()-time>34000) {
    timeEnd = millis();
  }
}

void mouseReleased() {
  if (mode == 0 && mouseX>width/1.64 && mouseX<width/1.1 && mouseY>height/1.41 && mouseY<height/1.16) {
    mode = 1; //title, start button
  }

  if (mode == 1 && mouseX>width/1.075 && mouseX<width/1.007 && mouseY>height/50 && mouseY<height/8) {
    mode = 0; //menu, back to title
  }

  if (mode == 1 && mouseY>height/3 && mouseY<height/1.5) { //menu
    if (mouseX>width/7 && mouseX<width/3.3) { //to stage1
      mode = 2.1;
    } else if (mouseX>width/2.4 && mouseX<width/1.7) { //to stage2
      mode = 2.2;
    } else if (mouseX>width/1.45 && mouseX<width/1.15) { //to stage3
      mode = 2.3;

      showRecipe = true;
    }
  }

  if (mode > 2 && mode < 3) {
    if (mode > 2.2) { //stage3 
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        mode = 1;
        howtoplay = true;
      }
    }
    if (howtoplay == true) {
      if (mouseX>width/1.24 && mouseX<width/1.07 && mouseY>height/1.21 && mouseY<height/1.1) {
        howtoplay = false; //next
        showRecipe = true;
      }
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        mode = 1; //back
        howtoplay = true;
      }
    }

    if (showRecipe == true && mouseX>width/2.8 && mouseX<width/1.55 && mouseY>height/1.32 && mouseY<height/1.1) {
      showRecipe = false; //game start
      howtoplay = false;
      time = millis();
    }
    if (showRecipe == true && mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
      howtoplay = true; //back
      showRecipe = false;
    }
  }

  if (mode > 3 && mode < 4) {
    if (mouseY>height/1.39 && mouseY<height/1.19) {
      if (mouseX>width/1.65 && mouseX<width/1.34) {
        mode = stage; //try again, go to stage user just played
        if (stage == 2.3) {
          howtoplay = false;
          showRecipe = true;
        } else {
          howtoplay = true;
          showRecipe = false;
        }
      } else if (mouseX>width/1.31 && mouseX<width/1.11) {
        mode = 1; //go to menu
      }
    }
  }
}

//----------------------------------------------
//--------------------stage1---------------------
//----------------------------------------------

void draw_stage1() {
  image(background_stage1, width/2, height/2);
  image(ui, width/2, 67);
  image(clock, width/2-50, 10);
  image(ui2, width/2, 67);

  if (howtoplay == true) {
    image(howtoplay1, width/2, height/2);
    image(nextbutton, width/1.15, height/1.15);
    image(backbutton, width/7.5, height/1.15);

    if (mousePressed) {
      if (mouseX>width/1.24 && mouseX<width/1.07 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(nextbutton_pushed, width/1.15, height/1.15);
      }
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(backbutton_pushed, width/7.5, height/1.15);
      }
    }
  }

  if (showRecipe == true) {
    image(recipe, width/2, height/2);
    image(startbutton, width/2, height/1.2);
    image(backbutton, width/7.5, height/1.15);

    pushMatrix(); //show recipe
    scale(0.8);
    for (int i=0; i<6; i++) {  
      image(objectList[stage1_bowlList[i]], (width/4.5)+(205*i), height/1.6);
    }
    popMatrix();

    if (mousePressed) {
      if (mouseX>width/2.8 && mouseX<width/1.55 && mouseY>height/1.32 && mouseY<height/1.1) {
        image(startbutton_pushed, width/2, height/1.2);
      }
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(backbutton_pushed, width/7.5, height/1.15);
      }
    }
  }

  if (showRecipe == false && howtoplay == false) {
    if (game == true) {
      objectY += (height/2.3-objectY)*0.3;

      fill(157, 180, 173);
      noStroke();
      ellipse(width/2, height/1.8, shadow, 50);
      shadow += (180-shadow)*0.3;

      if (answer==0) { //bowl 
        image(objectList[stage1_bowlList[bowlObject]], objectX, objectY);   
        if (keyPressed) {
          if (keyCode == LEFT) { 
            objectX = objectX + (width/10-objectX)*0.5;
            image(O, width/2, height/2.3); 

            check = 1;
          } else if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          }
        }
      } else if (answer==1) { //rot 
        image(objectList[stage1_rotList[rotObject]], objectX, objectY);
        if (keyPressed) {
          if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(O, width/2, height/2.3);
            check = 1;
          } else if (keyCode == LEFT) {
            objectX = objectX + (width/10-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          }
        }
      }
    }

    image(ui, width/2, 67);
    pushMatrix();
    scale(0.26);
    for (int i=0; i<6; i++) {  
      image(objectList[stage1_bowlList[i]], (width/4.5)+(250*i), height/5);
    }
    popMatrix();

    if (score == left) {
      game = false;
      readyY = -3000;
      startY = -3000;
      time = millis();

      image(stageClear, width/2, stageClearY);
      stageClearY += (height/2 - stageClearY)*0.3;
      if (millis()-timeEnd>3000) {
        mode = 3.1;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
    }

    if (life == 0 || millis()-time>34000) {      
      game = false;
      readyY = -3000;
      startY = -3000;

      image(gameOver, width/2, gameOverY);
      gameOverY += (height/2 - gameOverY)*0.3;
      if (life == 0 && millis()-timeEnd>3000) {
        mode = 3.2;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
      if (millis()-time>37000){
        mode = 3.2;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
    }

    fill(255);
    text(score, width/1.51, 55);
    text(left, width/1.36, 55);

    if (mode>2 && mode <3 && game == true) {
      //text((millis()-time)/1000, 0, 50);
      clockRotate = ((millis()-time-4000)/1000)*6;
    }
    pushMatrix(); //clock
    translate(width/2, 10);
    rotate(-radians(clockRotate));
    image(clock, -50, 0);
    popMatrix();

    for (int i=0; i<life; i++) {  //life
      image(lifeImg, (width/1.19)+(75*i), 35);
    }

    //--------------------------------------------------
    image(ready, width/2, readyY);  //ready start
    if (millis()-time<2000) {
      readyY += (height/2 - readyY)*0.3;
    }

    if (millis()-time<4000 && millis()-time>2000) { 
      readyY += (3000 - readyY)*0.3;
      image(start, width/2, startY);
      startY += (height/2 - startY)*0.3;
    }
    if (millis()-time<4500 && millis()-time>4000) {
      startY += (3000 - startY)*0.3;
      game = true;
    }

    image(ui2, width/2, 67);
  }
}


//----------------------------------------------
//--------------------stage2---------------------
//----------------------------------------------

void draw_stage2() {
  image(background, width/2, height/2);
  image(ui, width/2, 67);
  image(clock, width/2-50, 10);
  image(ui2, width/2, 67);

  if (howtoplay == true) {
    image(howtoplay2, width/2, height/2);
    image(nextbutton, width/1.15, height/1.15);
    image(backbutton, width/7.5, height/1.15);

    if (mousePressed) {
      if (mouseX>width/1.24 && mouseX<width/1.07 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(nextbutton_pushed, width/1.15, height/1.15);
      }
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(backbutton_pushed, width/7.5, height/1.15);
      }
    }
  }

  if (showRecipe == true) {
    image(recipe, width/2, height/2);
    image(startbutton, width/2, height/1.2);
    image(backbutton, width/7.5, height/1.15);

    pushMatrix(); //show recipe
    scale(0.8);
    for (int i=0; i<6; i++) {  
      image(objectList[stage2_bowlList[i]], (width/4.5)+(205*i), height/1.6);
    }
    popMatrix();

    if (mousePressed) {
      if (mouseX>width/2.8 && mouseX<width/1.55 && mouseY>height/1.32 && mouseY<height/1.1) {
        image(startbutton_pushed, width/2, height/1.2);
      }
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(backbutton_pushed, width/7.5, height/1.15);
      }
    }
  }

  if (showRecipe == false && howtoplay == false) {
    if (game == true) {
      objectY += (height/2.3-objectY)*0.3;

      fill(157, 180, 173);
      noStroke();
      ellipse(width/2, height/1.8, shadow, 50);
      shadow += (180-shadow)*0.3;

      if (answer==0) { //bowl 
        image(objectList[stage2_bowlList[bowlObject]], objectX, objectY);   
        if (keyPressed) {
          if (keyCode == LEFT) { 
            objectX = objectX + (width/10-objectX)*0.5;
            image(O, width/2, height/2.3); 
            check = 1;
          } else if (keyCode == DOWN) {
            objectY = objectY + (height*1.2-objectY)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          } else if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          }
        }
      } else if (answer==1) { //rot 
        image(objectList[stage2_rotList[rotObject]], objectX, objectY);
        if (keyPressed) {
          if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(O, width/2, height/2.3);
            check = 1;
          } else if (keyCode == DOWN) {
            objectY = objectY + (height*1.2-objectY)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          } else if (keyCode == LEFT) {
            objectX = objectX + (width/10-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          }
        }
      } else if (answer==2) { //box
        image(objectList[stage2_boxList[boxObject]], objectX, objectY);
        if (keyPressed) {
          if (keyCode == DOWN) {
            objectY = objectY + (height*1.2-objectY)*0.5;
            image(O, width/2, height/2.3);
            check = 1;
          } else if (keyCode == LEFT) {     
            objectX = objectX + (width/10-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          } else if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(X, width/2, height/2.3);        
            check = 2;
          }
        }
      }
    }

    image(ui, width/2, 67);
    pushMatrix();
    scale(0.26);
    for (int i=0; i<6; i++) {  
      image(objectList[stage2_bowlList[i]], (width/4.5)+(250*i), height/5);
    }
    popMatrix();

    if (score == left) {
      game = false;
      readyY = -3000;
      startY = -3000;
      time = millis();

      image(stageClear, width/2, stageClearY);
      stageClearY += (height/2 - stageClearY)*0.3;
      if (millis()-timeEnd>3000) {
        mode = 3.1;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
    }

    if (life == 0 || millis()-time>34000) {
      game = false;
      readyY = -3000;
      startY = -3000;

      image(gameOver, width/2, gameOverY);
      gameOverY += (height/2 - gameOverY)*0.3;
      if (life == 0 && millis()-timeEnd>3000) {
        mode = 3.2;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
      if (millis()-time>37000) {
        mode = 3.2;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
    }

    fill(255);
    text(score, width/1.51, 55);
    text(left, width/1.36, 55);

    if (mode>2 && mode <3 && game == true) {
      //text((millis()-time)/1000, 0, 50);
      clockRotate = ((millis()-time-4000)/1000)*6;
    }
    pushMatrix(); //clock
    translate(width/2, 10);
    rotate(-radians(clockRotate));
    image(clock, -50, 0);
    popMatrix();

    for (int i=0; i<life; i++) {  //life
      image(lifeImg, (width/1.19)+(75*i), 35);
    }

    //--------------------------------------------------
    image(ready, width/2, readyY);  //ready start
    if (millis()-time<2000) {
      readyY += (height/2 - readyY)*0.3;
    }

    if (millis()-time<4000 && millis()-time>2000) { 
      readyY += (3000 - readyY)*0.3;
      image(start, width/2, startY);
      startY += (height/2 - startY)*0.3;
    }
    if (millis()-time<4500 && millis()-time>4000) {
      startY += (3000 - startY)*0.3;
      game = true;
    }

    image(ui2, width/2, 67);
  }
}

//----------------------------------------------
//--------------------stage3---------------------
//----------------------------------------------

void draw_stage3() {
  
  image(background, width/2, height/2);
  image(ui, width/2, 67);
  image(clock, width/2-50, 10);
  image(ui2, width/2, 67);

  howtoplay = false;

  if (showRecipe == true) {
    image(recipe, width/2, height/2);
    image(startbutton, width/2, height/1.2);
    image(backbutton, width/7.5, height/1.15);

    pushMatrix(); //show recipe
    scale(0.8);
    for (int i=0; i<6; i++) {  
      image(objectList[stage3_bowlList[i]], (width/4.9)+(220*i), height/1.6);
    }
    popMatrix();

    if (mousePressed) {
      if (mouseX>width/2.8 && mouseX<width/1.55 && mouseY>height/1.32 && mouseY<height/1.1) {
        image(startbutton_pushed, width/2, height/1.2);
      }
      if (mouseX>width/14.5 && mouseX<width/5.1 && mouseY>height/1.21 && mouseY<height/1.1) {
        image(backbutton_pushed, width/7.5, height/1.15);
      }
    }
  }

  if (showRecipe == false && howtoplay == false) {
    if (game == true) {
      objectY += (height/2.3-objectY)*0.3;

      fill(157, 180, 173);
      noStroke();
      ellipse(width/2, height/1.8, shadow, 50);
      shadow += (180-shadow)*0.3;

      if (answer==0) { //bowl 
        image(objectList[stage3_bowlList[bowlObject]], objectX, objectY);   
        if (keyPressed) {
          if (keyCode == LEFT) { 
            objectX = objectX + (width/10-objectX)*0.5;
            image(O, width/2, height/2.3); 
            check = 1;
          } else if (keyCode == DOWN) {
            objectY = objectY + (height*1.2-objectY)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          } else if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          }
        }
      } else if (answer==1) { //rot 
        image(objectList[stage3_rotList[rotObject]], objectX, objectY);
        if (keyPressed) {
          if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(O, width/2, height/2.3);
            check = 1;
          } else if (keyCode == DOWN) {
            objectY = objectY + (height*1.2-objectY)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          } else if (keyCode == LEFT) {
            objectX = objectX + (width/10-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          }
        }
      } else if (answer==2) { //box
        image(objectList[stage3_boxList[boxObject]], objectX, objectY);
        if (keyPressed) {
          if (keyCode == DOWN) {
            objectY = objectY + (height*1.2-objectY)*0.5;
            image(O, width/2, height/2.3);
            check = 1;
          } else if (keyCode == LEFT) {     
            objectX = objectX + (width/10-objectX)*0.5;
            image(X, width/2, height/2.3);
            check = 2;
          } else if (keyCode == RIGHT) {
            objectX = objectX + (width/1.1-objectX)*0.5;
            image(X, width/2, height/2.3);        
            check = 2;
          }
        }
      }
    }

    image(ui, width/2, 67);
    pushMatrix();
    scale(0.26);
    for (int i=0; i<6; i++) {  
      image(objectList[stage3_bowlList[i]], (width/4.7)+(260*i), height/5);
    }
    popMatrix();

    if (score == left) {
      game = false;
      readyY = -3000;
      startY = -3000;
      time = millis();

      image(stageClear, width/2, stageClearY);
      stageClearY += (height/2 - stageClearY)*0.3;
      if (millis()-timeEnd>3000) {
        mode = 3.1;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
    }

    if (life == 0 || millis()-time>34000) {
      game = false;
      readyY = -3000;
      startY = -3000;

      image(gameOver, width/2, gameOverY);
      gameOverY += (height/2 - gameOverY)*0.3;
      if (life == 0 && millis()-timeEnd>3000) {
        mode = 3.2;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
      if (millis()-time>37000) {
        mode = 3.2;
        score = 0;
        life = 3;
        clockRotate = 0;
      }
    }

    fill(255);
    text(score, width/1.51, 55);
    text(left, width/1.36, 55);

    if (mode>2 && mode <3 && game == true) {
      //text((millis()-time)/1000, 0, 50);
      clockRotate = ((millis()-time-4000)/1000)*6;
    }
    pushMatrix(); //clock
    translate(width/2, 10);
    rotate(-radians(clockRotate));
    image(clock, -50, 0);
    popMatrix();

    for (int i=0; i<life; i++) {  //life
      image(lifeImg, (width/1.19)+(75*i), 35);
    }

    //--------------------------------------------------
    image(ready, width/2, readyY);  //ready start
    if (millis()-time<2000) {
      readyY += (height/2 - readyY)*0.3;
    }

    if (millis()-time<4000 && millis()-time>2000) { 
      readyY += (3000 - readyY)*0.3;
      image(start, width/2, startY);
      startY += (height/2 - startY)*0.3;
    }
    if (millis()-time<4500 && millis()-time>4000) {
      startY += (3000 - startY)*0.3;
      game = true;
    }

    image(ui2, width/2, 67);
  }
}









2019_1 Interactive Video Week 14








PImage background;
PImage clock;
PImage lifeImg;
PImage O;
PImage X;
PImage ui;
PImage ui2;
PImage ready;
PImage start;
PImage stageClear;
PImage gameOver;
PImage menu_background;
PImage title;
PImage stage1_icon;
PImage stage2_icon;
PImage stage3_icon;
PImage againbutton;
PImage againbutton_pushed;
PImage background_stage1;
PImage result;
PImage result_clear;
PImage result_fail;
PImage selectbutton;
PImage selectbutton_pushed;
PImage startbutton;
PImage startbutton_pushed;


PImage[] objectList = new PImage[24];

int[] stage1_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage1_boxList = {2, 3, 18, 19, 20, 21, 22, 23};
int[] stage1_rotList = {4, 5, 12, 13, 14, 15, 16, 17};

int[] stage2_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage2_boxList = {2, 3, 18, 19, 20, 21, 22, 23};
int[] stage2_rotList = {4, 5, 12, 13, 14, 15, 16, 17};

int[] stage3_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage3_boxList = {2, 3, 18, 19, 20, 21, 22, 23};
int[] stage3_rotList = {4, 5, 12, 13, 14, 15, 16, 17};

int left = 30;
int score = 0;
int life = 3; 
int time = 0; 

int answer;
int bowlObject;
int rotObject;
int boxObject;
int bowlNum = 5; 
int rotNum = 5;
int boxNum = 5;

float stage = 0;
float mode = 0;
/* 
 mode 0: title
 mode 1: menu
 mode 2.1: level 1
 mode 2.2: level 2
 mode 2.3: level 3
 mode 3: end
 mode 3.1 : result-clear
 mode 3.2 : result-fail
 */

float clockRotate = 0; 
float objectY = 0;
float objectX = 640;
float shadow = 300;
float readyY = -3000;
float startY = -3000;
float gameOverY = -3000;
float stageClearY = -3000;

float check = 0; // 0:none, 1:correct, 2:incorrect

boolean game = false;

void setup() {
  imageMode(CENTER);
  size(1280, 720);
  background = loadImage("background.png");
  clock = loadImage("clock.png");
  lifeImg = loadImage("life.png");
  ui = loadImage("ui.png");
  ui2 = loadImage("ui2.png");
  O = loadImage("O.png");
  X = loadImage("X.png");
  ready = loadImage("ready.png");
  start = loadImage("start.png");
  gameOver = loadImage("gameover.png");
  stageClear = loadImage("stageclear.png");
  menu_background = loadImage("menu.png");
  title = loadImage("title.png");
  stage1_icon = loadImage("stage1.png");
  stage2_icon = loadImage("stage2.png");
  stage3_icon = loadImage("stage3.png");
  againbutton = loadImage("againbutton.png");
  againbutton_pushed = loadImage("againbutton_pushed.png");
  background_stage1 = loadImage("background_stage1.png");
  result = loadImage("result.png");
  result_clear = loadImage("result_clear.png");
  result_fail = loadImage("result_fail.png");
  selectbutton = loadImage("selectbutton.png");
  selectbutton_pushed = loadImage("selectbutton_pushed.png");
  startbutton = loadImage("startbutton.png");
  startbutton_pushed = loadImage("startbutton_pushed.png");


  for (int i=0; i<24; i++) {
    String objectlist = (i) + ".png";
    objectList[i] = loadImage(objectlist);
  }

  answer = int(random(2)); //choose answer 0bowl 1rot 2box
  bowlObject = int(random(bowlNum)); //choose object
  rotObject = int(random(rotNum));
  boxObject = int(random(boxNum));
}

void draw() {
  imageMode(CENTER);

  if (mode == 0) {
    image(title, width/2, height/2);

    fill(255);
    textSize(30);
    text("start", 900, 600);
    image(startbutton, width/1.32, height/1.27);

    if (mousePressed) {
      if (mouseX>width/1.64 && mouseX<width/1.1 && mouseY>height/1.41 && mouseY<height/1.16) {
        image(startbutton_pushed, width/1.32, height/1.27);
      }
    }
  }

  if (mode == 1) { //menu
    image(menu_background, width/2, height/2);

    image(stage1_icon, width/4.5, height/2.05);
    image(stage2_icon, width/2, height/2);
    image(stage3_icon, width/1.28, height/2);

    if (mouseY>height/3 && mouseY<height/1.5) {
      if (mouseX>width/7 && mouseX<width/3.3) {
        pushMatrix();
        translate(width/4.5, height/2.05);
        scale(1.2);
        image(stage1_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage2_icon, width/2, height/2);
          image(stage3_icon, width/1.28, height/2);

          pushMatrix();
          translate(width/4.5, height/2.05);
          scale(0.95);
          image(stage1_icon, 0, 0);
          popMatrix();
        }
      } else if (mouseX>width/2.4 && mouseX<width/1.7) {
        pushMatrix();
        translate(width/2, height/2);
        scale(1.2);
        image(stage2_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage1_icon, width/4.5, height/2.05);
          image(stage3_icon, width/1.28, height/2);

          pushMatrix();
          translate(width/2, height/2);
          scale(0.95);
          image(stage2_icon, 0, 0);
          popMatrix();
        }
      } else if (mouseX>width/1.45 && mouseX<width/1.15) {
        pushMatrix();
        translate(width/1.28, height/2);
        scale(1.2);
        image(stage3_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage1_icon, width/4.5, height/2.05);
          image(stage2_icon, width/2, height/2);

          pushMatrix();
          translate(width/1.28, height/2);
          scale(0.95);
          image(stage3_icon, 0, 0);
          popMatrix();
        }
      }
    }
  }

  //---------------game----------------

  if (mode == 2.1) {
    stage = 2.1;
    fill(0);
    rect(0, 0, width, height);
    fill(255);
    text("stage 1 not yet", width/2, height/2);
    if (mousePressed) {
      mode = 3.2;
    }
  }
  if (mode == 2.2) {
    stage = 2.2;
    draw_stage2();
  }
  if (mode == 2.3) {
    stage = 2.3;
    fill(0);
    rect(0, 0, width, height);
    fill(255);
    text("stage 3 not yet", width/2, height/2);
    if (mousePressed) {
      mode = 3.2;
    }
  }
  //-----------------------------------

  if (mode>3 && mode<4) { 
    image(result, width/2, height/2);
    image(againbutton, width/1.325, height/1.28);
    image(selectbutton, width/1.325, height/1.28);
    if (mousePressed) {
      if (mouseY>height/1.39 && mouseY<height/1.19) {
        if (mouseX>width/1.65 && mouseX<width/1.34) {
          image(againbutton_pushed, width/1.325, height/1.28);
        } else if (mouseX>width/1.31 && mouseX<width/1.11) {
          image(selectbutton_pushed, width/1.325, height/1.28);
        }
      }
    }
    if (mode == 3.1) {
      image(result_clear, width/1.325, height/2.4);
    } else if (mode == 3.2) {
      image(result_fail, width/1.32, height/2.4);
    }
  }
}

void keyReleased() {
  if (mode>2 && mode<3) {
    if (check == 1) {
      if (mode == 2.1) {
        answer = int(random(2));
      }
      answer = int(random(3));
      bowlObject = int(random(bowlNum)); 
      rotObject = int(random(rotNum));
      boxObject = int(random(boxNum));
      objectY = 0;
      score += 1;
      check = 0;
      objectX = width/2;
      shadow = 300;
    } else if (check == 2) {
      if (mode == 2.1) {
        answer = int(random(2));
      }
      answer = int(random(3));
      bowlObject = int(random(bowlNum)); 
      rotObject = int(random(rotNum));
      boxObject = int(random(boxNum));
      objectY = 0;
      life -= 1;
      check = 0;
      objectX = width/2;
      shadow = 300;
    }
  }
}

void mouseReleased() {
  if (mode == 0 && mouseX>width/1.64 && mouseX<width/1.1 && mouseY>height/1.41 && mouseY<height/1.16) {
    mode = 1;
  }

  if (mode == 1 && mouseY>height/3 && mouseY<height/1.5) {
    if (mouseX>width/7 && mouseX<width/3.3) {
      mode = 2.1;
    } else if (mouseX>width/2.4 && mouseX<width/1.7) {
      mode = 2.2;
      bowlNum = 8; 
      rotNum = 8;
      boxNum = 8;
      time = millis();
    } else if (mouseX>width/1.45 && mouseX<width/1.15) {
      mode = 2.3;
    }
  }

  if (mode > 3 && mode < 4) {
    if (mouseY>height/1.39 && mouseY<height/1.19) {
      if (mouseX>width/1.65 && mouseX<width/1.34) {
        time = millis();
        mode = stage;
      } else if (mouseX>width/1.31 && mouseX<width/1.11) {
        mode = 1;
      }
    }
  }
}

//-----------------------------------------------
//--------------------stage2 code------------------
//-----------------------------------------------

void draw_stage2() {
  image(background, width/2, height/2);

  if (game == true) {
    objectY += (height/2.3-objectY)*0.3;

    fill(157, 180, 173);
    noStroke();
    ellipse(width/2, height/1.8, shadow, 50);
    shadow += (180-shadow)*0.3;

    if (answer==0) { //bowl 
      image(objectList[stage2_bowlList[bowlObject]], objectX, objectY);   
      if (keyPressed) {
        if (keyCode == LEFT) { 
          objectX = objectX + (width/10-objectX)*0.5;
          image(O, width/2, height/2.3); 
          check = 1;
        } else if (keyCode == DOWN) {
          objectY = objectY + (height*1.2-objectY)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        } else if (keyCode == RIGHT) {
          objectX = objectX + (width/1.1-objectX)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        }
      }
    } else if (answer==1) { //rot 
      image(objectList[stage2_rotList[rotObject]], objectX, objectY);
      if (keyPressed) {
        if (keyCode == RIGHT) {
          objectX = objectX + (width/1.1-objectX)*0.5;
          image(O, width/2, height/2.3);
          check = 1;
        } else if (keyCode == DOWN) {
          objectY = objectY + (height*1.2-objectY)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        } else if (keyCode == LEFT) {
          objectX = objectX + (width/10-objectX)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        }
      }
    } else if (answer==2) { //box
      image(objectList[stage2_boxList[boxObject]], objectX, objectY);
      if (keyPressed) {
        if (keyCode == DOWN) {
          objectY = objectY + (height*1.2-objectY)*0.5;
          image(O, width/2, height/2.3);
          check = 1;
        } else if (keyCode == LEFT) {     
          objectX = objectX + (width/10-objectX)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        } else if (keyCode == RIGHT) {
          objectX = objectX + (width/1.1-objectX)*0.5;
          image(X, width/2, height/2.3);        
          check = 2;
        }
      }
    }
  }

  image(ui, width/2, 67);

  if (score == left) {
    println("complete");
    game = false;
    readyY = -3000;
    startY = -3000;

    image(stageClear, width/2, stageClearY);
    stageClearY += (height/2 - stageClearY)*0.3;
    if (mousePressed) {
      mode = 3.1;
      score = 0;
      life = 3;
      clockRotate = 0;
    }
  }

  if (life == 0 || millis()-time>34000) {
    println("failed");
    game = false;
    readyY = -3000;
    startY = -3000;

    image(gameOver, width/2, gameOverY);
    gameOverY += (height/2 - gameOverY)*0.3;
    if (mousePressed) {
      mode = 3.2;
      score = 0;
      life = 3;
      clockRotate = 0;
    }
  }

  fill(255);
  textSize(32);
  text(score, width/1.5, 50);
  text(left, width/1.35, 50);

  if (mode>2 && mode <3 && game == true) {
    //text((millis()-time)/1000, 0, 50);
    clockRotate = ((millis()-time-4000)/1000)*6;
  }
  pushMatrix(); //clock
  translate(width/2, 10);
  rotate(-radians(clockRotate));
  image(clock, -50, 0);
  popMatrix();

  for (int i=0; i<life; i++) {  //life
    image(lifeImg, (width/1.19)+(75*i), 35);
  }

//--------------------------------------------------
  image(ready, width/2, readyY);  //ready start
  readyY += (height/2 - readyY)*0.3;
  if (millis()-time>2000) { 
    readyY += (3000 - readyY)*0.3;
    image(start, width/2, startY);
    startY += (height/2 - startY)*0.3;
  }
  if (millis()-time>4000) {
    startY += (3000 - startY)*0.3;
    game = true;
  }
  
  image(ui2, width/2, 67);
}


2019_1 Interactive Video Week 13









PImage background;
PImage clock;
PImage lifeImg;
PImage O;
PImage X;
PImage ui;
PImage ready;
PImage start;
PImage stageClear;
PImage gameOver;
PImage menu_background;
PImage title;
PImage stage1_icon;
PImage stage2_icon;
PImage stage3_icon;

PImage[] objectList = new PImage[24];


int[] stage1_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage1_boxList = {2, 3, 18, 19, 20, 21, 22, 23};
int[] stage1_rotList = {4, 5, 12, 13, 14, 15, 16, 17};

int[] stage2_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage2_boxList = {2, 3, 18, 19, 20, 21, 22, 23};
int[] stage2_rotList = {4, 5, 12, 13, 14, 15, 16, 17};

int[] stage3_bowlList = {0, 1, 6, 7, 8, 9, 10, 11};
int[] stage3_boxList = {2, 3, 18, 19, 20, 21, 22, 23};
int[] stage3_rotList = {4, 5, 12, 13, 14, 15, 16, 17};

int left = 30;
int score = 0;
int life = 3; 
int time = 0; 

int answer;
int bowlObject;
int rotObject;
int boxObject;
int bowlNum = 5; 
int rotNum = 5;
int boxNum = 5;

float mode = 0;
/* 
 mode 0: title
 mode 1: menu
 mode 2.1: level 1
 mode 2.2: level 2
 mode 2.3: level 3
 mode 3: end
 */

float clockRotate = 0; 
float objectY = 0;
float objectX = 640;
float shadow = 300;
float readyY = -3000;
float startY = -3000;
float timeUpY = -3000;
float gameOverY = -3000;
float stageClearY = -3000;

float check = 0; // 0:none, 1:correct, 2:incorrect

boolean game = false;

void setup() {
  imageMode(CENTER);
  size(1280, 720);
  background = loadImage("background.png");
  clock = loadImage("clock.png");
  lifeImg = loadImage("life.png");
  ui = loadImage("ui.png");
  O = loadImage("O.png");
  X = loadImage("X.png");
  ready = loadImage("ready.png");
  start = loadImage("start.png");
  gameOver = loadImage("gameover.png");
  stageClear = loadImage("stageclear.png");
  menu_background = loadImage("menu.png");
  title = loadImage("title.png");
  stage1_icon = loadImage("stage1.png");
  stage2_icon = loadImage("stage2.png");
  stage3_icon = loadImage("stage3.png");

  for (int i=0; i<24; i++) {
    String objectlist = (i) + ".png";
    objectList[i] = loadImage(objectlist);
  }

  answer = int(random(2)); //choose answer 0bowl 1rot 2box
  bowlObject = int(random(bowlNum)); //choose object
  rotObject = int(random(rotNum));
  boxObject = int(random(boxNum));
}

void draw() {
  imageMode(CENTER);

  if (mode == 0) {
    image(title, width/2, height/2);
    fill(0);
    rect(750, 550, 400, 100);
    fill(255);
    textSize(30);
    text("start", 900, 600);
   
  }

  if (mode == 1) { //menu
    image(menu_background, width/2, height/2);

    image(stage1_icon, width/4.5, height/2.05);
    image(stage2_icon, width/2, height/2);
    image(stage3_icon, width/1.28, height/2);

    if (mouseY>height/3 && mouseY<height/1.5) {
      if (mouseX>width/7 && mouseX<width/3.3) {
        pushMatrix();
        translate(width/4.5, height/2.05);
        scale(1.2);
        image(stage1_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage2_icon, width/2, height/2);
          image(stage3_icon, width/1.28, height/2);

          pushMatrix();
          translate(width/4.5, height/2.05);
          scale(0.95);
          image(stage1_icon, 0, 0);
          popMatrix();
        }
      } else if (mouseX>width/2.4 && mouseX<width/1.7) {
        pushMatrix();
        translate(width/2, height/2);
        scale(1.2);
        image(stage2_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage1_icon, width/4.5, height/2.05);
          image(stage3_icon, width/1.28, height/2);

          pushMatrix();
          translate(width/2, height/2);
          scale(0.95);
          image(stage2_icon, 0, 0);
          popMatrix();
        }
      } else if (mouseX>width/1.45 && mouseX<width/1.15) {
        pushMatrix();
        translate(width/1.28, height/2);
        scale(1.2);
        image(stage3_icon, 0, 0);
        popMatrix();
        if (mousePressed) {
          image(menu_background, width/2, height/2);
          image(stage1_icon, width/4.5, height/2.05);
          image(stage2_icon, width/2, height/2);

          pushMatrix();
          translate(width/1.28, height/2);
          scale(0.95);
          image(stage3_icon, 0, 0);
          popMatrix();
        }
      }
    }
  }

  //---------------game----------------
  
  if (mode == 2.1){
    fill(0);
    rect(0, 0, width, height);
    fill(255);
    text("not yet", width/2, height/2);
    if (mousePressed) {
      mode = 0;
    }
  }
  if (mode == 2.2) {
    image(background, width/2, height/2);
    image(ui, width/2, 67);
    draw_stage2();
  }
  if (mode == 2.3){
    fill(0);
    rect(0, 0, width, height);
    fill(255);
    text("not yet", width/2, height/2);
    if (mousePressed) {
      mode = 0;
    }
  }
  //-----------------------------------
}

void keyReleased() {
  if (mode>2 && mode <3 && check == 1) {
    if (mode == 2.1) {
      answer = int(random(2));
    }
    answer = int(random(3));
    bowlObject = int(random(bowlNum)); 
    rotObject = int(random(rotNum));
    boxObject = int(random(boxNum));
    objectY = 0;
    score += 1;
    check = 0;
    objectX = width/2;
    shadow = 300;
  } else if (check == 2) {
    if (mode == 2.1) {
      answer = int(random(2));
    }
    answer = int(random(3));
    bowlObject = int(random(bowlNum)); 
    rotObject = int(random(rotNum));
    boxObject = int(random(boxNum));
    objectY = 0;
    life -= 1;
    check = 0;
    objectX = width/2;
    shadow = 300;
  }
}

void mouseReleased() {
  if (mode == 0 && mouseX>750 && mouseX<1150 && mouseY>550 && mouseY<650) {
      mode = 1;
    }
  
  if (mode == 1 && mouseY>height/3 && mouseY<height/1.5) {
    if (mouseX>width/7 && mouseX<width/3.3) {
      mode = 2.1;
    } else if (mouseX>width/2.4 && mouseX<width/1.7) {
      mode = 2.2;
      bowlNum = 8; 
      rotNum = 8;
      boxNum = 8;
      time = millis();
    } else if (mouseX>width/1.45 && mouseX<width/1.15) {
      mode = 2.3;
    }
  }
}



//-------------------stage2------------------------

void draw_stage2() {
  if (game == true) {
    objectY += (height/2.3-objectY)*0.3;

    fill(200);
    noStroke();
    ellipse(width/2, height/1.8, shadow, 50);
    shadow += (180-shadow)*0.3;

    if (answer==0) { //bowl 
      image(objectList[stage2_bowlList[bowlObject]], objectX, objectY);   
      if (keyPressed) {
        if (keyCode == LEFT) { 
          objectX = objectX + (width/10-objectX)*0.5;
          image(O, width/2, height/2.3); 
          check = 1;
        } else if (keyCode == DOWN) {
          objectY = objectY + (height*1.2-objectY)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        } else if (keyCode == RIGHT) {
          objectX = objectX + (width/1.1-objectX)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        }
      }
    } else if (answer==1) { //rot 
      image(objectList[stage2_rotList[rotObject]], objectX, objectY);
      if (keyPressed) {
        if (keyCode == RIGHT) {
          objectX = objectX + (width/1.1-objectX)*0.5;
          image(O, width/2, height/2.3);
          check = 1;
        } else if (keyCode == DOWN) {
          objectY = objectY + (height*1.2-objectY)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        } else if (keyCode == LEFT) {
          objectX = objectX + (width/10-objectX)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        }
      }
    } else if (answer==2) { //box
      image(objectList[stage2_boxList[boxObject]], objectX, objectY);
      if (keyPressed) {
        if (keyCode == DOWN) {
          objectY = objectY + (height*1.2-objectY)*0.5;
          image(O, width/2, height/2.3);
          check = 1;
        } else if (keyCode == LEFT) {     
          objectX = objectX + (width/10-objectX)*0.5;
          image(X, width/2, height/2.3);
          check = 2;
        } else if (keyCode == RIGHT) {
          objectX = objectX + (width/1.1-objectX)*0.5;
          image(X, width/2, height/2.3);        
          check = 2;
        }
      }
    }
  }
  image(ui, width/2, 67);

  image(ready, width/2, readyY);
  readyY += (height/2 - readyY)*0.3;

  if (millis()-time>2000) {
    readyY += (3000 - readyY)*0.3;
    image(start, width/2, startY);
    startY += (height/2 - startY)*0.3;
  }

  if (millis()-time>4000) {
    startY += (3000 - startY)*0.3;
    game = true;
  }

  if (score == left) {
    println("complete");
    game = false;
    time = millis();
    readyY = -3000;
    startY = -3000;
    
    image(stageClear, width/2, stageClearY);
    stageClearY += (height/2 - stageClearY)*0.3;
    if (mousePressed) {
      mode = 0;
      score = 0;
      life = 3;
      clockRotate = 180;      
      
    }
  }

  if (life == 0 || millis()-time>34000) {
    println("failed");
    game = false;
    time = millis();
    readyY = -3000;
    startY = -3000;
    
    image(gameOver, width/2, gameOverY);
    gameOverY += (height/2 - gameOverY)*0.3;
    if (mousePressed) {
      mode = 0;
      score = 0;
      life = 3;
      clockRotate = 180;
    }
  }

  fill(0);
  textSize(32);
  text(score, width/1.5, 50);
  text(left, width/1.35, 50);

  if (mode>2 && mode <3 && game == true) {
    text((millis()-time)/1000, 0, 50);
    clockRotate = ((millis()-time-4000)/1000)*6;
  }

  pushMatrix();
  translate(width/2, 10);
  rotate(-radians(clockRotate));
  image(clock, -50, 0);
  popMatrix();

  for (int i=0; i<life; i++) { //life
    image(lifeImg, (width/1.18)+(80*i), 45);
  }
}

2019_1 Interactive Video Week 12












PImage background;
PImage clock;
PImage lifeImg;
PImage O;
PImage X;
PImage ui;

PImage[] objectList = new PImage[6];

int[] stage1_bowlList = {0, 1};
int[] stage1_boxList = {2, 3};
int[] stage1_rotList = {4, 5};

int left = 10;
int score = 0;
int life = 3; 

float mode = 0;

float clockRotate = 0; 
int time = 0; 

/* 
 mode 0: title
 mode 1: menu
 mode 2.1: level 1
 mode 2.2: level 2
 mode 2.3: level 3
 mode 3: end
 */

int a;
int b;

int num = 2; 

float objectY = 0;

float check = 0; // 0:none, 1:correct, 2:incorrect


void setup() {
  size(1280, 720);
  background = loadImage("background.png");
  clock = loadImage("clock.png");
  lifeImg = loadImage("life.png");
  ui = loadImage("ui.png");
  O = loadImage("O.png");
  X = loadImage("X.png");

  for (int i=0; i<6; i++) {
    String objectlist = (i) + ".png";
    objectList[i] = loadImage(objectlist);
  }

  a = int(random(3)); //choose answer 0bowl 1rot 2box
  b = int(random(num)); //choose object
}

void draw() {
  image(background, 0, 0);

  /*beginShape(); //bowl
   vertex(0, height/5);
   vertex(width/3.5, height/5);
   vertex(width/3.5, height/1.32);
   vertex(0, height/1.32);
   endShape();
   
   beginShape(); //box
   vertex(width/5, height/1.31);
   vertex(width/1.25, height/1.31);
   vertex(width/1.25, height);
   vertex(width/5, height);
   endShape(CLOSE);
   
   beginShape(); //trash can
   vertex(width/1.35, height/5);
   vertex(width, height/5);
   vertex(width, height/1.32);
   vertex(width/1.35, height/1.32);
   endShape(CLOSE);*/

  if (mode == 2.1){
    num = 2;
  }else if(mode == 2.2){
    num = 2;
  }else if (mode == 2.3){
    num = 2;
  }
  
  //------------stage2-------------
  if (mode == 2.2) {

    imageMode(CENTER);

    objectY += objectY + 0.02;
    if (objectY > height/2.3) {
      objectY = height/2.3;
    }

    if (a==0) { //bowl 
      image(objectList[stage1_bowlList[b]], width/2, objectY);   
      if (mousePressed) {
        if (mouseX<width/3.5 && mouseY<height/1.2 && mouseY>height/5) {
          image(O, width/2, height/2.3); 
          check = 1;
        } else if (mouseX>width/5 && mouseX<width/1.25 && mouseY>height/1.31) {
          image(X, width/2, height/2.3);
          check = 2;
        } else if (mouseX>width/1.35 && mouseY<height/1.2 && mouseY>height/5) {
          image(X, width/2, height/2.3);
          check = 2;
        }
      }
      imageMode(CORNER);
    } else if (a==1) { //trash can
      image(objectList[stage1_rotList[b]], width/2, objectY);
      if (mousePressed) {
        if (mouseX>width/1.35 && mouseY<height/1.2 && mouseY>height/5) {
          image(O, width/2, height/2.3);
          check = 1;
        } else if (mouseX>width/5 && mouseX<width/1.25 && mouseY>height/1.31) {
          image(X, width/2, height/2.3);
          check = 2;
        } else if (mouseX<width/3.5 && mouseY<height/1.2 && mouseY>height/5) {
          image(X, width/2, height/2.3);
          check = 2;
        }
      }
      imageMode(CORNER);
    } else if (a==2) { //box
      image(objectList[stage1_boxList[b]], width/2, objectY);
      if (mousePressed) {
        if (mouseX>width/5 && mouseX<width/1.25 && mouseY>height/1.31) {
          image(O, width/2, height/2.3);
          check = 1;
        } else if (mouseX<width/3.5 && mouseY<height/1.2 && mouseY>height/5) {
          image(X, width/2, height/2.3);
          check = 2;
        } else if (mouseX>width/1.35 && mouseY<height/1.2 && mouseY>height/5) {
          image(X, width/2, height/2.3);        
          check = 2;
        }
      }
      imageMode(CORNER);
    }
  }
  //----------------------------------

  if (score == left) {
    println("complete");
    score = 0;
    life = 3;
    mode = 0;
  }

  if (life == 0 || millis()-time>15000) {
    println("failed");
    score = 0;
    life = 3;
    mode = 0;
    clockRotate = 180;
  }

  image(ui, 0, 0);

  fill(0);
  textSize(32);
  text(score, width/1.5, 50);
  text(left, width/1.35, 50);

  if (mode>2 && mode <3) {
    text((millis()-time)/1000, 0, 50);
    clockRotate = ((millis()-time)/1000)*12;
  }

  

  pushMatrix();
  translate(width/2, 10);
  rotate(-radians(clockRotate));
  image(clock, -100, -10);
  popMatrix();

  for (int i=0; i<life; i++) { //life
    image(lifeImg, (width/1.23)+(80*i), 20);
  }
}

void keyPressed() {
  mode=2.2;
  time = millis();
}

void mouseReleased() {
  if (check == 1) {
    a = int(random(3));
    b = int(random(num));
    objectY = 0;
    score += 1;
    check = 0;
  } else if (check == 2) {
    a = int(random(3));
    b = int(random(num));
    objectY = 0;
    life -= 1;
    check = 0;
  }
}

2019_1 Interactive Video Week 11








PImage background;
PImage time;
PImage life;
PImage O;
PImage X;

PImage[] correctList = new PImage[2];
PImage[] keepList = new PImage[2];
PImage[] rotList = new PImage[2];

float left = 10;
float done = 0;

float mode = 0;
/* 
mode 0: title
mode 1: menu
mode 2.1: level 1
mode 2.2: level 2
mode 2.3: level 3
mode 3: end
*/

float a;
int b;


void setup() {
  size(1280, 720);
  background = loadImage("background.png");
  time = loadImage("time.png");
  life = loadImage("life.png");
  O = loadImage("O.png");
  X = loadImage("X.png");

  for(int i=0; i<2; i++){
    String rotlist = "rot" + (i+1) + ".png";
    String keeplist = "keep" + (i+1) + ".png";
    String correctlist = "correct" + (i+1) + ".png";
    rotList[i] = loadImage(rotlist);
    keepList[i] = loadImage(keeplist);
    correctList[i] = loadImage(correctlist);
  }
  a = int(random(2.99));
    b = int(random(1.99));
}

void draw() {
  image(background, 0, 0);
  
  //rect(width/2, 0, width/2, height/1.5);
  //rect(width/5, height/1.5, width/1.5, height);
  
  if (mode == 2.2){
    
    imageMode(CENTER);
    
    
    if (a==0){
      image(correctList[b],width/2,height/2.3);   
      if (mousePressed){
        println("correct");
        if (mouseX<width/2 && mouseY<height/1.2){
          image(O, width/2, height/2.3);
          println("O");
        }else{
          image(X, width/2, height/2.3);
          println("X");
        }
      }
      imageMode(CORNER);

    }else if (a==1){
      image(keepList[b], width/2, height/2.3);
      if (mousePressed){
        println("keep");
        if (mouseX>width/5 && mouseX<width/1.25 && mouseY>height/1.5){
          image(O, width/2, height/2.3);
          println("O");
        }else{
          image(X, width/2, height/2.3);
          println("X");
        }
      }
      imageMode(CORNER);
      
    }else{
      image(rotList[b], width/2, height/2.3);
      if (mousePressed){
        println("rot");
        if (mouseX>width/2 && mouseY>height/1.2){
          image(O, width/2, height/2.3);
          println("O");
        }else{
          image(X, width/2, height/2.3);
          println("X");
        }
      }
      imageMode(CORNER);
    }
  }
}


void mousePressed(){
  mode=2.2;
  a = int(random(3));
  b = int(random(2));
}

1 2 3