Bullets in Dragon Song
|
Similar to the previous week this week have mostly been about fine tuning parts of the game. Anthon Fredriksson introduced us to smart pointers and helped us implement them in our game. With this a lot of our memory leaks were eliminated. Some other parts of the game were also fixed, but for this blog post I will write about the bullets in the game. The player bullets, the enemy bullets and the huge sound wave “bullet”. All of these are actually projectiles but I have decided to name them bullets in the code for a good reason I am sure. The player bullet and the power up bullet were already implemented in the game, I only made some minor changes due to the redesign we made of the game last week because of the delay between when the player shot a projectile and when the sound played. When the bullet no longer has any connection to the beat of the game the player had no reason not to spam shoot the enemies, making the game impossible to lose. Therefore I added a limit to how many bullets that can be active on the screen at the same time. The solution was simple, I added an integer that holds how many bullets that can be activated at the same time. When the player shoots a bullet one value is subtracted from this integer, and when some collision happens between the bullet and an object or the end of the screen one value is added to this integer. Last week the player could activate the power up bullet without any limitations, resulting in that the player could spam the power up. I changed this in a similar way of the player bullet with an integer. When the number 1 key is pressed one value is added to this integer, and when this integer reaches 10 a big P symbol (a place holder) the power up can be activated. If this power up is activated the integer is set to 0 again. The enemy bullets was created this week. The class is written almost the same as the player bullet class as it works very similar. The challenge for us now is how the enemy bullets should be activated. At this moment they are activated when the player has activated the player bullet five times, and is activated from every living enemy. We have not yet decided how this should be done, or how we will write the code for it. This is one of our goals for the beta presentation this Friday. A picture showing the player bullet and the enemy bullets. Because of changes to the game we have used place holders for the bullets:
The following code is a example of the collision between enemies and player bullet, with the ++m_bulletCount integer adding a value to allow the player to activate a bullet again. This piece also includes collision with discobomb bullets and enemies. This is just an bonus example if you want to see how the smart pointer works in our collision checking.
|
