ASP.NET
  Home arrow ASP.NET arrow .Netterpillars: Artificial Intelligence an...
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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? 
ASP.NET

.Netterpillars: Artificial Intelligence and Sprites, Part 2
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2005-01-11

    Table of Contents:
  • .Netterpillars: Artificial Intelligence and Sprites, Part 2
  • The Branch Class
  • Main Program and GameEngine Class
  • Second Draft: Coding the Player Character
  • Main Program and GameEngine Class
  • Third Draft: Coding the Game Engine and Collision Detection
  • Fourth Draft: Coding the Config Screen and Game Over
  • Coding for the Introduction Screen
  • Final Version: Coding the Netterpillars AI
  • The Main Program: Final Version
  • 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


    .Netterpillars: Artificial Intelligence and Sprites, Part 2


    (Page 1 of 11 )

    In this article on artificial intelligence, you will take a computer game from first draft to final version. It is excerpted from chapter two of the book Beginning .NET Game Programming in C#, by Ellen Hatton et. al. (Apress, 2004, ISBN: 1590593197) and is the second of two parts.

     

    The Coding Phase

    As you did in the previous chapter, you’ll start coding the basic objects for the game (simplest first), and then tackle the more difficult code of the game engine and the netterpillar AI classes.

    To allow you to test every new method created, you’ll do your code in five steps:

    1. First draft: Code the static objects.

    2. Second draft: Code the player character.

    3. Third draft: Code the game engine and collision detection.

    4. Fourth draft: Code the configuration screen and game over.

    5. Final version: Code the netterpillars AI.

    The details of each of these versions are shown in the next sections.

    First Draft: Coding the Static Objects

    In the next sections, we show the code and discuss the details of the classes for the static objects, mushrooms, and branches, and create an early version of the main program and the GameEngine class, so you can test these classes.

    The Sprite Class

    You’ll only add a new property in this class, the IMAGE_PATH constant, which will be used by all the child classes to compose the full path from where the images should be loaded.

    The Mushroom Class

    There’s not much to say about the Mushroom class. It just has an overloaded constructor that creates a sprite with the mushroom drawing, to be used instead of the original sprite constructor with a parameter. This will allow cleaner code when creating mushrooms.

    public class Mushroom : Sprite {
      public Mushroom() {…}
    }


    The code for the constructor will be as follows:

    public class Mushroom : Sprite {
      public Mushroom() :
        base(Application.StartupPath+”\\”+IMAGE_PATH+
             ”\\Mushroom.gif”) {}
    }

    Note that all you do is call the base class’s new method, passing the appropriate parameters.


    NOTE When a child class defines a method that already exists in the base class, any object created from the child class will call the code in the method of this class, unless you explicitly call the base class method, as in the preceding code sample (using base() after the colon, plus any necessary parameters).

    This chapter is from Beginning .NET Game Programming in C# by Ellen Hatton et al. (Apress, 2004, ISBN: 1590593197). Check it out at your favorite bookstore today. Buy this book now.

    More ASP.NET Articles
    More By Apress Publishing


     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT