Week 5

Recalling analog games, I created a simple interactive packman.
pressing 4 arrow buttons, packman moves around the screen without without getting out of the screen.


// mouth
float MW = PI/4; 

// pacman 
float curX = 0;
float curY = 0;
float pacmanRadius = 50;
float direction = 0;
  
void setup() {
  size(1080, 720);
  background(0);
}

void draw() {
  background(0);
  fill(255, 255, 0);
  arc (curX, curY, pacmanRadius, pacmanRadius, MW/2 + direction, 2*PI - MW/2 + direction);

}

void keyPressed(){
   if (key == CODED){
     if (keyCode == RIGHT) {
       if( curX+50<1080){
         curX=curX+10;
         direction = 0;
         }  
     } else if (keyCode == LEFT) {
         if( curX-50>0){
           curX=curX-10;
           direction = PI;
         }
     } else if (keyCode == UP) {
           if( curY-50>0){
             curY=curY-10;
             direction = PI * 3/2;
         }
     } else if (keyCode == DOWN){
             if( curY+50<720){
               curY=curY+10;
               direction = PI/2;
             }
           }
         }
       }

덧글

댓글 입력 영역