|
-
Enemy Troubles...
I made an enemy movie clip with all the AI and everything in it. The problem I'm having is that in Flash 5 you cannot removeMovieClip() a movieclip unless it's duplicated, but my movieclip is not duplicated, and I can't find a way to duplicated it without having it still attack the player's MC.
You can see and play it here: http://reversemonster.com/albums/alb...me_Scene_1.swf
Controls:
arrowkeys move you around
Tab/Shift move you on the z-axis (kinda)
control lays a bomb down
when you play it you'll see that when the enemy's life gets to 0 he doesn't dissapear, that's because he's not a duplicated MC so I can't remove him.
-
Senior Member
Have you tried
this.swapDepths(1000);
this.removeMovieClip();
-
Didn't do it.
Hey, Wattz.
Let me guess; you have an instance of the enemy on _root with an instance name of "enemy" or something like that. You use a for loop to duplicate it and removeMovieClip to make the duplicates dissapear when they are defeated, right?
In the code you have in the "enemy" instance that makes it attack the player, just wrap everything in an if statement like so:
Code:
if (this._name != "enemy){
// attacke code here
}
This way you can run your for loop to duplicate the enemy, giving it another instance name. Then the attack code will run because its name will not be "enemy", and it can be removed because it is a duplicate MC.
If I've made any incorrect assumptions in the above, let me know, but this should solve your problem.
hth
japangreg
Hush child. japangreg can do what he wants. - PAlexC
That was Zen - this is Tao.
-
Well I tried that if statement and it kept the root MC from attacking, but then I added an else on to it so that if it WAS _root.atom1 (the root enemy's name) then it would make a duplicate of itself.
So it makes a duplicate, but the duplicate won't move. I've tried debugging and it shows that there's a new MC and it's name isn't atom1, but the new MC won't move. Then I tried taking the for-loop off of the duplication and it created a ton of MCs that didn't move, but they were each placed in a position like they were chasing the player. That's kind of hard to explain...
Code:
} else {
for(i = 2; i <=doop; i++) {
duplicateMovieClip(_root.atom1,atom+i,doop);
}
}
thats the for loop i'm using now. As of right now it creates one MC called "level0.5" but the MC won't give chase. Sooooo...
I have no idea what's wrong.
-
Didn't do it.
Hey, Wattz.
Alright, let's see if we can get this straightened out... by the way, I like the concept of your game so far. It should be pretty fun once all the kinks are worked out.
First off, what's the general concept you want in terms of the computer attack pattern? Do you want multiple enemies on the stage at one time that regenerate as soon as they are destroyed, or a set number that once they are removed from the play field don't return? Or are you looking to do only one enemy that regenerates?
The reason I ask this is because I'm trying to understand why you put the duplication code in the onClipEvent(enterFrame) handler for the enemy MC. Because you are using a for loop, I'm assuming you want multiple enemies on stage at the same time. If this is true, you really only need to run the duplication code once, so there's no need to put that in an enterFrame event.
Here's my suggestion: move the duplication code to either the load event for the MC or to a frame action (frame action would most likely be best)
Also, it appears as if your duplicate script is a bit buggy; take a look at the for loop:
Code:
for(i = 2; i <=doop; i++) {
duplicateMovieClip(_root.atom1,atom+i,doop);
}
The arguments for the duplicateMovieClip function are original name, new name, depth. The first you have specified is fine as it is always the same MC being duplicated. The second in also fine because it uses the i variable to alter the instance name. The third is the problem; doop is not altered in your for loop, so each duplicate is being placed on the same depth. When you duplicate an MC to a depth where another MC resides, the old MC is destroyed and the new one takes its place.
That should be changed to something like:
Code:
for(i = 2; i <=doop; i++) {
duplicateMovieClip(_root.atom1,atom+i,doop + i);
}
Give this a try and let us know if it solves the problem.
hth
Hush child. japangreg can do what he wants. - PAlexC
That was Zen - this is Tao.
-
sorry for the late reply. I lost my connection to the net for 36 hours.
What I did while I was stuck offline was kinda... by-passed the duplication code all together. I took it all out and decided to make a different level on each frame and copy/paste _root.atom1 and change it's name to atom2, and in other levels when there are more and more enemies atom3,4,5, etc...
But now my problem is with changing frames. I have two different if statements that will send the player either to the next frame (which is the next level) and the other sends the player to the game-over scene. But neither seem to work.
Code:
if (_root.atom1.i >= 10){
nextFrame();
} else {
if (value < 1) {
gotoAndPlay (3);
} else {
//AI coding here
}
To me, it should work. Try out the game to see what happens when either _root.atom1.i (consumptions) = 10 or when _root.atom.value (essence) is below zero. The if statements are located in the onClipEvent(enterFrame) of _root.atom and in _root.atom1.
I tried re-locating the statements into the frame but the game wouldn't start at all. Also, in each level frame the only action is "stop()" to prevent the scene from playing through all the frames and skipping levels. When I removed "stop()" from the frame, the game did some wierd things... So I don't think removing it is an option.
Does anyone know what could be going wrong?
Here's the game now: http://reversemonster.com/albums/album58/game_001.swf
Thanks for all your help!
-
Senior Member
code:
if (_root.atom1.i >= 10){
_root.nextFrame();
} else {
if (value < 1) {
_root.gotoAndPlay (3);
} else {
//AI coding here
}
-
Senior Member
you can also use "unloadMovie" .. i use it also for my enemys ..
another question .. where did you insert the AI code for the enemys? .. i used an "onload" event to initalize the enmy where i give health, states ect. and then an "onenterframe" code .. so i onlly must copy paste the mc to make more enemys or just duplicate it ...
here is the URL to my projectthread ..
http://www.flashkit.com/board/showth...hreadid=463413
when you have more questions .. ask ..
-
Didn't do it.
Hey, Wattz.
Okay, the situation has apparently changed, so let me see if I'm still up to speed here: You now have several frames in your movie, each with a stop() action in them. In each frame, you have copies of your enemy MC each with a unique instance name (i.e., "atom1" in the thr first frame, "atom2" in the second, and "atom3" and "atom4" in the third) You should put the player's MC in it's own layer and stretch it across all of the level frames.
Now, if this is true, you should put the code to check the score/damage in an onClipEvent(enterFrame) handler on the player's MC (not sure what instance name you have given this, but for the moment let's assume it's "player")
So, in the actions panel for player, you could have something like this:
Code:
onClipEvent(load){
score = 0;
}
onClipEvent(enterFrame){
if (score == _root.target_score){
_root.nextFrame();
}
if (_root.value < 1) {
_root.gotoAndPlay ("gameOver");
}
}
In this example, you would need to declare "target_score" in each frame as the number of "atom"s you want to have destroyed before progressing to the next level. So target_score could be 1 in the fist level, 2 in the second, etc. I don't know what code you are using to modify your score variable (I think it's i, but I'm not sure what you mean by consumptions) but if you alter it to change the score variable in the "player" MC, it should work.
The problem is that in each level you want to have a different quota that the player must achieve to progress to the next level. Using the code you have, once _root.atom1.i reaches 10, then _root will continue to advance each frame because it will always evaluate as true.
To correct this, you need to have a different quota for each level, hence the _root.target_score variable. But remember, because player.score is always increasing, _root.target_score must take into account the score earned from earlier levels, so if you need a score of 10 to progress to the second level, the target_score on level 2 must be higher than 10 or the movie will just begin to advance uncontrolably.
hth
japangreg
Hush child. japangreg can do what he wants. - PAlexC
That was Zen - this is Tao.
-
http://reversemonster.com/albums/album58/game_001.swf
Alright here it is. This is it in it's damn-near-done stage. All that's left really is typos, maybe a change to the layout, and MAYBE a background image. Not sure what would be good for one.
I just wanna thank you all for your contributions, they helped me figure it out A LOT!
-
I have a new problem!
Whenever I publish the movie, the game won't play right once you get to level 2. Level 1 works fine, but when you get to level 2 then the bombs won't duplicate and the upgrades won't either.
But here's the kicker: When you test only the scene with the game in it, all the levels work perfect!
Is Flash doing something? I checked every scene for "overlapping" variables and things that might keep the duplications from happening but I can't find anything.
Should I convert all the scenes into frames and put them all into the game scene? I think that might be the only way to fix it. Does anyone have any ideas?
-
Senior Member
Scenes are only useful if you dont use any actionscript. As soon as you have statements like gotoAndStop("someframe"), its better to get rid of scenes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|