A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: maze walls

  1. #1
    Member
    Join Date
    May 2008
    Posts
    48

    maze walls

    iam tryin to make a maze game. my codes all right ( NOT REALY!!) but the
    walls arnt good a hittest they just arnt . I tryed combineing two codes... total disaster!!
    help on better maze with better colision plaese... thanks


    PHP Code:
    // combined sucky code
    onClipEvent(load){
     
    speed 0;
    }
    onClipEvent (enterFrame) {
     if (
    Key.isDown(Key.UP)) {
     
    speed 7;
    }
    else if (
    Key.isDown(Key.DOWN)) {
     
    speed =- 7;
     }
     
     else 
    gotoAndStop(1);
    }
    onClipEvent (enterFrame) {
     if (
    Math.abs(speed)>0) {
     
    speed *= .7;
     }

     if (
    Key.isDown(Key.LEFT)) {
     
    _x -= 7;
     }
     if (
    Key.isDown(Key.RIGHT)) {
     
    _x += 7;
     }

     
    speed *= .98;
     
    Math.sin(_rotation*(Math.PI/20))*speed;
     
    Math.cos(_rotation*(Math.PI/20))*speed*-1;
     if (!
    _root.maze.hitTest(_x+x_y+ytrue)) {
     
    _x += x;
     
    _y += y;
     } else {
     
    speed *= -.6;
     }
    }
    onClipEvent (enterFrame) {
        if(
    _root.maze.hitTest(_x+(_width/2),_y,true)){
            
    this._x -= 7;
        }
        if(
    _root.maze.hitTest(_x-(_width/2),_y,true)){
            
    this._x += 7;
        }


  2. #2
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    I didn't quite get what's going on in the code. Though here's a fla that was in the Flash MX samples that has that maze game. Hope it helps.
    Last edited by PhobiK; 12-21-2008 at 09:55 PM.
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  3. #3
    Member
    Join Date
    May 2008
    Posts
    48

    hard for me

    thats to dificult is there somthing lil more easier??

  4. #4
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    the only difficult part is to find the code there
    Code:
    onClipEvent (enterFrame) {
    	if (_root.started && _root._currentframe==1) {
    		with (_root.square) {
    			//
    			// keyboard controls
    			if (Key.isDown(Key.DOWN)) {
    				_y += 1;
    			}
    			if (Key.isDown(Key.UP)) {
    				_y -= 1;
    			}
    			if (Key.isDown(Key.LEFT)) {
    				_x -= 1;
    			}
    			if (Key.isDown(Key.RIGHT)) {
    				_x += 1;
    			}
    			//
    			// detect if edges of the player square are colliding with the maze walls
    			if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
    				_x -= 1;
    			}
    			if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
    				_x += 1;
    			}
    			if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
    				_y -= 1;
    			}
    			if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
    				_y += 1;
    			}
    			//
    			// detect if maze is finished
    			if (_root.goal.hitTest(_x, getBounds(_root).yMax, true)) {
    				_root.gotoandstop(3);
    			}
    		}
    	}
    }
    who is this? a word of friendly advice: FFS stop using AS2

  5. #5
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    Thanks for posting it Well it's not too difficult. getBounds is used to get the limits of the mc. It gives you the values xMin, xMax, yMin and yMax. So you check the hitTest like you were doing it but with those values. You can also keep it your way replacing the getBounds with _x + _width/2 for example. That works too.
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center