PDA

View Full Version : help with game :-\


Elbudster
01-14-2004, 08:10 PM
I need a little help with my game. I'm making a game like missile command and I duplicate the missiles that you fire and the enemy missiles that fly down. When you fire missiles it like overwrites the enemy missiles that fly down. I know it has something to do with the depth when I duplicate the two movie clips but I dnno how to fix it so that they don't overwrite eachother.

I tried searching and nothing really helped me. I tried using something like...

m++;
duplicate(_root.missile, "missile" + m, m)
e--;
duplicate(_root.enemy, "enemy" + e, e)

and that didn't really work either... I need a hitTest to work with the duplicated movie clips and I found something that I thought would work when searching but didn't :| So if anyone can help me I would greatly appreciate it :D

Heres the .fla for it...

splict
01-14-2004, 09:25 PM
Elbudster,
It is a lot better to have your code on an empty frame instead of attached to movie clips. One of a few reasons is because it is easier to organize if you have it all together - IMO.

With your movie, when you add 1 to i it becomes 2,3,4, etc. when you add 1 to e it is the same thing. so whenever e and i are equal, you are putting movieclips at the same depth - which, as you know, doesn't work.

One solution would be to use the same variable for both. Such as _root.currentDepth in place of your 'e's and 'i's. That way if a missle is attached on to 5 and then an enemy is attached it will know to go on 6.

Another solution would be to place all your missles inside of a movieclip, called missles and all of your enemies inside their own movieclip container called enemies. (I'm real creative ;))

You still have a few other problems, though, cause after I shoot 3 missles, there is so much slowdown I can't move my mouse. :(

-splict

Elbudster
01-14-2004, 10:00 PM
Thanks for the help, how do i use the currentDepth though? Like duplicateMovieClip(_root.missile, "missile" + _root.currentDepth, _root.currentDepth) ? Sorry for my stupidity :P

Also, any ideas on the hit test thing?

Marz
01-14-2004, 10:07 PM
I'd suggest making the variables and depths like the such...

Your one loop could go from 0 - 500 and the other from 501 to 1000

if(m > 500){m=0;}else{m++;}
if(e > 1000){e=501;}else{e++;}

And that's all there is to it man... The chance of you having 500+ shots onscreen is very unlikely.

splict
01-14-2004, 10:09 PM
Your one loop could go from 0 - 500 and the other from 501 to 1000even better... of course ;)

Elbudster
01-14-2004, 10:17 PM
w00t thanks a lot Marz. How would I go about doing the hitTest on these movie clips now :S

Marz
01-14-2004, 10:25 PM
It's a complicated procedure at times..

First off... I just have some small questions...

1. Do you want the missles to be able to cancel each other out?

2. WHat version of Flash are you using.

I'll gte back to you later on possibly.

Elbudster
01-14-2004, 10:30 PM
k :)

When missile and enemy collide I want missile to play a little animation im going to add. When the two first collide I want enemy to be removed and once missile's new animation has finished playing that be removed as well.

Im using flash mx.

I really appreciate the help btw :D

junahu
01-15-2004, 08:03 AM
hmm...

The hitest shouldn't be too hard, assuming you did the earlier suggestion of spawning the missiles and enemies into separate movieclips. But of course I don't know that. Did you?

Elbudster
01-15-2004, 05:22 PM
Umm, I'm kinda confused... What do you mean by that junahu :S

junahu
01-16-2004, 07:37 AM
Originally posted by splict
Elbudster,

Another solution would be to place all your missles inside of a movieclip, called missles and all of your enemies inside their own movieclip container called enemies. (I'm real creative ;))



In this way you can have each missile hitest the movieclip enemies (e.g. _root.enemies.hitTest(_x,_y,true)) rather than having each missile hitest each enemy

The origin of the movieclip missiles has to be 0 though, otherwise you'll be hittesting the wrong coordinates which is rarely a good thing.

Elbudster
01-16-2004, 05:31 PM
Ok, now I feel retarded... :| Movie clip containers? Do you mean like a layer for them or...?

Sorry for my stupidity :-\

Marz
01-17-2004, 01:46 AM
HEre you go man... It's quite allright to have code inside of your missles... As in our case.. The missles won't have too much code.

in the player's bullet movieclip



on(enterFrame)
{
// move missle up.. or left or however you have it

if(this.hitTest(_root.enemy))
{
_root.enemy.gotoAndPlay("death");
}
}



Now.. if you have multiple enemies... Have a variable in the main movie part (main frame that loops) hold the number of enemies currently on screen. Keep those enemies numbered in a certain way so that they can be accessed through means of enemy0, enemy1, enemy2, etcetera....



on(enterFrame)
{
// move missle up.. or left or however you have it

for(i=0; i<_root.numEnemies; i++)
{
if(this.hitTest(_root["enemy"+i]))
{
_root["enemy"+i].gotoAndPlay("death");
}
}
}