I'm currently making an RPG game and I relly need help on making enimies who will randomly move around but when they get a certain distace close to you they attack you with a random attack. Plz help!
I'm currently making an RPG game and I relly need help on making enimies who will randomly move around but when they get a certain distace close to you they attack you with a random attack. Plz help!
At 8/8/06 11:42 AM, narutofan02472 wrote: I'm currently making an RPG game and I relly need help on making enimies who will randomly move around but when they get a certain distace close to you they attack you with a random attack. Plz help!
You know you're basically asking us to make a whole game for you ! ill give you some code to work off (a random movement script) but i'm not gona make your whole goddamn game, just learn actionscript yourself.
onClipEvent (load) {
function getXY() {
myX=random(550), myY=random(400);
speedX=(_x-myX)/200, speedY=(_y-myY)/200;
}
setInterval(getXY, 2000);
getXY();
}
onClipEvent (enterFrame) {
_x += speedX, _y += speedY;
if (_x>=550 || _x<=0) {
speedX = -speedX;
}
if (_y>=400 || _y<=0) {
speedY = -speedY;
}
}
This is really easy. You should be able to do this by yourself.
Assuming that this is tile based with square tiles...
function moveRandom() {
switch(Math.floor(Math.random()*4)) {
case 0:
//move up
break;
case 1:
//move left
break;
case 2:
//move down
break;
case 3:
//move right
break;
default:
throw new Error("Should never be reached.");
break;
}
//If occupies same space as player
//Make random attack using Math.floor(Math.random()*numberOfDifferent
Attacks)
}
And call that function for each enemy whenever they need it.
And next time, please give us a better description of your game's mechanics before asking for code.
At 8/8/06 11:52 AM, Fat_Lifeguard wrote: This is really easy. You should be able to do this by yourself.
Assuming that this is tile based with square tiles...
function moveRandom() {
switch(Math.floor(Math.random()*4)) {
case 0:
//move up
break;
case 1:
//move left
break;
case 2:
//move down
break;
case 3:
//move right
break;
default:
throw new Error("Should never be reached.");
break;
}
//If occupies same space as player
//Make random attack using Math.floor(Math.random()*numberOfDifferent
Attacks)
}
wtf dude that wont help him at all, just saying //move left. He's gona copy and paste that see it dosent work and not bother with it, your just gona put him off actionscript for life putting that gobeldy gook in his face.
uhh.. actually i'm not that clueless about actionscrip and i can tell that fat lifeguard's code is practically all comments, i know how to measure distance but im more interested in loading random frames.
At 8/8/06 02:05 PM, narutofan02472 wrote: uhh.. actually i'm not that clueless about actionscrip and i can tell that fat lifeguard's code is practically all comments, i know how to measure distance but im more interested in loading random frames.
It's hard to give people code that's definitely going to work if you don't know much about the game mechanics.
Anyway, to stop at random frames:
gotoAndStop(Math.floor(Math.random()*(rang
e+1))+min)
range being the spread of the frames (i.e. the range between 6 and 10 is 10-6, or 4) and min being the lower limit (in the previous example, 6).
At 8/8/06 11:52 AM, Fat_Lifeguard wrote: throw new Error("Should never be reached.");
please do not teach people to throw errors if you arent going to set up a try and catch first.
that is not only terrible coding habits, but you are making things complicated for new ASers.
At 8/8/06 02:58 PM, authorblues wrote: that is not only terrible coding habits, but you are making things complicated for new ASers.
Explain, AB, explain. What is throw new error?
At 8/8/06 03:02 PM, -Toast- wrote:At 8/8/06 02:58 PM, authorblues wrote: that is not only terrible coding habits, but you are making things complicated for new ASers.Explain, AB, explain. What is throw new error?
I've never heared of it myself, but it seems to be one of them things you dont need and you can just do it some other way, or else i'd have heard about it i guess. Am i right?
At 8/8/06 03:04 PM, -reelbigcheese- wrote:At 8/8/06 03:02 PM, -Toast- wrote: Explain, AB, explain. What is throw new error?I've never heared of it myself, but it seems to be one of them things you dont need and you can just do it some other way, or else i'd have heard about it i guess. Am i right?
its not unnecessary, but generally speaking, a person will never use it.
its only implimented to create an easier way to handle user-thrown errors
AS: Try and Catch by me
At 8/8/06 03:10 PM, authorblues wrote: AS: Try and Catch by me
Didn't get it :P. What is it used for?
At 8/8/06 03:18 PM, -Toast- wrote:At 8/8/06 03:10 PM, authorblues wrote: AS: Try and Catch by meDidn't get it :P. What is it used for?
I think I got it up to the vit where I got bored and stopped reading because the next bit of code looked long and scary (about halfway through). It's a method for error handling... or something?