Programming our Heads up display
|
I began our fifth week by fixing a few problems I had with my missile movement by taking the values from inside the window so now they work properly. I had an exciting task ahead of me this week I had to program our Heads up display and what my group wanted was something different from what you would normally see in a game. Where in games you have numbers and health bars everywhere but not to different and it ended as a good experience for me. They wanted 3 energy bars on the bottom half of the screen with the bars increasing on a timely basis. I started by taking a sprite one of your graphic designers made and loaded the texture onto a sprite inside the HUD class as well as the setting other options such as the color with a transparency which was easily done by adding a forth number inside sf:Color(x,x,x,X) and to make things easier I set the origin of the sprite in the middle of it. Now I had some problems since I wanted to use my Heads up display class and make an array to draw out three sprites on my window but it did not want to be push backed. My solution was simply to make my array into a std::vector and create tree objects. Now I had to draw out my sprites on the window but since my view moves I had to bind them to my view instead, I did this by setting the position by calculation using the views center x minus or plus the view size x and depending on where I wanted it on my screen I used differential of 2 or 4 then I took the view center y plus view size differential 2 minus the Heads up display local height. By this time I had three outlays to draw my energy meters upon so I started by making a similar class as the Heads up display and this time I also needed a vector for my energy meter class so i created the object 100 times using a for loop to make bar. Then I set the position for inside the first heads up display object and used used another for loop with an integer with the current energy you possessed this was in a white color. To be sure it wouldn’t continue forever I set a maximum value and used if statements to stop the white bar. Then I made a new sprite and draw it out using the same object on the same surface behind the current bar so you should see when the white bar was full in a gray color.
Haiku Coding is fun in the bad, messy, main. The code comes toghter! |
