# So I am trying to make a Pacman kinda game

**URL:** <https://discourse.processing.org/t/so-i-am-trying-to-make-a-pacman-kinda-game/7358>\
**Category:** Coding Questions\
**Created:** [January 9, 2019, 4:51pm UTC](https://discourse.processing.org/t/so-i-am-trying-to-make-a-pacman-kinda-game/7358 "2019-01-09T16:51:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![captainmajere](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@captainmajere](https://discourse.processing.org/u/captainmajere)\
**Post date:** [January 9, 2019, 4:51pm UTC](https://discourse.processing.org/t/so-i-am-trying-to-make-a-pacman-kinda-game/7358/1 "2019-01-09T16:51:29Z")

</div>

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:

```auto
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;
}

}

```

---

<div class="post-metadata">

**Author:** ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)\
**Post date:** [January 9, 2019, 5:07pm UTC](https://discourse.processing.org/t/so-i-am-trying-to-make-a-pacman-kinda-game/7358/2 "2019-01-09T17:07:21Z")

</div>

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:

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/19724/build-a-pacman-game)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/11156/pac-man-game-not-completed-asking-for-assistance)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

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

> **[Collision Detection](http://www.jeffreythompson.org/collision-detection/circle-circle.php)**
>
> An online book about collision detection using Processing.

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

---

<div class="post-metadata">

**Author:** ![HD161693](https://avatars.discourse-cdn.com/v4/letter/h/ac91a4/32.png) [@HD161693](https://discourse.processing.org/u/HD161693)\
**Post date:** [January 12, 2019, 9:48pm UTC](https://discourse.processing.org/t/so-i-am-trying-to-make-a-pacman-kinda-game/7358/3 "2019-01-12T21:48:35Z")

</div>

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:

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

```
