NOGDUS
July 16, 2018, 01:38:30 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Blogs Help Search Tags Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: ASK Tutorial 07 - Heads Up  (Read 2327 times)
0 Members and 1 Guest are viewing this topic.
Richard Marks
202192397
Administrator
Member
*

Respect: 3425
Offline Offline

Posts: 1027


happy


« on: March 30, 2010, 05:06:15 PM »

ASK Tutorial 07 - Heads Up

Yep! Time for yet another Allegro Starter Kit tutorial! Cool

The concept: Add the heads up display to the game screen, and show the player's remaining lives.

It is assumed that you are using Visual C++ 2008 Express (MSVC9)
If you're not using MSVC9, then you will need to adjust some steps to suit your IDE.

This tutorial builds off the previous tutorial's code, so don't forget to add the code from the previous tutorial.


Step #1 - Create a new Empty Win32 Project (not a Console Application) in your IDE.

File -> New Project
Choose Win32 Project
Enter "ASKHeadsUpDemo" for the Name
Click OK
Click Application Settings
Check the Empty Project check-box
Click Finish

Step #2 - Save the Empty Project

File -> Save All

Step #3 - Copy the code files from Tutorial 06 into your project's folder.

Copy all the *.cpp and *.h files from the Tutorial 06 project into the folder that holds the ASKHeadsUpDemo.vcproj file.

Step #4 - Add the files to the Project

Project -> Add Existing Item
Choose all the .h and .cpp files you just copied and click Add.

Step #5 - Add the code to the PrimaryWindow files to implement the demo concept.

This is going to be the easiest addition. Add two new function declarations to PrimaryWindow.h
Code:
void RenderHeadsUpDisplay();
void RenderPlayerLivesIndicator();

And add the function stubs to PrimaryWindow.cpp

The heads up display will consist of a simple gray bar on top of which we will draw the indicators.
For now, the only indicator we will have is the number of lives the player has remaining.

It would be easy to display this information as text, but we are not going to do that! Cheesy
I figured that it would be cooler to display the number of lives as a row of little triangles.

The RenderHeadsUpDisplay() function will draw the gray bar, and then call any indicator rendering functions.
Of which, currently there is only one.
Code:
const int hudBackColor = makecol(32, 32, 32);
rectfill(_backBuffer, 0, SCREEN_H - 18, SCREEN_W, SCREEN_H, hudBackColor);
this->RenderPlayerLivesIndicator();

To draw the player lives indicator, we will use a simple loop.
The code for RenderPlayerLivesIndicator() is very straightforward, and should not need to be explained any further.

Code:
int xOffset = 8;
int yOffset = SCREEN_H - 18;
int iconWidth = 8;
int iconWidthOver2 = iconWidth / 2;
int iconHeight = 16;
int iconSpacing = 4;
int iconBottom = yOffset + iconHeight;

for (int i = 0; i < playerLives_; i++)
{
int x = xOffset + ((i * iconWidth) + (i * iconSpacing));
triangle(_backBuffer,
x, iconBottom,
x + iconWidthOver2, yOffset,
x + iconWidth, iconBottom,
playerColor_);
}

Add a call to RenderHeadsUpDisplay() from RenderFrame() and that brings this tutorial to a close.

When you compile and run the project, you should get:
1 - A window with a black background
2 - The bouncing blue ball from the first tutorial
3 - The green triangle from the second tutorial that you can move left and right using the arrow keys.
4 - A single reloading cyan bullet that you can fire using the space bar.
5 - The ball should disappear if the bullet collides with it.
6 - The ball should re-appear (re-spawn) after roughly 1 second has passed after it dies.
7 - The ball should attack the player when it is moving downwards, and above the Y center line.
8 - Three second delay before you can move the player as it is in a "re-spawning" state.
9 - The player should flash on and off while it is in the re-spawning state.
10 - There is now a heads up display at the bottom of the screen showing the number of lives the player has.

Thanks for reading! See you in the next tutorial!
Let me know if you were able to follow this tutorial without any trouble.


(Updated April 2, 2010 - Changed usage of underscores in regards to Redslash's notice.)
Logged

Tags: ask code  Allegro tutorial allegro starter kit tutorial c++ 
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!