Interactive Video | Week 5 assignment




<Runaway>

Steal the delicious strawberry cake from the cook and run away!


+ You can move the cake using direction key.

+ When you click on the mouse, the mouse hides under the plate.

+ If you hit an obstacle, you'll go somewhere else.

+ Take the cake from the cook and escape!









float cakeX = 100;
float cakeY = 250;

int legX = 10;
int legY = 0;

PImage background;
PImage cake1;
PImage cake2;
PImage leg1;
PImage leg2;


void setup() {

  size (700, 500); 
  background = loadImage("background.png");
  cake1 = loadImage("cake1.png");
  cake2 = loadImage("cake2.png");
  leg1 = loadImage("leg1.png");
  leg2 = loadImage("leg2.png");
}


void draw () {

  image (background, 0, 0);

  //hide from cook by mousePressed
  if (mousePressed) {
    image (leg2, legX+50, legY-10);
    image (cake1, cakeX+15, cakeY+25);
  } else {
    image (leg1, legX, legY);
    image (cake2, cakeX, cakeY);
  }

  //moving mouse by keyPressed
  if (keyPressed) {
    if (keyCode == RIGHT) {
      cakeX += 1;
    } else if (keyCode == LEFT) {
      cakeX -= 1;
    } else if (keyCode == UP) {
      cakeY -= 1;
    } else if (keyCode == DOWN) {
      cakeY += 1;
    }
  }

  //do not fall off the table
  if (cakeX < 50) {
    cakeX=50;
  } else if (cakeY < 180) {
    cakeY=180;
  } else if (cakeY > 360) {
    cakeY=360;
  }

  //run away from the obstacle
  if (40 < cakeX && cakeX < 150 && cakeY > 270) {
    cakeY=290;
  } else if  (cakeX > 380 && cakeY > 240) {
    cakeY=250;
  }

}


덧글

댓글 입력 영역