I've been working on this game for a while now, and I've gotten most things to work. I have the health bar working, the game over screen working, and have it so it's fairly easy to move in the levels, but I'm having some trouble with my enemies and attacking them. http://frost-skyder.deviantart.com/art/Termination-116498169? I was wondering if anyone could help me fix a few issues. That's not the entire game (that would be horribly boring), but some of my script I've been testing, so far, some issues have come up.
First Issue:My character won't follow through on his attack move. I know it only recognizes when the Space bar is down, but I want to find a way so the animation finishes, even if the button is not being pressed.
[quote="Main Scrip on Main Character Movie Clip"] //Main Character's Movement onClipEvent(enterFrame){ if(_root.Health<=0){ _root.gotoAndPlay("GameOver"}
[quote="Script on Attack Move"] //Main Character's Code on Attack Movement onClipEvent (enterFrame) { if(_root.Skyder.hitTest(_root.Npc1)){ _root.Npc1.gotoAndPlay("Npc1 Die"}[/quote] That's what I've got for now, and it seems to work fairly well. The Attack move is what kills my npc, I just wish the animation would follow through.
Second Issue:My enemy just sits there....I don't know any script for programming him to run up to my character when he's a determined pixels apart. I've heard of "A*" script, but don't understand it at all, or know how to use it.
[quote="Npc Movement (Keeps him with the background)"] //Npc1's Movement onClipEvent (enterFrame) { if(Key.isDown(Key.RIGHT)){ this._x-=15 _xscale =60; }else if(Key.isDown(Key.LEFT)){ this._x+=15 _xscale =60;}
}[/quote] [quote="The Enemy's Attack"] //Npc1's Attack Movement onClipEvent (enterFrame) { if(_root.Skyder.hitTest(_root.Npc1)){ _root.Health -=1;} }[/quote] That's about where all my problems lie. All my other script is working just dandy. If anyone has any suggestions, or some advice, I'd be thrilled to hear it. I've been stuck on these problems for a while now.
Take out the else{ gotoAndStop() } and put _parent.gotoAndStop() on the last frame of every animation.
For the npc, you'll have to do something like: if(x < playerX - playerWidth/2 - width/2) x += speed else if(x > playerX + playerWidth/2 + width/2) x -= speed }
Firstly, what Bluydee said...your link doesn't work. Please fix that.
Alright, I'm not the world's best programmer but I've still got SOME experience under my belt, so I'm gonna try to help.
Alright, here's your code (with indents added):
Main Scrip on Main Character Movie Clip wrote: //Main Character's Movement onClipEvent(enterFrame){ if(_root.Health<=0){ _root.gotoAndPlay("GameOver" }
First off, go up to your onClipEvent(load) statements and add var attacking = false;
Then, change your above code to:
Main Scrip on Main Character Movie Clip wrote: //Main Character's Movement onClipEvent(enterFrame){ if(_root.Health<=0){ _root.gotoAndPlay("GameOver" }
if(Key.isDown(Key.RIGHT)){ this.gotoAndStop("Run Right" this._xscale =100; }else if(Key.isDown(Key.LEFT)){ this.gotoAndStop("Run Right" this._xscale =-100; //I removed your SPACE line } else if(Key.isDown(Key.DOWN)){ this.gotoAndStop("Duck" }else if (attacking == false) { this.gotoAndStop("Idle 1"} }
//This allows ducking/running to interrupt attack if (attacking == true && this._frame != "Attack 1" { attacking = false; }
So, now, attacking is a variable that determines when you are...um...attacking (<- Not a humor attempt...just clumsy typing and me being too lazy to hit BackSpace). If you aren't attacking, you go to idle position. Otherwise, you stay in attacking poisition.
Alright, for the final piece, you need some code that makes it so that, at the end of the attacking animation, it goes back to the idle frame. To be safe, it should also set "attacking" back to false. I don't know your MC setup, so you have to code it yourself...just, it might be helpful to know that _parent (similar to _root) lets you scope to the properties of the object holding the current movie clip.
I hope that helps your first problem!!
Fun fact: this, as far as I can tell, is a useless command!
I'll help with second problem later...nanerpuss ; )
...wait...I don't think i understand what you mean. Could you please expand?
He means that this guy has an individual MC animated for each state of the player. Each of the player MC's frames contains the appropriate MC. gotoAndStop() navigates to the frame, and the animated mc plays when the playhead is put there.
Thanks for the help you guys, I really appreciate it. Sorry it took so long for me to respond. [url=http://frost-skyder.deviantart.com/art/Termination-116498169?loggedin=1] This is the fixed link. I can't seem to find out how to edit posts on here, so I'll just slap it up now.
[quote="dank"]Take out the else{ gotoAndStop() } and put _parent.gotoAndStop() on the last frame of every animation.[/quote] Tried this, and it doesn't seem to work...I may be misunderstanding where to put it. I also tried the npc text and I end up with errors. I'm not very skilled in AC 2, so I'm not sure what's causing it to backfire.
I also tried Programpro's idea, but for some reason my script keeps complaining that it's not on the event handler. Any suggestion on how to fix that?
[url]=http://frost-skyder.deviantart.com/art/Termination-116498169?loggedin=1[/url] ...Okay, now it may work. =/ Sorry I keep messing up the link, I keep doing silly typos.
I'd delete my last post because it's void now, but I still haven't figured that out. Anyway, I got the event handler to stop complaining, but now he won't attack at all, the space key is completely ignored. It kept saying "'else' encountered without matching 'if'" so I placed my script like so:
I hope this isn't considered bumping, but I've worked on the game a bit more, and solved a few issues. I still have the issue where I cannot get my npcs to chase the main character though. [url=http://frost-skyder.deviantart.com/art/Termination-116498169] I've got basically everything to work besides the npcs' chase mode.
One npc I have though seems to be causing a few issues. The C-16 fires projectiles, but my programming isn't working.
At first I tried this:
I wrote it on the charater, which was dubbed Npc2, and the projectile in one of his actions Bullet. Unfortunately, it's not working. Then I tried by writing it on the projectile, which also didn't work.
Any suggestions? I've tried Kirupa.com and there's not much there that seemed to help.
http://frost-skyder.deviantart.com/art/Termination-116498169 Sorry, still suck at posting links for some reason, but this is a similar version to what I'm working on now.
Would it just be better to post the fla file so the actual programming can be messed with, or should I just only post a link to the swf version?