Archive for April, 2012

Immediate Mode GUIs

Most GUIs are written such that each button or other element is an object. You have an initialisation phase in which you create the objects, then you call update and render functions, and feed them events (such as mouse clicks). You get back function calls, in which you do stuff.

Fair enough, but it takes a couple of objects and functions to handle even the most simple button. What if each button could be referenced in only one place, and be just be a single function call?

Well, there is a way to do that. There’s a description of the technique here:

Immediate mode GUIs do things differently. Now the input becomes the state, and the GUI elements become functions. Buttons don’t exist at all from one frame to the next. There’s less code (on the user side) and more direct control over the GUI.

There’s a lot of discussion about which type of GUI is ‘more elegant’, ‘simpler’ or ‘more efficient’. These questions are rather subjective. You can do anything either way, and write it well or badly. Some things, such as graphical layout tools, work more naturally in retained mode. Immediate mode lends itself particularly to scripting. Not being an artist, I’m going for immediate mode. Take your pick.



Playing it (finally)

As soon as the enemies could shoot back, the game became unplayable.

Even though they didn’t move, they were much faster at shooting, and since one hit was death, no sooner would you see an enemy than the squad would be wiped out.

I felt that I needed to make the game playable before continuing, otherwise there would not be much point. There were two rules though:

  • I can’t make the AI worse. It already does nothing but turn and shoot.
  • I can’t make the enemy characters weaker relative to the player.

Two advantages that the player should have had already were superior numbers and the element of surprise. The enemy are scattered around the map while the squad are all together. The player can always expect to meet something around the next corner but the AI has no idea where a threat will come from. If I could make these work it should be possible to win.

The first problem was that on turning a corner, the characters would be exposed side-on and were unable to fire until they had rotated. I fixed this by adding automatic turning to face the mouse cursor. Now you could strafe round corners and get shots off much quicker.

The second problem was the one-shot kills. Focused fire should finish off an enemy before it has a chance to do much damage. Reducing damage to 20% per shot gives a 4x advantage to the player (if all the squad is alive).

Now I can roam the map and pick them off. So much for the prototype. I may have to start making a game now.