I’ve been trying to figure this out for a very long time now and as you can see I still haven’t…
first… here’s a link to the first part
http://www.bgidesign.com/flashgames/shooting.html
pretty simple… rocks flying through space… if they touch your ship you’re dead… onPress fires a shot… if your shot hits one of the rocks something happens.
now the problem is…
It’s easy to detect when a “ROCK” hits the “SHIP” because the ship is one object and can be done with collision detection using hitTest method inside the “ROCK” movie clip…
but as I mentioned I want to see if my shots hit one of the rocks… and here’s the big BUT…
all my rocks are randomly generated like this:
duplicateMovieClip(_root.star, “star”+i, i);
duplicateMovieClip(_root.star2,“star2”+i,i+1);
where “star” and “star2” are just ugly circles converted to MovieClips and named that.
this is where the problem occurs… if I was to check for collision detection between a “BULLET” and “STAR” or “STAR2” I would only be able to do it for the initial movie clip and not the duplicated ones because their name changes as they are duplicated and become star200…star201…star202 etc…
I have tried a LOT of things but I don’t seem to be able to figure out a programmatic way of working around this…
I would really appreciate your help even if it’s just a thought… maybe it’s something small that I could do different and make it work
just for reference here is the code… maybe it will help you help me… hehe
Main Timeline Frame 1
Mouse.hide();
startDrag(_root.shooter, true);
SHIP - referred to as “shooter” in the code
on (release) {
_root.fire = 1;
_root.i += 1;
duplicateMovieClip(_root.bullet, “bullet”+i, i);
}
BULLET
onClipEvent (load) {
this._visible = 0;
if (_root.fire == 1) {
this._x = _root.shooter._x;
this._y = _root.shooter._y;
}
z=0;
zspeed=0.9;
fl=10;
}
onClipEvent (enterFrame) {
if (this != _level0.bullet) {
if (_root.fire == 1) {
this._y -= 10;
this._visible = 1;
}
if (this._y<0) {
this.removeMovieClip();
}
}
scale=fl/(fl+z);
_xscale=_yscale=100*scale;
z+=zspeed;
}
STAR
onClipEvent (load) {
this._x = Math.random()*680 + 10;
this._y = 0;
z=0;
zspeed=1;
fl=100;
}
onClipEvent (enterFrame) {
if (!_root.dead){
if (this.hitTest(_root.shooter)) {
xd = _root.shooter._x;
xy = _root.shooter._y;
_root.hit._x = _root._xmouse;
_root.hit._y = _root._ymouse;
_root.hit._visible = true;
_root.hit.gotoAndPlay(2);
Mouse.show();
_root.shooter._visible = false;
_root.dead = true;
}
}
this._y += 5 - (_root._ymouse/500);
if (this != _level0.star) {
if (this._y>520) {
this.removeMovieClip();
}
}
scale=fl/(fl+z);
_xscale=_yscale=1000*scale;
z+=zspeed;
}
CONTROLLER / DUPLICATOR
onClipEvent(enterFrame) {
i+=1;
j+=1;
if (j/5 == 5) {
duplicateMovieClip(_root.star, “star”+i, i);
duplicateMovieClip(_root.star2, “star2”+i, i+1);
j = 0;
}
}
Thank you kindly in advance