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.

Blog Player-Flare-Crosshair

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_yAcc = sin(m_sprite->getRotation()*3.14159265 / 180);

m_x += m_xAcc * 5;
m_y += m_yAcc * 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

En reaktion på ”Flares!

  1. Känns tydligt vad det är du har sysslat med den senaste veckan. att göra projektilen för ert spel. Är inte helt säker på om er crosshair är implementerad eller om den bara agerar som visuell representation just nu, men eftersom det är flare som beskrivs i posten så spelar det ingen större roll.

    Det är bra att du ger exempel på hur koden du skriver ser ut. Eftersom namnen på variablerna och funktionerna är tydliga så krävs inga kommentarer för att förklara vad koden ska göra, vilket är ett plus. Undrar lite hur en sinus + cosinus funktion kan ge en rak linje med tanke på att de svänger, men du verkar ha koll på läget. Så tycker det är bra skrivet om hur din kod fungerar och hur du vill att den ska fungera.

    Du skriver även att flare är riktigt viktig för spelet, vilket beskrivs i texten. Att du även gör så att man inte kan förstöra gameplay genom att skjuta hur många flares som helst är klokt. Ni kommer förmodligen behöva justera värdet för flares när ert spel börjar närma sig att bli färdigt, men det är balansering, och inget man bör tänka på allt för mycket innan det är relevant.

    Känner som helhet att bloggposten är värdefull, då den ger en inblick i hur man kan programmera projektiler. Dessutom beskrivs det varför flare är viktig i spelet, som gör att texten känns relevant till koden. Bra jobbat! (bry dig inte så mycket om småsakerna, nämner bara för att nämna, typ)

    //Olle Staffas Grupp 13

    Gilla

Lämna en kommentar