How do you create a stack for recording movements [In fighting game]
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.
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.
In C++, you can use the STL stack or queue class; they're in the <stack> and <queue> headers respectively.
Here's some pseudo-code describing the general form of an array based stack and queue.
// A stack using an arraydatatype stack[MAX];int index = 0;// Push:ASSERT(index < MAX-1);stack[index++] = temp;// Pop:ASSERT(index > 0);temp = stack[--index];// A queue using an arraydatatype queue[MAX];int head = 0; int tail = 0;//Put:ASSERT(tail < MAX-1);queue[tail++] = temp;//Get:ASSERT(head < MAX-1);temp = queue[head++];
Dude, use the STL. It's not perfect, but it's better than writing it from scratch. [rolleyes]
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
- Goishin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement