Adding a health bar to Lugaru

Add comment!

June 21st, 2010

This is a guest blog post from MCMic, a new regular in the Wolfire IRC channel. I asked him to share some thoughts on the blog because he added one of the first new features to Lugaru since it went open-source: the oft-requested health bar. Read on for his introduction:

Hi, I'm MCMic. I'm a French student in computer sciences and a free software supporter. I did develop a free game: Slime Volley.

Slime Volley Slime Volley
Slime Volley, a free software version of Slime Volleyball

I also contributed once to a game from another programmer, but it was nothing like Lugaru: Pink Pony :D

Usually I don't buy games, I donate to their creators, because I mostly play free games (as in freedom ;-)), but the Humble Indie Bundle was really attractive since we chose the price and could give some to charity. It felt more like a donation than buying. All the games had a GNU/Linux version, that's something important for me since I only use GNU/Linux.

So when they announced that they released the code (unfortunately only the code) under a free license, it was really great news for me :-).

It was really exciting to read about the improvements being made to the code on the IRC channel code. (Mainly cleaning, that's the problem of code that is made in being secret and finally is open sourced -- it's ugly) But, while cleaning was a really important job to do (thanks to those who did that and those who still do that), it wasn't really much fun.

One thing that shocked me while I played Lugaru was the lack of indicator of the health state of the character. I first thought the numbers indicated when you hit an enemy were the damages, but it's just the score. I really missed a good old health bar for my character, so I decided to implement one in Lugaru. :-)

In order to know where to put the display code, I looked where the score was displayed and added my health bar below. To know which variables should be displayed I looked at the code of for when the damage is produced. And mostly in the code that check if you're still alive.

My first version just displayed the damages as numbers, like "Damages : 140/250" under the score. I quickly realised that there was a problem, sometimes I died while my shown damages were really low. So I got back into the code and discover that the character can also die from blood loss. I added that variable in the displaying, and now it was coherent.

Then I wanted to display a pretty bar instead of just numbers. So I looked the code that display dialogues. Remeber, there is a colored rectangle behind dialogues, and what I wanted to display was nothing more than colored rectangles.

After a few tries, moving the rectangles and ordering them, I finally got to a result that pleased me. I then added a border to my health bar so it was less ugly.

And then I thought about how I could get it integrated in the main repo.

Lugaru Health Bar
The health bar in action.

I asked on IRC if they would integrate it if it were configurable and they said probably, so I got to work. I looked at the way the variable "showpoints" was handled and did a "showdamagebar" that worked the same way. I managed quickly to have the bar configurable in the config file. Then I was told to do a clone of the repo and keep it synchronized so when they would want to integrate my modifications it would be easy. I lost a lot of time on that! In fact, the password you have to use for a mercurial google repo is not the one of your google account, it's another that google creates for you. But it's not written big enough... And the Google servers don't return a pretty error like "your password is incorrect", no, mercurial just crashes with an ugly Python error. So I asked on the mercurial IRC channel and lost a week trying to figure out what was wrong to finally discover that password "feature" in google code. I hope the Python error will soon be turned into a more readable one.

Once my code was committed and merged with the new cleans (in a week, there was a lot of them), I asked on the IRC channel if my health bar could be integrated. I was told that it should be deactivated by default and should be enabled in the config menu. Ouch. The config menu code was something I didn't know at all. But fortunately, vadim showed me a diff of what he did in the code in order to add his features in the config menu. (vadim added the 3D screens support to Lugaru) and with his code as an example, it was in fact pretty easy to add a new field in the config menu.

Lugaru Damage Config
The updated config menu.

Then I came on IRC again and they finally integrated my feature. What now? Well, maybe I'll help a little with the clean of code first, but then I have other ideas of things to implement in Lugaru.

Like 3D generated grass instead of the flat texture or a mod/campaign manager (the menu code needs to be cleaned first).

You can keep aware of my advancements on