The past week I decided to focus on the player’s HUD (Heads-Up Display) which is key to displaying information to the player, something which has proven itself an issue as we tested the game. Being unaware of their ammunition’s limit has repeatedly caused players waste away shots, something I believe will be resolved when there is and easy and clear visual display of their ammunition.
The HUD also contains several bubbles with represents the player’s current oxygen. The oxygen slowly decreases over time and if it ever reaches zero, the player loses. Oxygen can easily be refilled by finding and picking up a sample, which helps motivate the player to seek the samples on a mechanical level. Oxygen’s main role is similar to the timer in a 2D Mario game: it means you cannot just stand around forever, but at the same time does not force you to stress. IT is just a motivator to keep the player swimming.
But let us take a look at a screenshot from the game;
Here we have just entered the level. On our upper left we can see ten bubbles, all identical. This is the oxygen bar. One bubble fades for each ten seconds that pass. Over to the left we can see fire flare shells representing the player’s ammunition, currently at max capacity. Each time the player fires a flare one cartridge disappears and when there are none left the player is out of ammunition and thus unable to use the flares. Let us now step forward a bit:
As we can see, the player has gone about for something above thirty second since they found their last sample, which has caused three of the oxygen bubbles to fade out. There are still seven more bubbles left, so they still have ample time to look around and figure out where to go next. They have however spent two flares, leaving only three shells in the upper-right. The only way to replenish flares is to find crate of ammunition, meaning being sparing in the use of them could be wise.
Both bars were really just created from arrays of sprites that create several sprites just next to each other. Each sprite remains separate for the purpose of having their texture changed:
sf::Texture* texture;
for (int i = 0; i < 10; i++)
{
filename = ”../external/graphics/o2bar.png”;
texture = m_texture_manager->CreateTextureFromFile(filename);
O2[i] = new sf::Sprite(*texture);
O2[i]->setPosition(64*i, 10);
}
for (int i = 0; i < 5; i++)
{
filename = ”../external/graphics/bullet.png”;
texture = m_texture_manager->CreateTextureFromFile(filename);
m_flareLimit[i] = new sf::Sprite(*texture);
m_flareLimit[i]->setPosition(1856 – (64 * i), 10);
}
This is then checked during each update cycle:
Player* player = (Player*)m_player;
for (int i = 0; i < 10; i++)
{
if (10 * i < m_oxygen)
{
//sf::Texture* texture;
filename = ”../external/graphics/o2bar.png”;
m_texture = m_texture_manager->CreateTextureFromFile(filename);
O2[i] = new sf::Sprite(*m_texture);
O2[i]->setPosition(64 * i, 10);
}
if (10 * i > m_oxygen)
{
//sf::Texture* texture;
filename = ”../external/graphics/o2bar2.png”;
m_texture = m_texture_manager->CreateTextureFromFile(filename);
O2[i] = new sf::Sprite(*m_texture);
O2[i]->setPosition(64 * i, 10);
}
if (i < 5)
{
if (i < m_flares && m_limit[i] == false)
{
m_limit[i] = true;
}
if (i + 1 > m_flares && m_limit[i] == true)
{
m_limit[i] = false;
}
}
}
So so for oxygen, if m_oxygen is lower than the sprite’s array number times ten, the sprite turns to the darkened version to show that it is currently expended. However, the game keeps checking, and if m_oxygen goes over said value again then the bubble is refilled. Flares follows a similar method, checking the array value plus one against m_flares. If the array number (plus one) is higher, then a correlating bool is set to false, causing the sprite not to be drawn during the following update cycles unless m_flares once again raises in value to that the array value is no longer higher.
All in all this was a rather simple method. I met some issues due to bugs leading into bugs that lead to memory leaks which led to bugs, but in the end we got it working. I see this as an essential tool to give the player feedback and help them know what is going on, and I am currently considering to try and make it easier to understand. Hope you liked reading all of this.
/Stefan