2nd blog post of 10 Week Project – Implementing Lost Souls
|
In case you are interested in all updates of Group 12’s game, here are my group members’ blogs: This week I have been working on implementing the lost souls in the game amongst other things. To implement the lost souls I used one of my fellow programmer’s codes as guidance to create the new entity for the game. Firstly, I added the entity’s name to an enum called “Alignment” and then I was able to add it to the collision map (to see how the collision works in our game, check out André’s blog post here). I then created the .h and .cpp files for the lost soul’s class. The class is publically inherited from the base class Entity. I named the class “LostSoulObject”, and the functions of this class are the constructor “LostSoulObject”, “Init”(short for initialize), “Update” and “OnCollision”. What happens in this class is very simple. When a lost soul is attached in the game, the constructor will set the current animation, position etc. and initialize will give the entity it’s ID and alignment and also set the position of the lost soul’s sprite. The Update-function updates the animation of the lost soul, and the OnCollision-function makes the lost soul disappear when collided with the player. This is simply code used to create the lost soul. All other code involving the lost souls was written in either the player object’s class or the entity manager’s class. In the player object’s class there is a collision function. If the player’s hixbox collides with the lost soul’s hitbox, an integer called “collectedSouls” is increased by one and the boolean “hasLostSoul” is set as true. Then, in the player object’s update function, when either the Q-key or the E-key is pressed and the hasLostSoul boolean is true, the lost soul is sacrificed or freed. When Q is pressed and the player has a lost soul, the function “SacrificeSoul” is called and the collectedSouls integer decreased by one. When E is pressed the samething happens, but instead of the SacrificeSoul-function the ReleaseSoul-function is called. There is also an if statement that checks if the collectedSouls integer is equivalent to or less than zero, and if this condition is true the Boolean hasLostSoul is set as false, thus you cannot sacrifice or free souls when you do not have any collected lost souls. In the SacrificeSoul-function, depending on what elemental type the player is currently using, the current type’s points is increased by three and the other two types are increased by one. This is done with if/else statements to check what type is current. The ReleaseSoul function increases each elemental point’s integer by one. To make sure that this really worked I output the player’s three elemental points integers and the collectedSouls integer.
The next thing I will do is to make the lost souls spawn when an enemy is killed. This will depend on the probability of a random number. |



