BLOG WEEK 5 – Vector subscript out of range

Hello there!

This week has been doing a lot for the final, when I say a lot, I mean a lot. I have been creating stuff for the program all over to make the final as good as possible. However creating objects in the game also means that you have to make the infamous std::vector. A vector is just ”lockers” where you can save information, (I will not go in any further in to it.) Vectors have an exceptional ability to crash the program if you are not doing it right and not telling you where too look for the error, so you need to go through all and every one of your vector’s and check if any of them where wrong. Just even something as simple as ++ instead of — will make it crash, and it is so simple to miss anything that could crash.

Have I told you about the part where everything we do in our program is based on vectors? Why? Well its the simplest way of doing ANYTHING with multiple objects, so far as I know atleast. Since you need them to check hitboxes, you need them for updates, drawing and erasing memory leaks.

So how about we talk about memory leaks, I had previously thought of a way to delete objects that would be superb, I had a counter that counted up whenever something spawned it had a counter add one. This made it so I could draw everything and interact so I could do it in reverse, what this did for the game is so when two units would spawn the one thats closest to the bottom screen draws itself first.

Now I was thinking about the memory leaks I was thinking that it would erase things that was the oldest so it would not mess up anything else that was on the screen. This however was where my superb plan would go in to fail. Everytime the program checked for something to delete it would start to check at things that did not exsist making the game crash. So this is when i started to go crazy about the vector crashes so I did it so it would go the correct way instead of backwards and would you look at that, no more crashes! This was an incredible feeling having the program to erase objects and not crash! This made the game playable without mayjor lags.Main menu2

BLOG WEEK 5 – Vector subscript out of range

BLOG WEEK 5 – Touching up the menu!

Hello!
4dd35e2b218fe182436644fb10a73b64
This week I have started to make the game look nice instead of making it work, and for now I have started to look at the menu and starting to fix up alot of things on it. First of all the menu screen is another picture nothing to fancy about it.

Next the buttons! The buttons are working so when you hover over them they change the look of it, or making it to be selected so to say. So i created a hitbox for the mouse pointer and for the buttons and simply made collision between the rects. So when the hitbox for the mouse intersected with the button it would simply change picture of the button making it look selected. I also made it look a bit more 3D just by simply setting the sprite 5 pixels lower and that results in more fancy buttons.

So the next thing on the checklist for the menu was the animation for the enemies walking, this was nothing special except doing an animation on it since anyone that have been programming in SFML should know how to do it.

Last but not least we have the way of putting the player in to the game, so instead of just popping up in the game we needed to have something to make it look better, more of a smooth transition. The whole plan for the menu is that it is going to scroll upwards and then make the player sprite to run up thowards the screen and when its in the same possition in the original spawning point for the player sprite that you can stear the game would start.

So I had to make a variable that could change all the sprites possition on the screen at the same time. I tried to use the sprite move command and even sprite setpossition(0, getpossition().y + scrollspeed) neither of these things worked so I had to controll it from one value instead of all the sprites them self move. So i solved this so i set the possition of all the sprites + scrollspeed that always goes upwards untill the screen is compleetly gone. After that I loaded in a pice of the map that would be in the begining so when the map would start to scroll it would not look strange. After that the player runs up and the game starts.

Thanks for me!

BLOG WEEK 5 – Touching up the menu!

Code review

Efter att ha kollat på hovercraftturret.cpp (som jag antar är player klassen) Ser jag att den är otroligt större än vad våran är, men jag kan tänka mig att man behöver det eftersom det är ett mer avancerat spel än vad vårat är. couplingen i denna klass är ganska mycket eftersom ni låter klassen i sig själv ha koll på en massa olika saker vilket man bara ser i konstruktorn där ni skickar in en rad olika pekare och andra saker. Hur som helst en bra idé är kanske att ha en slags for av iEntity klass som håller reda på en rad olika saker så man slipper att skicka in så många saker (Om man nu skulle kunna se likheter mellan de olika objekten i programmet) för då slipper man krångla med så många saker. 

Code review

Blog week 4 – Smart code? Powerup that influence the speed

a9398e8068666b2ec1e28ccae2a679f9
Hello!
Since having the game’s looser or win condition being dependent of how long you take on completing the level, we needed something that would speed up or slow down the scrolling entities depending on what would happen in the game. Turns out to be harder that i thought, maybe I am just over thinking it and making it harder than it is.

However! I started to create the whole power up giving it the proper functions and variables, nothing to majorly fancy. I got it to spawn and behave like the other power ups, so now it was only the functioning of the power up left. I needed something that could change the speed of every scrolling entity in the program, or well that was how far I had thought trough before hand. So I created a variable wich would control the speed, so when I activated the power up it would change that to a higher value, and after a while it would change it back to the original value.

Alright got that covered, now I only needed to make every active object adapt to this speed, so i created a loop for each of the different entities and set so their scrolling speed to what I would set the value to from the power up. Easy enough, so I tested it. Worked out great until i saw what happened when a new entity would spawn, it was as fast as if I would not have a power activated, it was easily fixed by just sending in the extra speed they would have before spawning it in.

Alright, now we have a working speed up system with smart code wich could change the speed with the power up. Now I needed to create something that would slow down the game, like mud! Same story short, i created the class and so forth. So i spawned in the mud and when the mud intersected the player’s hit box it would slow down. This needed its own variable because I can not set the variable to be minus something since then everything would fly away in rocket speed. So i just had to send in the other variable with the first when im setting the speed of every entity.

Either way, if the player would intersect with the mud it will slow down, else it would not. Since it checks every mud tile I can’t have it like this, so I needed something that could check if it still is intersecting the other time around, so I gave the mud class its own bool if it is slowing or not. So after the first collision test I made another that would check the first tile that would have the bool set to true and checked if the player still where colliding with the player, if it did slowed would still be true, otherwise it would turn it off making it a functioning way of controlling speed.

Blog week 4 – Smart code? Powerup that influence the speed