Question About my game?

edited October 2014 in Questions about Code

Hey guys I was wondering how to program collisions (I'm new to programming). How do I make it so that when Pac man hits any of the ellipses something will happen. For example if I touch an ellipse I want a "game over" sign to appear. I know how to program the sign but how do I program that interaction between pacman and my shapes when they touch each other. This is what I have so far:

PImage face;
PImage apple;

int y = 0;
int x = 0;
int speed = 3;
int positionX=700;
int positionY=500;
int diameter=70;

float y = 0;
float yspeed = 3;

float f = random(100,700);

void setup() {
  size(700,500);
  smooth();
  face=loadImage("face.png");
  apple=loadImage("apple.png");
  frameRate(300);
}

void draw() {
  background(255);
  x = x + speed;

 //left to right bounce
  if ((x > width) || (x < 0)) {
    speed = speed * -1;
  }
  stroke(0);
  fill(175);
  ellipse(x,100,70,70);
  ellipse(x,300,70,70);
  ellipse(x,600,70,70);
  //up down bounce

 y = y + yspeed;

  if ((y > height) || (y < 0)) {
    yspeed = yspeed * -1;
  }
  stroke(0);
  fill(175);
  ellipse(100,y,70,70);
  ellipse(300,y,70,70);
  ellipse(500,y,70,70);

//Diagnal bounce below

if(positionX>=width-diameter/2){
    Switch=1;
  }
  if(positionX==diameter/2){
    Switch=0;
}
if(Switch==0){
  positionX++;

}
else if(Switch==1){;
  positionX--;

}
  if(positionY>=height-diameter/2){
    Switch=1;
  }
  if(positionY==diameter/2){
    Switch=0;
}
if(Switch==0){
  positionY++;

}
else if(Switch==1){;
  positionY--;
}

ellipse(positionX, positionY, diameter, diameter);

//Player image
imageMode(CENTER);
face.resize(50,50);
image(face, mouseX, mouseY);

//random image
apple.resize(40,40);
image (apple, f, f);


}

Answers

Sign In or Register to comment.