PDA

View Full Version : [AS2] help with collision test


kendyb
12-10-2008, 02:26 AM
I am using classes in my flash game. I try to use the hitTest function but it does not work for me. Can someone please help me. In the following code, I have an array in the class ship called enemies that and I need collision between the missiles and the enemies passed on to the array. Here is my missile class:


class missile extends MovieClip
{
//speed of missle
var msleSpeed;

//function to set missle speed
function onLoad()
{
msleSpeed = 25;
}

//function to have missile actions
function onEnterFrame()
{
//speed missile moves at
_x += msleSpeed;

//if missile movieClip greater than 600 pixels, remove missile movieClip from stage
if(_x > 1000)
{
//to remove missile movieClip
this.removeMovieClip();
}

//check the enemies array in the ship class, if this hits enemy1, enemy1 explode
for(var i in _root.ship.enemies)
{
if(this.hitTest(_root.ship.enemies[i]))
{
//remove the shot
this.removeMovieClip();

//find the enemy ship in the array declared in the ship class and call the explode function
_root.ship.enemies[i].explode();
_root.ship.updateScore(50);
}

}
}


}

pradvan
12-12-2008, 03:28 PM
Please post your code in code tags.

FluffyPapes
12-23-2008, 10:00 PM
Well, it would help if you yourself could understand the code.

From what I know, this is copied and pasted off of Kongregate's [www.kongregate.com] "Shootorial".

Either way, the shootorial goes completely in depth with what each thing does. Try going back to Shootorial #5, where it first talks about the shooting and the collision detectings.