@5: /\/\@1|\|. +3|-| 1337357 70P1C 3V@
Hi everyone, i made this a while ago but it wasnt accepted on as:main coz it wasnt detailed enough, so i decided to redo it;
as knowledge needed:
AS:Random by Spamburger
AS:Condition's and loops -BleeBlap
what it is used for:
this code is used for making enemy's come at you and when they get to you they randomly attack.
set up:
have your main character's movie clip and give it the instance name of "player"
have your enemy movie clip with this on these frames:
1. standing still
2. walking
3. jumping
4. attack 1
5. attack 2
6. attack 3
the code:
onClipEvent(load){
speed=6}
onClipEvent (enterFrame) {
if (this._currentframe==1 || this._currentframe==2 && this.hitTest(_root.player)) this.gotoAndPlay(random(3)+4);
}
if (_currentframe == 4 && !this.hitTest(_root.player)) {
this.gotoAndPlay(1);
}
if (_currentframe == 5 && !this.hitTest(_root.player)) {
this.gotoAndPlay(1);
}
if (_currentframe == 6 && !this.hitTest(_root.player))
this.gotoAndPlay(1); //this goes to and plays 1
}
if (_root.player._x>this._x) {
this._x += speed;
this.gotoAndStop(2);
_xscale=-100
}
if (_root.player._x<this._x) {
this._x -= speed;
_xscale=+100
this.gotoAndStop(2);
}
}
explaining the code:
onClipEvent(load){
speed=6}
sets the speed that the character move's at to 6
if (this._currentframe==1 || this._currentframe==2 && this.hitTest(_root.player)) this.gotoAndPlay(random(3)+4);
}
if the current frame is either 1 or 2 (this._currentframe==1 ||this._currentframe==2) and it's hitting the player (&& this.hitTest(_root.player)) this.gotoAndPlay(random(3)+4) this movieclip goes to a random frame between for and 6, thats why you have +4 on the end.
if (_currentframe == 4 && !this.hitTest(_root.player)) {
this.gotoAndPlay(1);
}
if the current frame is 4 and it's not hitting the player, the movie clip goes back to the first frame. (having an ! before a statement makes it if its NOT true)
its the same for the next 3 statements, just with different frames.
if (_root.player._x>this._x) {
this._x += speed;
this.gotoAndStop(2);
_xscale=-100
}
if (_root.player._x<this._x) {
this._x -= speed;
_xscale=+100
this.gotoAndStop(2);
}
this checks whether the _x co-ordernates of the player is above or below this's and if its either this goes to the second frame, flips and move's that direction.
I hope you learnt something from this tutorial, reply with any questions/queries