PDA

View Full Version : need help removing coliding mcs



archmage_flash
May 5th, 2007, 07:27 PM
I have a game I am working on where i need colliding mcs to be destroyed on contact with each other I have this code on the bullet mc

onClipEvent (enterFrame) {
for (i in _root) {
if (_root[i]._name.indexOf("newbaddie") != -1) {
if (this.hitTest(_root[i]) && _root[i]._currentframe != 11) {
///is destroyed on 2th frame of this mc
this.gotoAndPlay(2);
}
}

}}

and this on the baddie mc

onClipEvent (enterFrame) {
for (i in _root) {
if (_root[i]._name.indexOf("newdupe") != -1) {
if (this.hitTest(_root[i]) && _root[i]._currentframe != 11) {
_root.combo++;
_root.score+= _root.combo;
this.removeMovieClip();
}
}
}
}


So I need some advice on how to get rid of em both on contact because they sometimes don't both get removed.
Thanks:bucktooth:


PS: A link to the game is here: http://img297.imageshack.us/my.php?image=mygamethingprototypetesvf9.swf

npgames
May 6th, 2007, 12:29 PM
for the bullets, i would try setting the frame the deletion code takes place, in frame 3, so it has one more frame to delete the enemy and then delete

archmage_flash
May 6th, 2007, 12:43 PM
for the bullets, i would try setting the frame the deletion code takes place, in frame 3, so it has one more frame to delete the enemy and then delete


Actually the remove mc code for the ball is on frame 5 so your solution wont workk

and also I tryed putting it on frame 3 as well.

npgames
May 6th, 2007, 12:46 PM
beats me then

Sirisian
May 9th, 2007, 03:42 PM
I'd just create a bullet class with a pos : point and a vel : point for the velocity then iterate the array and render all of them to a MC or the root. Use the x and y values to perform the hitdetection by either using the distance formula:
if(Math.sqrt((x-object.x)*(x-object.x)+(object.y-y)*(object.y-y)) < radius+object.radius){//hit}
or by using SAT with AABB:
if(x>object.x && x<object.x+object.width y>object.y && y<object.y+object.height){//hit}
in both cases object would be the object that is being hitdetected. Not sure how far you are into game programming, but there are other ways, such at rays which are far superior.

Another thing to mention when creating your bullet, you can place it at the end of your barrel by using:
bullet.x = anchorPointOfTheturret.x + Math.cos(angleOfTheTurret)*lengthOfTheTurret
bullet.y = anchorPointOfTheturret.y + Math.sin(angleOfTheTurret)*lengthOfTheTurret

I don't use movie clips when I program games in flash, so meh.

Sirisian
May 9th, 2007, 06:05 PM
Okay, I spent a few minutes and made this:
Sorry for double posting, just wanna make sure you see this.

clicky (http://www.sirisian.templarian.com/flash/TurretGame.htm)

Here's the source, have fun with your game!

clicky for the source
(http://www.sirisian.templarian.com/flash/TurretGame.zip)