# Desperate for help - can't let this defeat me

**URL:** https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468
**Category:** Uncategorized
**Created:** [May 21, 2003, 9:43pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468 "2003-05-21T21:43:22Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ivcho](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@ivcho](https://forum.kirupa.com/u/ivcho)
#### Post date: [May 21, 2003, 9:43pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/1 "2003-05-21T21:43:22Z")

</div>

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](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&gt;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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 21, 2003, 10:06pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/2 "2003-05-21T22:06:01Z")

</div>

thank you… that seems like a great link… hopefully i’ll be able to find what I want on it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 21, 2003, 10:07pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/3 "2003-05-21T22:07:51Z")

</div>

i’m guessing you deleted your post cause I sure don’t see it anymore…heheheh

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 21, 2003, 10:13pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/4 "2003-05-21T22:13:42Z")

</div>

hmm… here is some pseudo code for you  
untested but maybe it will help

if (this.\_droptarget.indexOf(“rock”)!=-1)  
telltarget(this.\_droptarget){gotoAndPlay(“explode”);}

it does use deprecated features of flash though

(\_droptarget is a string, so you have to use telltarget to get at the object)

its a challenge to comeup with alternatives to hitTesting every rock, every frame (CPU nightmare).

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 21, 2003, 10:14pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/5 "2003-05-21T22:14:31Z")

</div>

i changed my mind because it wasnt the link i thought it was  
but it is a great page

> **[Yahoo Small Business - Cheap Domains, Web Hosting, Website Builder, Ecommerce...](https://smallbusiness.yahoo.com/)**
>
> Yahoo Small Business Offers Cheap Domain Names, Web Hosting, Easy Website Builder, Business Email, Local Listings, and Ecommerce Solutions for Your Small Business.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 21, 2003, 10:16pm UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/6 "2003-05-21T22:16:04Z")

</div>

thanks again… i’ll try your example and read the site

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 22, 2003, 1:33am UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/7 "2003-05-22T01:33:50Z")

</div>

Here’s a thought, have each rock add it’s name to an array, then have each bullet hittest against the array. but i’m not quite sure where to go from there.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 22, 2003, 1:49am UTC](https://forum.kirupa.com/t/desperate-for-help-cant-let-this-defeat-me/21468/8 "2003-05-22T01:49:29Z")

</div>

that’s something I thought about but as clownstaples said this will still need to be done every frame to detect collision… and considering it’s 40fr/sec and I have to loop through the whole array of current rocks it will still be a CPU nightmare :)…

but I’ll try it later on and let you guys know how it went.

thank you for trying to help
