1. Technology

An SDL GUI for Empire Tutorial Six

Setting Up the Game


Screenshot of Empire with splash screen

This is another tutorial about developing the Empire game. If you've found this article first, please see part one. Here's more information about the Empire Game.

In the previous SDL Gui tutorial 5 I added a clickable listbox. In this tutorial, I'm adding a bit of structure to the game including a splash screen and any game options then generate the game map and start the game.

Latest Code

  • Download Source Code File (Zip).
  • Download binaries (All Exe + SDL dlls + graphic files etc) zipped up. Just unzip everything into one folder. It should run. You shouldn't need SDL installed unless you are developing it.

The main game option is the number of computer players which ranges from 1-3. The splash screen is displayed when the game starts and when you . It's basically a display bitmap control so while it's on screen, so all the controls' and screen scrolling still work even when it's displayed. It is closed by clicking it or automatically when the game is ready for player input.

Rather than call a function directly to display it, I've created a flag variable showsplash defined in sdlgui.c and exported in sdlgui.h. The graphic for the splashscreen is added to the project in imagenames. It's a little convoluted but having the splashscreen display logic as part of the normal sdlgui logic makes it easier.

Currently this version of the sdlgui supports only one clickable set of controls at a time. Eventually when I get onto right clicks on the map, I'll be having another one popup and at that time, I'll modify sdlgui to support multiple sets of controls. Things like the panelx and panely variables will be moved into a struct and there'll be a linked list of structs, one for each open control sets. Such is the er joy of developing fairly complex guis!

So for now, the splashscreen is being displayed as a clickable control as part of the main panel (but displayed centrally on the screen), but only displayed if the global splashscreen variable is set to non-zero. I added a button to toggle the showsplash variable.

Rounded Corners?

I decided it would be nice to eventually have popup windows that could be displayed with rounded corners. As luck would have it there is an open source library, SDL_draw that provides this so no wheels require invention this time. Download the library, unzip it and copy the SDL_draw.h into the SDL includes library that you setup earlier.

In the zip file there is a folder called VC2008EE which contains the source of SDL_draw. Open the SDL_draw.sln file and if you aren't running Visual C++ 2008, it will upgrade it. You're left with three projects to build. I had to add the path to SDL_draw.h which I had copied to my c:\sdl\include folder. Also I had to had the sdl lib folder to the linker path. If this is your first time configuring visual studio see Setting Up Visual Studio/Visual C++ 2010 Express for SDL Development on Windows which also works with Visual Studio/C++ 2012.

Adding a new Control

One of the controls I discussed adding was a clickable image, an esdlimage. This is used to draw the splashscreen. I've added this in the usual way passing it it's surface. There's an extra parameter to handle if this is a splashscreen, so it makes the x,y adjustment. I've modified initsdlguilib to add the splashscreen.

The splashscreen vanishes if it's clicked. The function just sets the splashscreen value to 0. Unfortunately from a programming point of view the splashscreen code has had to be integrated into the mouse click handler, the control rendering handler. It's not ideal but it does work and sometimes you have to make these compromises. For instance, all controls are located at x > 800 except for the splash screen. There's a check to ignore clicks if x < 800 but this is ignored if the showsplash variable is set to 1.

I've reworked the control panel so that when the game starts you select 1-3 computer opponents then click the Start Game Button. At this point it will generate a new game map, add cities, starting armies and the game begins. But it doesn't yet! That'll be in the next tutorial.

  1. About.com
  2. Technology
  3. C / C++ / C#
  4. Programming Games
  5. An SDL GUI for Empire Tutorial six

©2014 About.com. All rights reserved.