Flash Tutorials: Maze - Collision Detection

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Collision Detection

Free Tutorial


Step 5    <<   Previous      Intro   1   2   3   4   5   6   7   8     Next   >>       >>   Webwasp Mates

 

Step Five: Creating the Maze

  1. Right Click on Frame 2 of the ActionScript Layer and select: Insert Blank Keyframe
  2. Select one of the Drawing tools such as the Pen Tool:
  3. Draw your: Maze Walls
  4. Note: If your Maze drawing is going to very complex I suggest you only draw a small section of the Maze to start with. You can come back and add to the drawing latter. If the walls are too thin or the path (where your blue dot moves) is too narrow you may find that the Player goes straight through the walls. The thicker the Walls and the wider the Paths the faster you can make your Player move so try not to make the walls too thin.

  5. Return back to the standard Selection tool:
  6. Select the: Drawing (make sure the whole thing is selected)
  7. Right click the Maze drawing and select: Convert it to Symbol
  8. For Name type: walls
  9. For Behavior select: Movie Clip
  10. Click: OK
  11. If the Property Inspector is closed, open it: Window > Properties (Ctrl F3)
  12. Give the Movie Clip an Instance Name: walls
  13. Right Click on the Movie Clip again and select: Convert it to Symbol
  14. For Name type: maze
  15. For Behavior select: Movie Clip
  16. Click: OK
  17. Note: This creates a series of nested Movie Clips one inside another. The Walls Movie Clip is inside the Maze Movie Clip. The Maze Movie Clip is on the Main Stage:

  18. Attach the following ActionScript to the outside of the Maze Movie Clip:
  19. onClipEvent (enterFrame) {
        with (_root.player) {

            // Controls Player Speed
            mySpeed = 3;

            // Controls how far the Player bounces off the wall after impact
            myBounce = 3;

            // keyboard controls
            if (Key.isDown(Key.DOWN)) {
                _y += mySpeed;
            }
            if (Key.isDown(Key.UP)) {
                _y -= mySpeed;
            }
            if (Key.isDown(Key.LEFT)) {
                _x -= mySpeed;
            }
            if (Key.isDown(Key.RIGHT)) {
                _x += mySpeed;
            }

            // detect if edges of the player is colliding with the Maze Walls
            if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
                _x -= myBounce;
            }
            if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
                _x += myBounce;
            }
            if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
                _y -= myBounce;
            }
            if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
                _y += myBounce;
            }

            // detect if Maze is finished
            if (_root.end.hitTest(_x, getBounds(_root).yMax, true)) {
                _root.gotoAndStop(3);
            }
        }
    }

         

Step 5    <<   Previous      Intro   1   2   3   4   5   6   7   8     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

96714 visitors to this page since Jan 04 •

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.