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!

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

Blog week 3 – Scrolling map, tiled?

Blog Picture 3
Hello!

Previously in the game we needed a scrolling background, however now we needed to start to actually make the background since it needs to mix up a bit so it would not seem so repetetive, and do other things like having a funktioning paralax, make a more flexible enviorment that could do more instead of just scrolling.

So we started to look at different ways of doing it, we had tiled wich Tommi suggested to us, and then we had the idea of doing everything from within the code just doing an array. However the array way takes longer time while tiled does the exactly same thing and you instantly get a visual feedback on how its going to look.

So we chose the tiled way, after looking at some tips on how tiled worked with the code I tried to figure out a way how to do it, but without any succsess I chose to look at a tutorial. Found a good one that explained it nicely, so i decided to try it out. But once again without any succsess i could not figure out what the program wanted to get it to work, however hope was not gone yet! So i contacted the programming group just to hear if someone got it to work, and i got another tutorial on how to do it. So i followed that tutorial and the same thing happend again, it did not work.

Plan B! Wich I am now currently workign on, so first of all was to create the sprites for it. Since i will be reusing the same squares and just change the texturerect I can easily make it look less repetable, at the same time I also created the sides and it was the same thing there, less repetable. However now i could try to fiddle with the paralax scrolling, all i did was to make the sides that are closer move a bit faster, and it did all the diference.

After that I have not done anymore but I am planning to when we start with the array diffrent sets of tiles will show, and/or maybe a random generated number will decide what to draw on each of the sprites, we have yet to decide that. But with this we can start designing the level for the game. Plannign on making the same way on how enemies should spawn also, its a good but a time consuming way.

Blog week 3 – Scrolling map, tiled?

Blog week 2 – Alot

So this last week has been really busy with programming, especially this thursday. Everything that should have been done for the alpha has been done, and not only that. All the code has been improved, I myself has learned the SFML library better, and now its a bit more object oriented in the code so its not just a big cluster of code.

However, the most interesting thing I’ve done this week is probably the diffrent arrays of each entity, so i could create infinite new sprites. (no not infinite, but you get the point!) So I started to create all the difrent classes of the difrent entities i where having in the main file, becuase without it I cant really think of a way of creating new things while running the code.

I long thought of a way to do this, and i tried to look at the code Jerry gave us with the SDL_Arkanoid, since its a pretty basic code it could probably fit inside my code aswell. however many trials, errors and crashes later i gave up on that. So i started to look on the internet, and i stumbled across some code wich would do the somewhat the same thing i wanted to do.

So i tried to reforge the code so it would fit in to my code and try it out, to my suprice it worked! Immediately I started to use this with my difrent classes, and to my suprice wich worked out better than i expected. I made it so when i created a sprite while running the code, it would give it a Rect wich would later be turned in to a hitbox, animations for the sprites and a update command wich would move and cycle through the frames. And also with this I used an iterator to get to the diffrent objects.

You could spawn arrows, enemies and powerups and many of them! Just with a command, every object to it has nothing to do with the one before, its animation is on another frame, it does its own thing just as i wanted! now it was only simple rinse and repeat for the other classes. It all went well untill i came to the powerup class, they are all pretty similar right now so there isnt that much difference between them, but when i started drawing out the powerups with the iterator. I probably sat with the same problem for half an hour trying to figure out it, i compared the 2 classes to eachother, not a single problem. Tried most of the stuff just to make it work. No error or anything since it wasnt faulty code the program where running. But after a while i found it, one simple counter, all it took. and then the program was running just fine!Blog picture 2

Blog week 2 – Alot

Blog week 1 – Projectile shooting

Blog picture 1

Hi!
The whole prototyping has been rough, not becuase it was hard but more lack of time. And by lack of time i do not mean that we had little time but our group prioritised the wrong thig, since writing everything in main seemed wrong so we started to build an engine.

However we started prototyping and I’ve done so the character can shoot and aim with the mouse, however its a bit strange right now since its flying all over where i do not want it to be. I’ve yet to figure out a good way for the arrow to move exactly thowars the possition of the mouse.

I have a way to calculate the angle that is between the character and the mouse now i only need a way to draw a ”line” and make the arrow move according to it. But right now the arrow flies off somewhere mostly upwards of to the left, however it stays on the screen and does not travel out from it, no clue why. Never gotten it to fly to the right for now, but I can’t really continue unless im getting this correct.

Before I tried the angle calculation I though that maybe a way to use linear equation with Y = kx + m so i calculated delta X and delta Y and divided to get k and let the Y possition of the arrow be influenced by the x possition and only let it move right or left. The idea was good but in initiation it did not work, how do i know that? Well there where three possitions the arrow could be in, one in the top right, one in the middle top and the last was  in the top left. So i gave up on the idea of that, maybe i could have gotten it to work with enough time but i felt it was a hard and painfull way.

After that i started with the other way of doing it, I already had both delta X and Y so i could start from there, and in c++ there is a thing called atan2 wich could be used as a way to calculate angle so i took atan2(delta X, delta Y) / 180 * PI and this is really where I am at right now, trying to figure out a way to make it shoot to the point of the mouse.

Blog week 1 – Projectile shooting