peachs312.egloos.com

peachs의 이글루

포토로그



Week 05 Interactive Video 2019


Move this cute cat with keyboard!(Mouse will not work)
Make the cat up, down, right, and left.
Fish never stops swimming!


*Code
PImage paw;
PImage cat1;
PImage cat2;
PImage fish1;
PImage fish2;
PImage fish3;

float fishx = 0;
float speedfx = 3;
float catx = 570;
float caty = 400;

void setup(){
  size(1280,720);
  paw = loadImage("paw.png");
  cat1 = loadImage("cat1.png");
  cat2 = loadImage("cat2.png");
  fish1 = loadImage("fish1.png");
  fish2 = loadImage("fish2.png");
  fish3 = loadImage("fish1.png");
 
}

void draw(){
  background(159,239,237);
  image(paw, 0,30);
  
  //fish 1
  image(fish1,fishx,100);
  fishx = fishx +speedfx;
  
  if (fishx > 1150){
    speedfx= -3; 
    fish1=fish2;
  } 
  
  if (fishx < 0 ){
    speedfx= +3;
    fish1=fish3;  
  }
 
  
  //cat
  image(cat1, catx, caty);
  if (keyPressed){
    if (keyCode == UP){
      caty = caty -3;      
    }
    if (keyCode == DOWN){
      caty = caty +3;      
    }
    
    if (keyCode == RIGHT){
      catx = catx +3;      
    }
    if (keyCode == LEFT){
      catx = catx -3;      
    }
    if (catx < 0){
      catx =0;
    }
    if (catx > 1100){
      catx =1100;
    }
    if (caty < 0){
      caty =0;
    }
    if (caty > 525){
      caty =525;
    }
  }
  
}
 

덧글

댓글 입력 영역