Sign in to follow this  
banhminds

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

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this