Jump to content
  • Advertisement
Sign in to follow this  
banhminds

How do you create a stack for recording movements [In fighting game]

This topic is 4063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As the subject is written. How do you create a stack for recording, reading, what actions has been used, as in what buttons has been pressed, etc... Record the button pressing? In an array? I'm wondering how to do this.

Share this post


Link to post
Share on other sites
Advertisement
I think you might want to use a queue rather than a stack for this.

In C++, you can use the STL stack or queue class; they're in the <stack> and <queue> headers respectively.

Share this post


Link to post
Share on other sites
Here's some pseudo-code describing the general form of an array based stack and queue.


// A stack using an array

datatype stack[MAX];
int index = 0;

// Push:
ASSERT(index < MAX-1);
stack[index++] = temp;

// Pop:
ASSERT(index > 0);
temp = stack[--index];

// A queue using an array

datatype queue[MAX];
int head = 0; int tail = 0;

//Put:
ASSERT(tail < MAX-1);
queue[tail++] = temp;

//Get:
ASSERT(head < MAX-1);
temp = queue[head++];



Share this post


Link to post
Share on other sites
Dude, use the STL. It's not perfect, but it's better than writing it from scratch. [rolleyes]

Share this post


Link to post
Share on other sites
not only that, but an array-based approach limits the number of commands you can have. Think of the complex joystick movements that fire off characters' secret moves. You run the risk of overloading your array. I would go with the stl queue.

- Goishin

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!