Week5 Interactive Video




Let’s raise a dog!
Take care of your dogs by checking it’s hunger, thirst and other needs and giving it what it needs.
You can move the dog by using the arrow keys, and click to select an action.


<CODE>


PImage ground;
PImage SIDE;
PImage dogR;
PImage emptyfood;
PImage food;
PImage water;
PImage realpad;
PImage dirty;
PImage carrot;
PImage carrot2;
float dogX = 500;
float dogY = 400;
boolean eatFood = false;
boolean drinkWater = false;
boolean goToilet = false;
boolean playCarrot = false;

void setup() {
  size( 1000, 500);
  ground = loadImage("ground.png");
  SIDE = loadImage("SIDE.png");
  dogR = loadImage("doggy2.png");
  emptyfood = loadImage("emptyfood.png");
  food = loadImage("food.png");
  water = loadImage("water.png");
  dirty = loadImage("dirty.png");
  realpad = loadImage("realpad.png");
  carrot = loadImage("carrot.png");
  carrot2 = loadImage("carrot2.png");  
}

void draw() {
  background(0);
  image (ground, 500, 250);
  println(mouseX, mouseY);
  
  imageMode(CENTER);
  
  //side
  image (SIDE, 850, 250);

  //food
  if (mousePressed) {
    if ( dogX >= 80 && dogX <= 180 && dogY >= 90 && dogY <= 190) {
    eatFood = true;
    }
  }
    
  if (eatFood) {
    image (emptyfood, 130, 140, 142, 95);
    noStroke();
    fill(#708907);
    rect (815, 270, 120, 10);
    } else {
      image (food, 130, 140, 142, 95);
      noStroke();
      fill(#708907);
      rect (815, 270, 30, 10);
    }
    
   //water
  if (mousePressed) {
    if ( dogX >= 150 && dogX <= 250 && dogY >= 380 && dogY <= 480) {
    drinkWater = true;
    }
  }
    
  if (drinkWater) {
    image (emptyfood, 200, 430, 142, 95);
    noStroke();
    fill(#708907);
    rect (815, 317, 140, 10);
    } else {
      image (water, 200, 430, 142, 95);
      noStroke();
      fill(#708907);
      rect (815, 317, 20, 10);
    }   
   
  //toilet
  image (realpad, 600, 370, 146, 150);
  
  if (mousePressed) {
    if ( dogX >= 527 && dogX <= 673 && dogY >= 295 && dogY <= 445) {
    goToilet = true;
    }
  }
    
  if (goToilet) {
    image (dirty, 600, 370, 72, 72);
    noStroke();
    fill(#708907);
    rect (815, 366, 0, 10);
    } else {
      noStroke();
      fill(#708907);
      rect (815, 366, 145, 10);
    }
    
    //carrot toy
  if (mousePressed) {
    if ( dogX >= 543 && dogX <= 657 && dogY >= 180 && dogY <= 220) {
    playCarrot = true;
    }
  }
    
  if (playCarrot) {
    image (carrot2, 600, 200, 114, 40);
    noStroke();
    fill(#708907);
    rect (815, 416, 150, 10);
    } else {
      image (carrot, 600, 200, 114, 40);
      noStroke();
      fill(#708907);
      rect (815, 416, 80, 10);
    }
    
  //dog move
  image (dogR, dogX, dogY, 240/2, 214/2); 
  if(keyPressed == true){
    if(keyCode == UP) {
      dogY = dogY - 3;
    } else if(keyCode == DOWN) {
       dogY = dogY + 3;    
    } else if(keyCode == RIGHT) {
        dogX = dogX + 3;  
    } else if(keyCode == LEFT) {
        dogX = dogX - 3;    
    }
  }
 
  //limit move
  if (dogX + 60 >= 700) {
    dogX = 640;
  }
  
  if (dogX-60 <= 0) {
    dogX = 60;
  }
  
  if (dogY >= 500-60) {
    dogY = 500-60;
  }
  
  if (dogY <= 60) {
    dogY = 60;
  }
}

덧글

댓글 입력 영역