Flares!
|
This week one of my main artifacts was to get the Flares to work as intended. Since our game takes place in a mostly dark environment where visuals are valuable, flares plays a key-role in the game. The intent for the final product is to let the player use flare to light up areas and handle enemies. While flares are a limited resource they are a key piece of the game. As seen, the game features a crosshair which is placed above the darkness, allowing aiming. The flares are meant to travel from the player, who is meant to be located in center of the screen, to the crosshair. After being fired the flare lasts ten seconds and only stops moving if it collides with a wall. I worked for a long time trying to figure out a way to control the traveling path of the projectile, reading up online. In the end, the code for the projectile’s travel looked like this: m_xAcc = cos(m_sprite->getRotation()*3.14159265 / 180); // Add an upper limit? m_x += m_xAcc * 5; m_sprite->setPosition(m_x, m_y); The cos and sin code I took from an older project, for which I originally found it online. It sees to it so that the speed of the projectile is the same no matter the angle it. There is also a piece of code that rotates the flare towards the mouse when it spawns, which is then used by ”getRotation” to tell which angle the projectile is to travel in. Once fired the flare flies on in the set direction unless it meets a wall. If it hits a wall it freezes and sticks there for the rest of it’s short existence. Ten seconds after the Flare is released it runs a removal function, causing the sprite to disappear. With all of this added, the next step was to limit the flare count. Each click on the left mouse button spawned one flare, but it would remove the entire point of the darkness if there was not a limit to the amount of flares in the game. The limit is set to 5, with one being lost each time a flare is fired. In the final product more flares are intended to be possible to pick up. The limit means the player has to be conservative and cannot just fire flares all over the place to remove the light issues. It also limits what the player will be able to do when it comes to handling enemies. This will be part of the game’s challenge and thus the access to flares will be a key part in balancing the game later on. At the point of writing, the Flare sprite still does not have its last component added to it, the effect that allows to it to shine through darkness. This is a quick thing to add but since I was not the one to write the light code, I will have to ask about how to solve it. The flares were a bother to get right, but their functionality for the game is key, and I learned a lot due to all the reading up I had to do just to figure out how to do it properly. There are likely fine-tuning to the flare’s speed and spawning mechanics that needs resolving, but for now it works and does what it is supposed to. Hope this was not too painful a read. /Stefan |
