Interactive Video | Week5 assignment


FILE


I made a 'Whac-A-Mole' game.
Two player can play this game.
Player 1 can move the mole using the Up,Down,Left,Down key on the keyboard.
The mole can move only in the hole.
And player 2 can catch the mole with the hammer.
When you hit the mole with the hammer, the mole changes its face and the ouch mark appears.


CODE

PImage title;
PImage mole;
PImage ouch;
PImage ouchmole;
PImage hammer;
PFont font1;
int moleX = 222;
int moleY = 442;

void setup () {
frameRate(15);
size (500,700);
title = loadImage("title.png");
mole = loadImage("mole.png");
hammer = loadImage("hammer.png");
ouch = loadImage("ouch.png");
ouchmole = loadImage("ouchmole.png");
font1= loadFont("BMJUA-48.vlw");

}
void draw() {

background(#A0DBF2);

/*title*/
image(title, 60, 60);

/*hill*/
noStroke();
fill(#7ABC50);
ellipse(250,650,1380,760);

/*player*/
textFont(font1);
textSize(20);
fill(0);
text("PLAYER1 KEYBOARD",150,160);
text("PLAYER2 MOUSE",150,200);
image(mole, 335, 137, width/25, height/25);
image(hammer, 305, 180, width/23, height/23);

/*hole*/
fill(50);
ellipse(100,400,70,30);
ellipse(250,400,70,30);
ellipse(400,400,70,30);
ellipse(100,500,70,30);
ellipse(250,500,70,30);
ellipse(400,500,70,30);
ellipse(100,600,70,30);
ellipse(250,600,70,30);
ellipse(400,600,70,30);

/*mole*/
image(mole,moleX,moleY);
 
  if (keyPressed ) {
    if (keyCode==LEFT) {moleX -= 150; }
    if (keyCode==RIGHT) {moleX += 150; }
    if (keyCode==UP) {moleY -= 100; }
    if (keyCode==DOWN) {moleY +=100; }
  }

if (moleX >= 372) {
moleX = 372; 
}

if (moleX <= 72) {
moleX =72; 
}
if (moleY >= 542) {
moleY = 542; 
}

if (moleY <= 342) {
moleY =342; 
}

/*ouchmole*/
if(mousePressed==true && moleX+40<=mouseX && mouseX<=moleX+100 && moleY-20<=mouseY && mouseY<=moleY+100){  
  image(ouch,moleX-25,moleY-20); 
  image(ouchmole,moleX,moleY);
}

/*hammer*/

 if(mousePressed){
 pushMatrix();
 translate(mouseX-55, mouseY);
 rotate(radians(-50)); 
 image(hammer,0,0);
 popMatrix();}
 else {
 image(hammer,mouseX-34,mouseY-43); 
 }
}

덧글

댓글 입력 영역