PDA

View Full Version : [AS2] hitTest Help


critter2003
09-16-2008, 06:53 AM
I'm making a Flash game for a university project and I'm having trouble with some of the coding. It's a geometry wars type shooting game where the player controls a character that can shoot in any direction around it at the enemies.

At the moment only the first bullet can kill the enemy. I've tried a combination of things and am guessing a for loop will fix my problem but I haven't been successful so far.

Secondly the hit detection between the enemies and what the player controls needs some fixing. I'd like it to only detect when the player hits the enemies, not their bounding box. For example, you can't go between the green enemies in my demo. I was experimenting with hitArea instead but again, couldn't get it to work.

I'm sure it's not too difficult but if someone could help that would be appreciated. I've attached a zip file with both my .swf and .fla files.

Indyaner
09-16-2008, 07:35 AM
It seems to me that you havnt set your Flag for the Shape-Hittest. Like the Reference (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary534.html) says:
shapeFlag A Boolean value specifying whether to evaluate the entire shape of the specified instance ( true ), or just the bounding box ( false ). This parameter can be specified only if the hit area is identified using x and y coordinate parameters..

And btw: You doint have to write always

if(statement == false)

Its a boolean value. You can simply ask

if(statement) //if statement is true

if(!statement) //if statement is false


bye

critter2003
09-16-2008, 07:57 AM
So for this enemy hitTest, how do I define the flag if it's x & y coordinates are constantly changing and I'm going to have multiple enemies.


for (var i:Number = 1; i<100; i++) {
if (yellowEnemies_mc["enemy"+i+"_mc"].hitTest(shot_mc0) && shotYellow == true) {
yellowEnemies_mc["enemy"+i+"_mc"].gotoAndPlay("death");
++enemiesKilled;
shot_mc0.removeMovieClip();
points();
}

mildSoup
09-21-2008, 08:06 AM
put all the enemies in an array and have the for loop cycle through the array.