PDA

View Full Version : Flash collisions issues


coolman88
06-04-2008, 03:12 PM
Ok well were do I begin,

I am trying to make a flash game were, there is a man in a tower shooting the enemies below.
I've managed to make the guy in tower shoot but I having trouble making his bullets hit the badmen. here what i got so far.

On the gun clip the code is,

onClipEvent(load)
{
_root.shot._visible=false;
shotcount=1;
}
onClipEvent (enterFrame)
{
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
myDegrees = Math.round((myRadians*180/Math.PI));
_root.yChange = Math.round(_root._ymouse-this._y);
_root.xChange = Math.round(_root._xmouse-this._x);
this._rotation = myDegrees+90;
}
onClipEvent(mouseDown)
{
_root.shot.duplicateMovieClip( "shot"+shotcount, shotcount+7000);
_root["shot"+shotcount]._visible=true;
shotcount++;
if(shotcount>100)
{
shotcount=1;
}
}

And on the bullet(shot) the code is

onClipEvent(load)
{
if(this._name=="shot")
{
this._visible=false;
}
else
{
this._visible=true;
}
this._x=_root.gun._x;
this._y=_root.gun._y;
shotxspeed=40*Math.sin(_root.gun._rotation*(Math.P I/180));
shotyspeed=40*Math.cos(_root.gun._rotation*(Math.P I/180));
}
onClipEvent(enterFrame)
{
this._x+=shotxspeed;
this._y-=shotyspeed;
if(this._x<0)
{
this.removeMovieClip();
}
if(this._x>800)
{
this.removeMovieClip();
}
if(this._y>600)
{
this.removeMovieClip();
}
if(this._y<0)
{
this.removeMovieClip();
}
}


Now what I have is 10 movie clips of badman on the stage moving around.
what is a section of code that makes it so when the shot hits the bad guy they both disapear and once all the badman have been destroyed its redirected to another frame, say the victory screen.

Any help would be greatly appreciated.

Cheers,
Coolman