We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to make my ellipse disappear when colliding with the walls of the maze (which are made up of arcs). Any tips?
Here's the code:
//Up to increase number of levels
//Down to decrease number of levels
int a=500;
void setup() {
size(550,500);
}
int nlevels=5;
int ellipse=5;
void draw() {
translate(0,20);
background(255);
noFill();
if (nlevels<33) {
strokeWeight(3);
}
else if (nlevels<50) {
strokeWeight(2);
}
else {
strokeWeight(1);
}
print(nlevels);
float dist=a/nlevels*0.8;
//1
line(a/2,(a/2)-dist/2,a/2,(a/2)+dist/2);
line((a/2)-dist/2,a/2,(a/2)+dist/2,a/2);
//2
arc(a/2+dist/4,a/2-dist/2,dist/2,dist/2,PI,TWO_PI);
for (int i=0;i<nlevels;i++) {
arc(a/2-dist/2,a/2-dist/2,(dist*i),(dist*i),PI/2,PI);
arc(a/2+dist/4,a/2-dist/2,(1.5*dist)+(dist*i),(1.5*dist)+(dist*i),PI,TWO_PI);
arc(a/2+dist/2,a/2-dist/2,dist+(dist*i),dist+(dist*i),0,HALF_PI);
line(a/2,(a+dist*(i-1))/2,a/2,(a+dist*i)/2);
if (i%2==0) {
if (i!=nlevels-1) {
line(a/2-dist/2,a/2+(i*dist/2),a/2+dist/2,a/2+(i*dist/2));
} else {
line(a/2,(a+dist*i)/2,a/2+dist/2,(a+dist*i)/2);
}
}
}
fill(0);
ellipse(mouseX,mouseY,20,20);
}
void keyPressed() {
if (key == CODED) {
switch (keyCode) {
case UP:
nlevels=min(83,nlevels+1);
ellipse=min(83,ellipse+1);
break;
case DOWN:
nlevels=max(5,nlevels-1);
ellipse=max(5,ellipse-1);
break;
}
}
}
Answers
Tip #1: Edit your post.
Tip #2: Select your code.
Tip #3: Press Ctrl + o.
http://www.JeffreyThompson.org/collision-detection/table_of_contents.php
I'm confused, what is it that I am supposed to follow on this guide?
you need to vectorize your dungeon and apply physics to the walls and the character. a good start is to look at this function that determines whether there is a collision between a segment and a circle, the second step should be the resolution of the collision but to start with and have to try;)
This function only works with rectangles and circles, is the simplest way to detect collision in 2d between circle "character" with maze "walls".
I guess you could use dist()?