So I am trying to make a Pacman kinda game


#1

I am new to processing so I am trying to make a pacman kinda game.

I want to make the small ball disappear and randomly spawn at another point in screen but I can’t specify the collision.

How can I do that? Here is my code:

int movx,movy,posy,posx;
float doty,dotx;
int i;
void setup(){

size(1000,500);
movx=0;
movy=0;
dotx=random(width);
doty=random(height);
posx=0;
posy=0;
}

void draw(){
posy=width/2+movy;
posx=height/2+movx;
background(255,255,255);

ellipse(dotx,doty,5,5);

  fill(255,255,0);
  stroke(0,0,0);
  strokeWeight(3);
  
    
  ellipseMode(RADIUS);
 ellipse(posy,posx,25,25);

 
  if(keyCode==UP){
movx+=-5;
}
if(keyCode==DOWN){
movx+=5;
}
if(keyCode==RIGHT){
movy+=5;
}

if(keyCode==LEFT){
movy+=-5;
}

if(key==ENTER){
frameCount=-1;
}

}

#2

I believe this question has been asked before on the previous forum, maybe try a quick google search.

There are many elements to pacman, including using a grid based system

Some good questions have already been answered on these posts as well:

As for your specific question, checking circular collision is really easy

I’d also bookmark this site if you plan on adding more collision elements


#3

It looks like you accidentally put the (x,y) in the wrong order in the second ellipse. And that would change the movement code, “movy” and “movx” would be flipped.

One way of doing collision would be to write a function, say circlesOverlap(), that calculates whether two circles overlap. Then in the draw() method, write an if statement that executes if the player and dot overlap, by passing the player and dot to the circlesOverlap() function.

for example, you could write a function like this:

boolean circlesOverlap(float x1, float y1, float radius1, float x2, float y2, float radius2){ 
     /* your code here */ 
     return false;
}