Determine if two images intercept?

edited March 20 in Questions about Code

I'm working on a project for computing where I have to make a game. In my game, you have to kick the ball by using the arrow keys into the moving goal. My project partner is working on the different difficult levels, so I do not have that part built into the code yet, but the different animations for each level have already been built below. I can't figure out how to get processing to recognize when the two images (ball and goal) intercept so that I can cause the lives to go down if the player misses. Any help would be greatly appreciated.

int u=325; //y-value for soccer ball
int v=250; //x-value for soccer ball
int w=0;//x-value for goal
int x=150; //y-value for easy
int y=90; //y-value for medium
int z=35; //y-value for difficult
PImage goal; //goal image
PImage background; //background image
PImage ball; //soccer ball image

void setup(){
size(500,375);
//Makes images appear
goal=loadImage("Soccer Goal.png");
background=loadImage("Field picture.jpg");
ball=loadImage("Soccer ball.png");
}

void draw(){
  //background must be in start of draw, otherwise unwanted trail occurs behind pictures
  background(background);
  image(ball,v,u,40,40);


  //Goals
  image(goal,w,x,250,250); //easy goal
    w=w+3; //animation
    w=w%375; //loop

  image(goal,w,y,200,200); //medium goal
    w=w+3; //animation
    w=w%375; //loop

  image(goal,w,z,150,150); //difficult goal
    w=w+3; //animation
    w=w%375; //loop

  //Lives
  fill(255); //background box fill
  stroke(255,10,10); //background box outline
  rect(350,15,80,50); //background box
  fill(255,10,10); //text color
  text("Lives",375,30); //label

  ellipse(365,45,15,15); //Life 1
  ellipse(390,45,15,15); //Life 2
  ellipse(415,45,15,15); //Life 3
}

void keyPressed(){
  if (key == CODED) {
  if(keyCode == RIGHT) {
    v=v+3;
  }
  if(keyCode == LEFT) {
    v=v-3;
  }

  if(keyCode == UP) {
    u=height-140; //easy goal ball shoot

  }
  if(keyCode == UP) {
    u=height-200; //medium goal ball shoot

  }
  if(keyCode == UP) {
    u=height-285; //difficult goal ball shoot
  }
}}

Answers

Sign In or Register to comment.