this is my first post here on gamedev.net
I have started to create games in SDL with C++. I've just moved over to SDL2 and I really enjoy producing games as a hobby. I love working with music, sound, graphics and code.
The first game I made was a top-view space shooter, with very simple structure with only a hardcoded menu, and play game loop.
So I felt ready to start with a larger project. In the new game I've introduced new concepts like camera, gamestates and other things. And a lot more story line. In simple terms it will be a 2d space shooter, with rpg elements. To be fair I believe it will be a hobby project that will span across 1-2 years.
This is how I imagne it to work:
- The game creates a new gamestate via a factory.
The game inits the gamestate (loading resources, preferrable from an xml, json) and
populate a big vector of gameObjects. A gameObject could be a tile, sprite, player etc. Pretty much anything
that has a coordinate and a graphical represententation on the screen.
The game loop:
Everything here is find and dandy and works really well for me. However, in a later stage I need more logic that introduces cutscenes and conversaions, and missions. I would also like to be able to create tailormade levels in form of game events.
To accomplish this I been thinking about two approaches:
- Create a class that works as "director" in the gamestate which can access all objects in the gameObject vector, with very specific functions and checks different conditions. It reads the different conditions and events from an xml, json file. This approach is probably the quickest one to implement, but it's hard to make it flexible and I feel I still have to write a lot of hacky C++ code that needs to be written to "customify" the levels.
- Use a interpreted language for the logic and initialization. I've been looking into incorporating Lua into C++, and it doesn't seem too difficult. When a gamestate is fired, it reads level data from a lua script, that instantiates all the gameObjects to the gameState. On the C++ side I guess I have to create somekind of API for lua to access.
This has many upsides since I can edit a script while running the application, no need for recompiling everything, and a lot quicker to produce levels, and custom made missions. So all the hackyness is in the Lua files and clean "engine-code" in the game. The biggest downsides with this I believe are performace and debugging.
I feel that the latter alternative is most appealing, but I'm very unsure where to put all the logic from lua. I still need a gameloop, and it needs to read the lua code each "frame" to check for conditions and events. So performance-wise it seems a bit of a waste? Since interpreting Lua must be a bottleneck (on every game-loop iteration)? Where else could I place the interpretation code?
So of you've done anything like this before or have ideas on how to tackle this approach, please let me know!
I've been googling for several days to get some pointers on how to tackle this and I would like to have a clear idea before starting coding something that might be a very bad solution.
Thank you for taking the time to read this rather long post =)
Edited by davidwik, 20 August 2014 - 05:11 AM.