Advertisement

animating query

Started by August 20, 2001 06:42 PM
1 comment, last by Ferinorius 23 years, 6 months ago
ok, im having some stubborn trouble. I know i can do this, but i am at a roadblock, or programmers block or something. my game consists of a lot of states in a huge finite state machine. one of these states is for animating the player. in this state, all i want to do is increase the player's x for a 100 pixels, animate the attack, then move him back. here is some psuedocode i have in my game:


state == ANIMATE_PLAYER1 {

//PLAYERPOSITION is a var that holds where in the animation
//we are

if (PLAYERPOSITION == 1) {
	player1 position --;
	DRAW_CHARACTER_HERE;
	if (player1 position > 400) {
		ANIMATE_ATTACK;
	}
	else {}
}
else {
	player1 position ++;
	if (player1 position < 500) {
		PLAYERPOSITION = 1;
		return to the state we were at before the attack
	}
	else {}

}

//exit the state where we animate player one
}

  
if this is hard to read, or if i am totally and utterly stupid, then let me know how i can make this work. i want to move the character from 500 pixels to 400 pixels and back, while not disrupting the rest of the animations with a for or while loop. Neo-Toshi - The City That Never Sleeps Edited by - Ferinorius on August 21, 2001 4:58:10 AM
There are probably a billion ways to do this and I''m not sure mine is the best, but one way would be to keep an animation flag for the player which determines whether or not the animation is currently playing (or you could have it 0 or -1 for no animation, and anything above that would indicate which animation is playing, if you have more than one animation). Then you also must keep track of the current frame of animation for the player. After you move the player 100 pixels, set its animation flag to 1 or however else you want to do it. Then, in your game loop, check to see if the animation is playing (meaning the animation flag is 1), and if it is, increase the animation frame every so many milliseconds. After the animation is done (the current frame of animation reached the total number of frames in the animation), move the player back 100 pixels and turn off the animation flag.

I don''t know if you really need a state just for an animation, since the animation is supposed to happen at the same time as everything else.
Advertisement
I think my above post made it confusing as to what my problem was. My problem is that while in the animate player state, it WONT move 100 pixels, at all. I just wondered if there was something wrong with the code or what not. Oh well. I will try that internal counter stuff and see if it works. I have an idea on how to do that.

Neo-Toshi - The City That Never Sleeps

This topic is closed to new replies.

Advertisement