Game Development of .Nettrix: GDI+ and Collision Detection - Further Improvements
(Page 22 of 22 )
Two last improvements you could make are creating levels for the game and producing a configurations screen, but these we’ll leave for you to do by yourself.
To create levels for the game, you could use a basic rule like this one: Every 3 minutes the block falling speed is increased by 10 percent, the game level is incremented by one, and the points earned for each block gets multiplied by the level number. You can just adjust the timer tick procedure to include the logic for this rule.
In the case of a configurations screen, you could choose to see or not to see the next block image (setting the Visible property of the picNextBlock accordingly) and adjust the block size on the screen, so the visually impaired can play with big blocks, and those who like to play pixel hunt can do so with single-pixel square blocks.
Because the whole game is based on the GameField.SquareSize constant, implementing this feature is just a matter of creating the configuration window and adjusting the screen size according to the chosen square size. The next code listing is provided to underscore this last point; just add the following code to the procedure to be able to adjust the screen size after the configuration:
// Adjusts the size and controls position based on the class constants.
// On the window height, sums the size of the window title bar.
this.Height = GameField.Height * GameField.SquareSize +
(this.Height - this.ClientSize.Height) + 3; // 3=border width
this.Width = GameField.Width * GameField.SquareSize + 92;
this.PicBackground.Height = GameField.Height * GameField.SquareSize + 4;
this.PicBackground.Width = GameField.Width * GameField.SquareSize + 4;
this.PicNextBlock.Left = GameField.Width * GameField.SquareSize + 12;
this.LblNextBlock.Left = GameField.Width * GameField.SquareSize + 12;
this.lblScore.Left = GameField.Width * GameField.SquareSize + 12;
this.lblScoreValue.Left = GameField.Width * GameField.SquareSize + 12;
this.CmdStart.Left = GameField.Width * GameField.SquareSize + 12;
You are adjusting neither the font size nor the button sizes, so to work with smaller sizes, some updating of the code will be necessary.
In the downloadable source code, the code is on the Load event of the form, so you can play with different sizes by simply adjusting the SquareSize constant and recompiling the code.
Lastly, if you want to look at a more object-oriented implementation of this game, look at how Chris Sells did it in his implementation of Wahoo (http://www.sellsbrothers.com/wahoo). It uses a similar masking technique, but the handling of the blocks is different from this example.
Summary In this chapter, you created your first game, .Nettrix, and explored some important concepts that will be used even in sophisticated games, including the following:
- Basic concepts about GDI+ and the new Graphics objects used in C#
- Basic concepts about collision detection and some suggestions on how to implement fast collision algorithms in your games
- Creation of simple classes and bitwise operators in C#
- Basic game engine creation, based on a game proposal and with the support of a game project
In the next chapter, we’ll introduce you to the concept of artificial intelligence, how to create a game with computer-controlled characters, and how to create faster graphics routines with GDI+. You’ll also examine some additional concepts concerning object-oriented programming.
Acknowledgments The authors would like to thank Tristan Cartony, who assisted with the creation of the .Nettrix C# code.
Book Reference James Arvo, “A Simple Method for Box-Sphere Intersection Testing,” in Graphics Gems, edited by Andrew S. Glassner (Academic Press, New York, 1990)
This chapter is from Beginning .NET Game Programming in C#, by David Weller, et al., (Apress, 2004, ISBN: 1590593197). Check it out at your favorite bookstore today.
Buy this book now. |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |