Game Development Tutorial

Everything a total beginner needs for game programing!

20. How about a raise?

To make things a little interesting, we'll give the player bonuses after he completes each level. I've thought of two bonuses: One that is awarded for empty columns, and one that is awarded on top, if there are no blocks left on the game field. To calculate the 'Empty Column Bonus' I used this formula: Level * # of Empty Columns * 100. For the second bonus, I used this formula: Level * 1000. So, If a player manages to clear all block in level 4, he would recieve (4*15*100) 6000 points from the Empty Column Bonus, and additional (4*1000) points from the Cleared Level Bonus. That's 10000 points! Nice! To show the player how many points he was awarded, we'll use our existing label (lblDisplay). And we'll pause the game for a few seconds between the levels. In the end, we'll create a method to switch us between levels. Ok, enough talking.

Let's start coding!This is the code that goes into the LevelScore() method:

// A variable for holding
// TEMPORARY empty column
// bonus:

int iColBonus = 0;
//Stop the game play...
Game.Stop();
// Calculate the bonus 
// for empty columns


// Go trough all columns:
for (int c = 0; c < iWidth; c++)
{
  // If the column is empty, 
  // increase empty column
  // bonus. The column is
  // empty whene there's no
  // block in the lowest field.
  // (Since we have gravity)

  if (Field[iHeight - 1, c] == 0)
  {
    // You can play with this
    // code to adjust how many
    // points are awarded for
    // every empty column:

    iColBonus += (100 * iLevel);
  }
}

// Add the empty column
// bonus to the total
// score, and show it:

iScore += iColBonus;
lblScore.Text = iScore.ToString();

// Calculate the bonus for
// cleared level :)
// (Mission impossible)

// Temporary variable:

int iLvlClrBonus = 0;
if (iColBonus ==
iWidth * (100 * iLevel))
{
  // Code that defines
  // and shows the bonus:

  iLvlClrBonus = iLevel * 1000;
  iScore += iLvlClrBonus;
  lblScore.Text = iScore.ToString();
}

// Inform the user that 
// the level is over.

lblDisplay.Text = "Level Complete!";
lblDisplay.Visible = true;
this.Refresh();

// Show bonuses, 
// if they exist:

if (iColBonus > 0)
{
 
// Pause 2 seconds:
  System.Threading.Thread.Sleep(2000);
  // Display first bonus:
  lblDisplay.Text = "Empty Column Bonus: "
  + iColBonus.ToString();
  this.Refresh();
}

if (iLvlClrBonus > 0)
{
  // Pause 2 seconds:
  System.Threading.Thread.Sleep(2000);
  // Display second bonus:
  lblDisplay.Text = "Clear Level Bonus: "
  + iLvlClrBonus.ToString();
  this.Refresh();
}

// Pause 2 seconds:
System.Threading.Thread.Sleep(2000);
// Reset the display
// label, and hide it.

lblDisplay.Visible = false;
lblDisplay.Text =
"GAME OVER!";

So, let's move to the next chapter and see how we can play with the parameters of our gameplay to make things more interesting.

Update: I finally managed to sort out the feed for this site. (Before, the feed for this site was copyed from my other blog... uh...)

0 comments:

Post a Comment

Downloads

Downloads
Finished Bubble Splash Game

Followers

Translate

Blog Directories

Programming Blogs - BlogCatalog Blog Directory
blog directory
Software Computers Business Directory - BTS Local
Top Blogs GoLedy.com
TopOfBlogs DigNow.net
Blog Directory blog search directory
Top Computers blogs Add to Technorati Favorites
Computers Blogs Blog Directory
blogsbycategory.com Blog Directory & Search engine
Blog Flux Directory Programming Blog Directory
Join My Community at MyBloglog! BlogRankers.com
Technology Blogs - Blog Rankings Blog Directory
C# Game programming tutorial Blogs lists and reviews
Bloglisting.net - The internets fastest growing blog directory Blog Directory - photarium
blogarama - the blog directory Blog Toplist
Blog directory Computers (Linux) - TOP.ORG
Blog Ratings si.blogs
Blogz game, development, programming, c#, visual studio, tutorial, source code
On our way to 1,000,000 rss feeds - millionrss.com
RSSMountain
TopBlogLists.com - Blog Search