Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-14-2010, 06:19 PM   PM User | #1
gaber79
New to the CF scene

 
Join Date: Oct 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
gaber79 is an unknown quantity at this point
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 12:10 AM..
gaber79 is offline   Reply With Quote
Old 10-18-2010, 11:33 AM   PM User | #2
sunjay
New to the CF scene

 
Join Date: Oct 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sunjay is an unknown quantity at this point
I need full explanation of that code.
__________________________________
Cheap Hotels Kanyakumari | Kanyakumari Tourist Home | Kanyakumari Sunrise and Sunset
sunjay is offline   Reply With Quote
Old 10-21-2010, 10:54 PM   PM User | #3
gaber79
New to the CF scene

 
Join Date: Oct 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
gaber79 is an unknown quantity at this point
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-21-2010 at 11:00 PM..
gaber79 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43 AM.


Advertisement
Log in to turn off these ads.