.NET
  Home arrow .NET arrow Page 12 - Game Development of .Nettrix: GDI+ and Col...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Game Development of .Nettrix: GDI+ and Collision Detection
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2004-08-23

    Table of Contents:
  • Game Development of .Nettrix: GDI+ and Collision Detection
  • Performing Graphic Operations with a Graphics Object
  • Creating Gradients
  • Collision Detection
  • Proximity Algorithms
  • Optimizing the Number of Calculations
  • Extending the Algorithms to Add a Third Dimension
  • Develop a Real Game Proposal
  • Diagrams of Basic Game Objects
  • The Game Engine
  • The Coding Phase
  • Testing the Program
  • The Block Class
  • The Constructor
  • The Down, Right, and Left Methods
  • The Rotate Method
  • The Show and Hide Methods
  • Final Version: Coding the GameField Class and the Game Engine
  • The CheckLines Method
  • The Game Engine
  • Adding the Final Touches
  • Further Improvements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Game Development of .Nettrix: GDI+ and Collision Detection - Testing the Program


    (Page 12 of 22 )

    Testing the Square Class

    Now you are ready to test your program. To do this, you’ll need to create a driver to call the class (a window with a button and a pictureBox will suffice), and a stub for the GameField class, since your Square class uses the BackColor property of this class.

    The stub is very simple, just a new file composed of the code lines shown in the next sample:

    public class GameField {
      public static Color BackColor;
    }

    The driver will be replaced by the main program in the final version, so you can implement it as code on the form that will be used as the game user interface. In this case, you can create a simple form with a picture (picBackground) and a button (cmdStart), with the code to create the objects and set the properties of the Square class, then call the Draw method.

    private void cmdStart_Click(Object sender, System.EventArgs e) {
     
    Square square = new Square();
      square.Location = new Point(40, 20);
      square.Size = new Size(10, 10);
      square.ForeColor = Color.Blue;
      square.BackColor = Color.Green;

      // Set the background property of GameField class.
      GameField.BackColor = picBackground.BackColor; 
     
      // Draw the square. square.
      Draw(picBackground.Handle);
    }

    Running the code, you can see the fruits of your labor: a nice path gradient– colored square is drawn on screen as shown in Figure 1-23.


    Figure 1-23. Your first results with GDI+

    Because in your game the squares won’t change color or size, you can assign these values when creating the objects, creating a new constructor in the Square class to do this, as illustrated in the next code sample:

    public Square(Size InitialSize,Color InitialBackcolor,Color InitialForecolor) {
     
    size = InitialSize;
     
    BackColor = InitialBackcolor;
     
    ForeColor = InitialForecolor;
    }

    So the code for your Start button will be as follows:

    private void cmdStart_Click(object sender, System.EventArgs e) {
     
    // Clean the game field.
     
    Square square = new Square(new Size(10, 10), Color.Blue, Color.Green);

      // Set the location of the square.
     
    square.Location = new Point(40, 20);
     
    // Set the background property of GameField.
     
    GameField.BackColor = picBackground.BackColor;
     
    // Draw the square.
     
    square.Draw(picBackground);
    }

    Now that everything is working correctly, continue with the coding by looking at the Block class.

    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.

    More .NET Articles
    More By Apress Publishing


       · Examples from the first page are invalid. You cannot do:Graphics g = new...
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek