Hello guys,
I am a beginner on processing and i would like to do something : The thing would be to have 2 images mooving across the screen and when they touch eachother they hit and change directions.
for the moment I’ve only did one mooving image so if someone could help me it would be amazing.
PImage dvd;
float b;
float d = 1;
float speedX = 3;
float speedY = 3;
float x = random(width);
float y = random(height);
void setup (){
fullScreen();
dvd = loadImage (“dvd.png”);
}
void draw () { background (0);
bouger();
couleurs();
}
void couleurs() {
b = b + d;
tint (b, 255-b, b);
if (b > 255 || b < 0) { d = d * -1;}
}
void bouger() {
x = x + speedX;
y = y + speedY;
if (x < 0 || x > width - 339) { speedX = speedX * -1;}
if (y < 0 || y > height - 149) { speedY = speedY * -1;}
image (dvd,x,y);
}
Hi @ here is a very nice tutorial about collision detection. Just swap the ellipses with the images.
thank you very much and happy new year !