week5








You can move the tomato by pressing the directional key.
You can also turn the tomato into ketchup by pressing the mouse.








Code

int X = 0;
int Y = 0;
PImage kitchen;
PImage tomato;
PImage ketchup;
PImage manB;
PImage manF;
PImage Sbubble;
PFont font1;


void setup() {

  size (500,500);
  kitchen = loadImage("kitchen.jpg");
  tomato = loadImage("tomato2.png");
  ketchup = loadImage("ketchup.png");
  manB = loadImage("man back.png");
  manF = loadImage("man front.png");
  Sbubble = loadImage("speech bubble.png");
  font1 = loadFont ("SangSangFlowerRoad-60.vlw");

}

void draw () {

 image (kitchen, -400, -150, 1100, 700);
 
 
 // speech bubble

 image (Sbubble, 190, 0, 320, 280);
 fill(0);
 textFont(font1);
 textSize(30);
 

// mouse play

if (mousePressed) {
 image (manF, 10, 70, 170, 270);
 image (ketchup, 70+X, 300+Y, 100, 100);
 text("No, I'm pure ketchup.", 250, 100);

} else {
 image (manB, 10, 70, 170, 270);
 image (tomato, 70+X, 320+Y, 50, 50);
 text("I'm a moving tomato, you idiot.", 220, 100);

 }


// keyboard play

if (keyPressed) {
  if (keyCode == UP) {
    Y -= 5; }
  else if (keyCode == DOWN) {
  Y += 5;}
  else if (keyCode == LEFT) {
  X -= 5; }
  else if (keyCode == RIGHT) {
  X += 5; }
}

if (X > 380) {
  X=380; }
  else if (X < -70) {
  X=-70; }
   else if (Y > 130) {
  Y=130; }
  else if (Y < 0) {
  Y=0; }
}


덧글

댓글 입력 영역