We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm currently making this little game where you're a ball and you must dodge other balls, and I want to make that when some ball hits you the game ends, I've read that dist() may help, but I've only seen it work with static objects and the mouse, not both being moving.
This my code:
int a=390;
int b=390;
int c=390;
int d=390;
int e=390;
int f=390;
int g=390;
int h=390;
int i=390;
int j=390;
void setup () {
size (420,420);
}
void draw () {
background(mouseY +250,mouseY ,0);
ellipse (mouseX,mouseY, 30,30);
a=a-5;
b=b-4;
c=c-7;
d=d-5;
e=e-6;
f=f-3;
g=g-5;
h=h-6;
i=i-7;
j=j-3;
ellipse (30,a+1, 25,25);
ellipse (75,b+2, 25,25);
ellipse (120,c+1,25,25);
ellipse (165,d+2,25,25);
ellipse (210,e+1,25,25);
ellipse (255,f+2,25,25);
ellipse (300,g+1,25,25);
ellipse (345,h+2,25,25);
ellipse (390,i+1,25,25);
if (a<=0)
a=390;
if (b<=0)
b=390;
if (c<=0)
c=390;
if (d<=0)
d=390;
if (e<=0)
e=390;
if (f<=0)
f=390;
if (g<=0)
g=390;
if (h<=0)
h=390;
if (i<=0)
i=390;
}
Any help will be appreciated!
Answers
Edit post, highlight code, press Ctrl-o to format code.
Have you read the collision detection post in the Common Questions part of the forum?
Thanks for your answer and the code thingy.
Yeah, I've seen several options but haven't find any that suits with what I need
A modified version below. If you want to have multiple objects, you can use an array or an ArrayList container https://processing.org/reference/ArrayList.html and classes. If this interests you, you can check:
https://processing.org/tutorials/arrays/
https://processing.org/tutorials/objects/
Kf
Thanks a lot! that was just what I needed, si all I got to do now is make a class for the balls so every single one will "end loop"?
This is an example using classes.
Kf
Wow!!! thank you very much, really, you saved me, thanks.