Testing for a hit using an array

  1. Copy the folder P:/Flash/wall arrays to Z:
  2. Add enough mcWall objects to the stage to make a maze with 10 walls
  3. Add this code to frame 1 in the Game timeline right after the line _global.hit=false;
    var walls = new Array(10); // there are 10 walls
      // add all the walls into an array so they can be treated as a group 
      for(var i = 0; i < _root.walls.length; i++) { 
          walls[i] = _root["wall" + i]; 
       }
  1. Create a movie clip object to be the character in the game
  2. Link your character to the Character.as code so it will be controlled by the keyboard. TEST your game and see if it works so far
  3. Add the code in Character.as to set the global variable named hit to true if the ending (destination in the main movie or _root) is hit.
    if(this.hitTest(_root.destination)){
    //you put the code in here that will set the global variable hit to true

    }
    Save it.
  4. Change the code in frame 3 of the game to say that if the global hit variable is true (game over) then go to frame 1 of the Ending scene, else continue looping at frame 2
  5. In Character.as add this code to the the onEnterFrame event that will check to see if the Character has collided with any walls and bounce it back to the beginning if so.
  6. for(var i = 0; i < _root.walls.length; i++) {
        if (this.hitTest(_root.walls[i])) {
             // if this movie clip hits one of the walls send it back
             this._x=???; // where does your character start?
             this._y=???;
             }
    
    }