# My Pacman Game issues

**URL:** <https://discourse.processing.org/t/my-pacman-game-issues/6806>\
**Category:** Libraries\
**Created:** [December 21, 2018, 12:31am UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806 "2018-12-21T00:31:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeOscar](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CodeOscar](https://discourse.processing.org/u/CodeOscar)\
**Post date:** [December 21, 2018, 12:31am UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/1 "2018-12-21T00:31:42Z")

</div>

I have a problem about when I want to press a key, up, down, right and left, change the image of my Pacman, depending on its position, with different animated sprites, which are in different images, according to their position, but my Pacman character does not it is shown, and in my video game it does not show me any error in the console.

**I need to fix this.**

This is the code link of my videogame: [https://editor.p5js.org/CodeOscar/sketches/HyfW-17g4](https://editor.p5js.org/CodeOscar/sketches/HyfW-17g4)

---

<div class="post-metadata">

**Author:** ![William3954](https://avatars.discourse-cdn.com/v4/letter/w/6a8cbe/32.png) [@William3954](https://discourse.processing.org/u/William3954)\
**Post date:** [December 21, 2018, 5:29am UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/2 "2018-12-21T05:29:26Z")

</div>

Try using only == with your conditionals (if) instead of ===

Btw- on mobile so I can not test it. Just something that stuck out to me.

---

<div class="post-metadata">

**Author:** ![Whahahahaha](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@Whahahahaha](https://discourse.processing.org/u/Whahahahaha)\
**Post date:** [December 21, 2018, 9:27am UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/3 "2018-12-21T09:27:54Z")

</div>

@CodeOscar in draw() you say `pacman.animate(data, rightImage);` , which will only animate the rightImage and ignore anything that happens inside the keyPressed function. I recommend making another image, imag or something and in function keyPressed do:

```auto
function keyPressed() {
 if (keyCode === RIGHT_ARROW) {
   	imag = rightImage;
   //pacman.animate(data, rightImage);
   pacman.dir(1, 0);
 } else if (keyCode === LEFT_ARROW) {
   	imag = leftImage;
   //pacman.animate(data, leftImage);
   pacman.dir(-1, 0);
 } else if (keyCode === UP_ARROW) {
   	imag = upImage;
   //pacman.animate(data, upImage);
   pacman.dir(0, -1);
 } else if (keyCode === DOWN_ARROW) {
   	imag = downImage;
   //pacman.animate(data, downImage);
   pacman.dir(0, 1);
 }
}

```

In draw you can now say: `pacman.animate(data, imag);` and it should update with that image  
now it still does not animate properly, but that is because in the pacman.js on line 18:

```auto
      animation.push(img);

```

will only add extra images which makes the array of animations longer and longer. you need to clear that out.  
Probably when you want to select another image (so in function keyPressed()).  
I’m not a p5.js master so I can’t guarantee this will make it work, or tell you how to, but this is definitely some things that are wrong.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 21, 2018, 1:02pm UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/4 "2018-12-21T13:02:34Z")

</div>

I would not have images being passed around as variables at all! Instead, make all your images globals, load them in setup, and then use conditional statements inside your pacman class to determine which way pacman is moving & use the appropriate image.

```auto
if( dx > 0 ){
  image( pacRight, pacX, pacY );
} else if ( dx < 0 ){
  image( pacLeft, pacX, pacY );
} else // ... etc

```

---

<div class="post-metadata">

**Author:** ![CodeOscar](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CodeOscar](https://discourse.processing.org/u/CodeOscar)\
**Post date:** [December 21, 2018, 4:58pm UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/5 "2018-12-21T16:58:23Z")

</div>

@TfGuy44 and @Whahahahaha Also **if you want** you can download my code for more details,

For download my code go to my code link of my videogame \> File \> Download

![Pacman](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e8dd02116b787422ca9a2b96a8f48db7494b20cf.png)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 22, 2018, 9:16pm UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/6 "2018-12-22T21:16:33Z")

</div>

I did Pacman back in 2015. I have no need to download your version.

> **[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.

---

<div class="post-metadata">

**Author:** ![CodeOscar](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CodeOscar](https://discourse.processing.org/u/CodeOscar)\
**Post date:** [December 24, 2018, 4:25pm UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/7 "2018-12-24T16:25:58Z")

</div>

@TfGuy44 Thank you very much for the link, I go to check the code, and execute them, for add features to my code 😉

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [May 14, 2024, 2:56pm UTC](https://discourse.processing.org/t/my-pacman-game-issues/6806/8 "2024-05-14T14:56:23Z")

</div>

I wrote a pac-man game in processing/java myself.  
I also improved a P5.JS pac-man game made by @seamusdonahue

> **[GitHub - pacman-admin/sitefinal: Allows you to download my Pac-Man.](https://github.com/pacman-admin/sitefinal)**
>
> Allows you to download my Pac-Man. Contribute to pacman-admin/sitefinal development by creating an account on GitHub.

[https://www.langdonstaab.ca](https://www.langdonstaab.ca)
