Finally, it's nice to be able to pause animation and step through it frame by frame to examine details. A couple of bool variables control calls to the gameLogic() function, with the key commands 'p' (play/pause) or 's' (step) |
Ohh i quite like that idea. I do kind of the same as you. I have a few shortcut keys for certain things like turning on and off bounding boxes, getting a certain upgrade or ship, ect. Then I just added in a in game console window that I can bring up with '~' to test more in depth things like adjusting enemy hit points and speed or spawning a certain group of enemies. Wanted to make a UI with sliders and stuff for it but just opted for a console instead since it seemed a bit easier.
But will definitely have to add in the step through frame by frame (Or even a few frames at a time) since I can definitely see where that would come in handy.
2) I'm not sure what you mean by 'state management'. If you mean whether a level is in play vs. being at a menu, then I use function pointers for this. There are INIT, Delete, Event, Logic and Draw functions for level play, and for each menu in the game. A function pointer for each of these is used to ensure that the appropriate function for the current state is being called. The program flow is determined by the function pointer assignments made in the INIT and Delete functions. |
Thats correct basically the global state of the game (IE Titlescreen, menu screen, level 1, level 2, ect).
I kind of go a different route for handling these. Basically I will have a base state class that each different state inheirits from. It basically just provides the functionality for changing from one state to the other and some other basic things that each of them needs like the update function, draw function, and event handling.
I then create a new class for each of the states that define whatever they need to do. To manage it all I stick them into a Stack. Have to give a shout out to the SFML book for the state management design (And pretty much the whole framework design). Here is the code from one of the games I have been working on that demonstrates it. The repo is quite behind from the current implementation have been meaning to push the recent changes to it for awhile now. But feel free to look around if you want it has most of the basic framework.
State.h and State.cpp - Base class for all the states.
https://github.com/Epidemic-Games/SFML/blob/master/State.h
https://github.com/Epidemic-Games/SFML/blob/master/State.cpp
GameState.h and GameState.cpp - Where the gameplay happens (Got rid of this for different level states)
https://github.com/Epidemic-Games/SFML/blob/master/GameState.h
https://github.com/Epidemic-Games/SFML/blob/master/GameState.cpp
StateStack.h and StateStack.cpp - This is what handles all the different states and determines which one is active.
https://github.com/Epidemic-Games/SFML/blob/master/StateStack.h
https://github.com/Epidemic-Games/SFML/blob/master/StateStack.cpp
And here is a common use of changing states. This comes from the MenuState and is for when the play button is hit. It pops the current state (MenuState) off the stack and pushes which state you want to go to onto it.
1 2 3 4 5 6 7 8
|
auto playButton = std::make_shared<GUI::Button>(*context.fonts, *context.textures);
playButton->setPosition(100, 250);
playButton->setText("Play");
playButton->setCallback([this] ()
{
requestStackPop();
requestStackPush(States::Game);
});
|
Anyways thank for the answer fun2code I'm always interested in how others go about different aspects of game programming and don't really know to many people that are into game programming.