Firstly, I don't know how much you know, so don't be offended if I explain something you are already aware of.
Since you are creating a new symbol type, I would suggest not combining other symbols but rather use the arrays those other symbols use. If you look in the "fryer" movieclip you will see the following:
- Code: Select all
(parent as MovieClip).fryArray.push(this);
So every fryer instance that is in the level adds itself to the array and the onGameTick fucntion checks to see if the hero is touching anyone of them; if so, hero dies. So by knowing this. if you want you new bad guy symbol to kill the hero, then you would add it to the same fryer array.
If you noticed in the file I had posted for you, I created a new array to store each instance of the baddies. You will want to do this for your new bad guy symbol as well so you can test between the touching of the bad guys and the hero.
Now you say, this is all fine and dandy; I can jump on top of an enemy, test the collision, and die... great. How do I kill the enemy?
Well I can think of a few ways, some more complicated than others. The easiest I think would be to use the variables already being used in the engine like the "grounded" variable. As far as I can tell, when the hero is either rising or falling the "grounded" variable becomes false. So we could modify the engines "Dangerous Surfaces" loop which is testing for collision against "fryers".
Here is Sophie's original loop:
- Code: Select all
//## Dangerous surfaces
for (i=0; i<mcLevel.fryArray.length; i++){
if ( mcLevel.fryArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ){
//mcLevel.mcPlayer.x = safeSpot.x;
//mcLevel.mcPlayer.y = safeSpot.y;
xMove = 0;
yMove = 0;
grounded = false;
touchingSlope = "not";
dying = true
}
}
Change the 'if' statement to also test to see if the hero is on the ground:
- Code: Select all
if ( mcLevel.fryArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) && grounded){
That 'if' statement evaluates 'true' if the hero is on the ground false if the hero is in the air, so we now need to append the the 'if' statement to include and 'else' clause. In here I would call a function that lies in the enemy movieclip that destroys itself, which would include removing that instance from any of the arrays it was stored in like the fryer array and bad guy array, also, if you are using my baddie script to animate the bad guy, you will also have to stop the onEnterFrame function controlling that animation before you remove the clip or you will get errors.