View Full Version : New here and messed up already.
Z Hero
03-16-2008, 02:25 AM
"Yoh, I'm new here, and I've had Adobe Flash CS3 for...4 weeks, I think. Anyways, working on a game and, as all the sites and tutorials say, the hardest part is AI. Anyways, I've decided to take a different approach to it, one noted in the Megaman Zero games. Anyways, here's my code.
onClipEvent(enterFrame){
tx = this._x; //The enemy's x
mx = _root.char._x; // the main character's x
rx = tx - mx; // The enemy's x minus the character's x
}
onClipEvent (enterFrame) {
tx = mx - 10; //When this frame appears, go to the Main character's x and stay there.
}
What I wanted that to do was make the frame that it was on AND the frames after it to move where ever the main character is (char) -10 on the x axis. But for whatever reason, it doesn't work.
Also, can anyone link me to a site where I can test my game? I've tried swfup and image shack, the sounds don't come up.
Thanks in advance - Z Hero"
I made this topic in the wrong forum, so I made it in here. Sorry. Anyways, help is appreciated.
drumn4life0789
03-16-2008, 05:26 AM
can i give you one little piece of advice. Instead of using variables like tx mx and rx. use actually words that mean something. It makes your code alot easier to debug. like tx could be position while mx could be origPosition, and rx could be diffPosition.
it would help out alot.
Z Hero
03-16-2008, 05:30 AM
That completely lost me. I'm still a beginner, but I'm not for starting off small. Could you explain a bit better as to what the code should be instead of that?
bluemagica
03-16-2008, 08:08 AM
Well Z Hero, drumn4life0789 just meant that you should name your variables with words so that we can understand what they are for .... like you named a variable tx , we dont know what is tx actually representing in game.....this is why you should use comments too...
Anyway, i am not sure bout this, but you are first setting tx to the value of this._x, so tx is say 50, but when you put a new value in it,that value is being assigned to tx, and not this._x....get it? moreover, on each enterframe, tx is being reset to the "this"'s x position....(i hope i knew what character you have reffered to with "this")....anyway, to make it work you should do this._x=mx-10 ; Also remember, this._X will only work if you are calling it from within the current object, otherwise, you should use full path.
Z Hero
03-16-2008, 02:54 PM
Well, there's not much other code to it, so if you think I should do an entirely different method of coding but with the same result, I'm all for it.
Z Hero
03-16-2008, 06:52 PM
Okay, how about if this is a counter attack? Like, say the hero attacks the enemy, the enemy health would go down, and he'd dissappear and reappear behind the hero and attck, then go back to his original position.
Or something like that, if I can get this done right, I can do the coding for the other moves myself. My weak point is AI.
Maybe you could store the enemy's planned moves in an array. Each "move" is an object with two functions, the movement function and the condition function. Every frame, it executes the movement function once. It tests to see if the condition function is true, and if it is, it shifts this "move" off the array so it will start the next move.
In this case, the movement function moves the enemy behind the player, and the condition function tests to see if it has arrived at that position. When the enemy is hit, you push this "move" onto the array.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.