5 Replies Latest reply on Dec 1, 2006 6:00 PM by kglad

    PacMan

    FlashIsTheCoolest123
      For this PacMan game I am making, I do not know how to add the code for the boudries, with an instance name of "walls". My PacMan guy can move around and stuff fine, but he goes through the walls, and that's a problem. Also, I don't know if the code goes under PacMan himself, or the walls that were converted to a movie clip named "Boundries". The code I have so far (that dos not work) is under PacMan:

      if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
      _x -= 1;
      }

      ... I got it from the example of "Maze" in the examples folder of Flash MX.

      Thanks!
        • 1. Re: PacMan
          kglad Adobe Community Professional & MVP
          you should be using a hitTest() between your pacman guy and walls. and that hitTest() needs to be in a continually executing loop.

          you would usually put that in the same loop that causes your pacman guy to move.
          • 2. Re: PacMan
            FlashIsTheCoolest123 Level 1
            Wow, I'm an idiot, and have no clue what that means, or what it does. How do I make a "loop"?.... and I hope the code relates to the PacMan and the walls... how do I make sure it does that? Thanks again
            • 3. Re: PacMan
              kglad Adobe Community Professional & MVP
              how does your pacman currently move? you must have a loop of some kind that repeatedly checks if the user is doing something (like pressing the right arrow key) and if-yes you have the pacman guy do something in response (like increase his _x property and move right).
              • 4. Re: PacMan
                FlashIsTheCoolest123 Level 1
                Oh, sorry. This is the code for my PacMan's movements (Its under himself, the movieclip):

                onClipEvent (load) {
                moveSpeed = 7;
                }
                onClipEvent (enterFrame) {
                if (Key.isDown(Key.RIGHT)) {
                this._x += moveSpeed;
                _rotation = 180
                }
                else if (Key.isDown(Key.UP)) {
                this._y -= moveSpeed;
                _rotation = 90
                }
                else if (Key.isDown(Key.DOWN)) {
                this._y += moveSpeed;
                _rotation = 270
                }
                else if (Key.isDown(Key.LEFT)) {
                this._x -= moveSpeed;
                _rotation = 0
                }
                }

                Thanks again!
                • 5. Re: PacMan
                  kglad Adobe Community Professional & MVP
                  your enterFrame() event is your loop. you can put your hitTest() there. for example: