if anyone can put collision detection between the object and sponge bob character? appreciate it

//Falling Game
//Kyle Foster

PImage bkg, catcher, object;

int direction = 1;
int i = 1;

//catcher
int cX = 300;
int cY = 390;

//object
int oX = int(random(1,600));
int oY = 0;
int speed = int(random(1,10));
int oX2 = int(random(1,600));
int oY2 = 0;
int speed3 = int(random(2,4));
int oX3 = int(random(1,600));
int speed2 = int(random(1,2));
int oY3 = 0;

int random=0;

void setup() {
  size (700, 525);
  catcher = loadImage("2015-07-14-1436902565-6235018-SpongeBob_5.png");
  object = loadImage("76259-spongebob-square-pants-burger.png");
  bkg = loadImage("Krusty_Krab_kitchen.png");
}

void draw() {

  background(bkg);
//Objects
oY = oY + speed;
oY = oY +5;

image(object,oX,oY);
  image(catcher, cX, cY);
  if(oY<=900){
  }
  else{
    oY = int(random(-1,-600));
    oX = int(random(1,729));
  }
  image(object,oX2,oY2);
  oY2 = oY2 +5;
  oY2 = oY2 +speed3;
  if(oY2<=900){
  }
  else{
    oY2 = int(random(-1,-300));
    oX2 = int(random(1,729));
  }
  image(object,oX3,oY3);
  oY3 = oY3 +5;
  oY3 = oY3 + speed2;

 //code that stops spongebob at sides of screen
  cX = constrain(cX, 0, width-110);

 //keypressed
  if (keyPressed && (key == CODED)) {
    if (keyCode == LEFT) {
      cX = cX - 10;
    } else if (keyCode == RIGHT) {
      cX =cX+10;
    }
  } 

  if (keyPressed) {
    if (key == 'a') {
      cX = cX - 10;
    } else if (key == 'd') {
      cX =cX+10;
    }
  } 
 //mousex and mouse y
  println(mouseX, mouseY);
}
Tagged:

Answers

Sign In or Register to comment.