Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Squall Darken

Managing Game States in Windows

This topic is 5698 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

Hello, i''m reading the Tricks of the Windows Game Programming Gurus and starting to program apps on my own. I know all about the switch statement for the game states in my functions that processes game logic. All I''m trying to do is start the game in a menu, which is simple. There will be a button where it switches to another display, where it is a simple ball going aroundin a window. I''m having trouble figuring out how to change the content of my window with the GDI. What''s the best way ? I want to be able to trigger the menu anytime and adapt the content of my window. I thought about deleting every DC button related to my menu and then update the window with my ball roaming around.. Is there a better way ? Like "buffering" somehow my menu and popping it in my window when it''s activated by the switch ?? Thanks, Squall Darken

Share this post

Link to post
Share on other sites
Two solutions:
- Your own GUI system (pain in the ass)
- Have only a title screen where the players must press a button to go to a different state of the game.

- Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda

Share this post

Link to post
Share on other sites
Im having the same diffuculties. How does one manage the various states, from startscreen, to optionsscreen, to ingamescreen, to ingameoptionsscreen etc......, and here is where Im at, maybe this will help you :

I store the states in a linked list. There is a controller class that can push() or pop() states onto / out of the stack. It works great, for a simple expierment I made a blank window, when you push the left mouse button, it pushes a "state" onto the stack and a MessageBox() pops up telling you "state x has been pushed onto the stack", and when you push the right mouse button it pops the topmost state and gives you the appropriate message. If theres no states left, it terminates.

Heres where Im stuck: How can something in the linked list point to a "state"? Ive been trying to define a generic state and inherit from it to make the other states, and make the state pointer (in the linked list) point to the various states.

I think I just need to sit down with a gallon of coffe and hash out the logic of it all. If I get something to work, I may post it.

The book "programming role playing games with directx" covers this, but in my opinion, VERY poorly.


Share this post

Link to post
Share on other sites
Defining your own GUI - for example with OpenGL code - isn't really thát difficult. I've been developping one on my own for my game and it's a lot more easier then I thought.

This is a sample of a button class:

      #define BUTTON_STATE_INACTIVE   0



class CGUIButton
CGUIButton(CGUIWindow *window, string caption, const int x, const int y, const int sizex, const int sizey);
bool DoActions(POINT mousePos, bool leftClick, bool rightClick, bool leftUp, bool rightUp);

int placeX1, placeY1, placeX2, placeY2;
int placeInWindowX, placeInWindowY;
int sizeX, sizeY;
void Render(const int state);
void UpdateCoordinates();
bool bDownState;
CGUIWindow *parentWindow;
string captionText;

And this is how you use it:

CGUIButton Button1(&Window, "Testbox level", 45, 90, 110, 20);

void Render()
if (Button1.DoActions(mousePosition, leftClick, rightClick, leftUp, rightUp))
// do stuff when button is clicked


Parental advisory explicit content
Don't click this!

[edited by - Vich on May 4, 2003 5:04:53 PM]

Share this post

Link to post
Share on other sites
Looks damn good May I ask how

int placeX1, placeY1, placeX2, placeY2;    int placeInWindowX, placeInWindowY; 

are different? I''d like to work on my own GUI as well, but I''m not sure how to appraoch it. I''ve been told virtual functions were the way to go?

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!