We are about to switch to a new forum software. Until then we have removed the registration on this forum.
//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);
}
Answers
https://forum.processing.org/two/search?Search=collision
Please format your code. Edit your post, select code and hit ctrl+o. Ensure there is one empty line before and after the code block.
Also, you do the coding part. If you struggle, you provide details of your error or the part that you don't understand. Put effort in your code.
Kf
What is the shape of object and sponge bob( rect if I am not wrong)
if both are rect you have to saerch about rect-rect collision Detection
or AABB collision Detection
Here are a set of step-by-step tutorials on how to add collision detection between objects of different shapes:
http://www.jeffreythompson.org/collision-detection/table_of_contents.php