Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change enemy collision event

    I'm working on this game. I have all the components together but I can't figure out how to change the collision event. As of now, the event is to restart the game. Instead of doing that, i'd like to go to a new map...like a warp point. I understand I need to change IF collision then change the event after that. I'm just starting to learn flash so I'm not sure what to change the event to or how to do that. Here is the code for the enemy collision. Also I have 3 enemy sprites so far and want each sprite to go to a different map.

    Code:
    		//check if we have collision with hero
    		var xdist = ob.x-char.x;
    		var ydist = ob.y-char.y;
    		if (Math.sqrt(xdist*xdist+ydist*ydist)<ob.width+char.width) {
    			//end the game
    			removeMovieClip(_root.tiles);
    			_root.gotoAndPlay(1);
    If you need more info, let me know.
    Last edited by gaber79; 10-16-2010 at 01:10 AM.

  • #2
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need full explanation of that code.
    __________________________________
    Cheap Hotels Kanyakumari | Kanyakumari Tourist Home | Kanyakumari Sunrise and Sunset

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay. So, i have a tile based game. It's set up to where i can move from map to map by different door tiles. However, my enemies are set up to restart the game when you touch them. I would like to move to another map when I touch the enemy. Here is the full code for the enemy actions.

    Code:
    function enemyBrain() {
    	//loop through all enemies currently on stage
    	for (var i = 0; i<game.currentEnemies; ++i) {
    		//name of new enemy
    		var name = "enemy"+i;
    		var ob = game[name];
    		//check if enemy will hit the wall
    		getMyCorners(ob.x+ob.speed*ob.xMove, ob.y+ob.speed*ob.yMove, ob);
    		if (ob.downleft and ob.upleft and ob.downright and ob.upright) {
    			//move enemy
    			moveChar(ob, ob.xMove, ob.yMove);
    		} else {
    			//reverse enemy direction
    			ob.xMove = -ob.xMove;
    			ob.yMove = -ob.yMove;
    		}
    		//check if we have collision with hero
    		var xdist = ob.x-char.x;
    		var ydist = ob.y-char.y;
    		if (Math.sqrt(xdist*xdist+ydist*ydist)<ob.width+char.width) {
    			//end the game
    			removeMovieClip(_root.tiles);
    			_root.gotoAndPlay(1);
    		}
    	}
    }
    So, basically, I have the if statement right because when it hits the enemy, it restarts the game. removeMovieClip takes the game off. the next line "_root.gotoAndPlay(1)" tells it to restart the game to frame 1 which is the click here to start frame.
    Last edited by gaber79; 10-22-2010 at 12:00 AM.


  •  

    Posting Permissions

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