View Full Version : starting AI
itsmario
February 11th, 2007, 01:33 PM
i want to make a game where the char walks from side to side on the screen and shoots enemies, who come from the sides.
how do i make the enemies come from the sides randomly and attack?
SacrificialLamb
February 12th, 2007, 02:51 AM
i would have some thing like this
t=0
onEnterFrame = function() {
t++
if (t==0){
nme = _root.attachMovie(thing , "thing"+i)
si = random(2);
nme._y = random(Stage.height-100)
if (si==1){
nme._x = -100
nme.onEnterFrame = function() {
this._x+=10
//other code on the enamy
}
} else {
nme._x = Stage.width+100
nme.onEnterFrame = function() {
this._x-=10
//other code on the enamy
}
}
t = 4 + random(20)
}
}
SacrificialLamb
February 13th, 2007, 01:07 AM
That code I gave you did not work. I had coded it in notepad and it was only an idea. This code I have tested. If you make a MC and make the linkage name thing it should work
t = 0;
//makes t 0
i = 0;
//makes i 0
onEnterFrame = function () {
if (t == 0) {
//chekes to see if t is == to 0
nme = _root.attachMovie("thing", "thing"+i, 100+i++);
//"thing" is the linkage name
//"thing"+i the new name given to the attached MC
//100+i++ is the depth (the ++ at the end add's one to i) i start with 100 so aas to not over wirhgt other MC that you may have
//also makes "nme" == the name of the new movie clip (for ther first one it is "_root.thing0")
si = random(2);
//genirated a random number that is 0 or 1 (1 also == true)
nme._y = random(Stage.height-100);
//set's a random y valu that is betwen the top of the Stage and 100 of the bottom useing a var "nme" of the new MC name
if (si) {
//with 1 == true this is the same as "si==1"
nme._x = -100;
//this is a posishon to the left of the stage (should be out of sight)
nme.onEnterFrame = function() {
//this is a new onEnterFrame for the enamy i used the var "nme" of the new MC name so flash sees it like "_root.thing0.onEnterFrame = function() {"
this._x += 10;
//this makes it move right (on to the Stage)
if (this._x > Stage.width+100){
//this will see if the MC is off the other side of the Stage by 100
this.removeMovieClip()
//this will remove the MC
}
//other code for the enamy can go here
};
} else {
nme._x = Stage.width+100;
//this is a posishon to the right of the stage (should be out of sight)
nme.onEnterFrame = function() {
//this is a new onEnterFrame for the enamy i used the var "nme" of the new MC name so flash sees it like "_root.thing0.onEnterFrame = function() {"
this._x -= 10;
//this makes it move left (on to the Stage)
if (this._x < -100){
//this will see if the MC is off the other side of the Stage by 100
this.removeMovieClip()
//this will remove the MC
}
//other code for the enamy can go here
};
}
t = 4+random(20);
//this will make up a new time a betwen 4 and 23 frames (time will very depending on your FPS)
}
t--;
//removes 1 form t
};
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.