Visual Basic.NET
  Home arrow Visual Basic.NET arrow Entity Creation and Messaging in a VB.NET ...
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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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? 
VISUAL BASIC.NET

Entity Creation and Messaging in a VB.NET Text-Based Game
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-07-22

    Table of Contents:
  • Entity Creation and Messaging in a VB.NET Text-Based Game
  • Implementing Movement
  • Checking for Entity Collision
  • Implementing a Message System

  • 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


    Entity Creation and Messaging in a VB.NET Text-Based Game


    (Page 1 of 4 )

    The player can't be alone in the world. Obviously, he's going to have to have some non-human company. Let's put some non-human characters into the game. In this ninth and final part of our series teaching VB.NET through the creation of a text-based game, we're also going to create a messaging system.

    Drawing Other Entities

    The non-human characters will be derived from Entity, just as the player character is, because they're going to share some of the same properties. They are going to have names, heatlh, attack, defense, a character symbol, a position on the map, and so forth.

    Let's go ahead and implement an entity who will pace back and forth. This entity is completely pointless as far as gameplay is concerned, but implementing him will help us with non-human entity functionality because we have to deal with drawing him and moving him around.

    Create a class called PacingManEntity (in the file PacingManEntity.vb) to house our new entity:


    Public Class PacingManEntity


    End Class

    The first thing we need to do with this new class is inherit from Entity and then set up an appropriate constructor, which will call Entity's constructor and pass the appropriate values:

    Public Class PacingManEntity

     Inherits Entity


     Sub New(ByVal x As Integer, ByVal y As Integer)

     MyBase.New("Pacing Man", "P", ConsoleColor.Red, _

    x, y, 10, 1, 1)

     End Sub

    End Class

    As you can see above, his name is Pacing Man, and his symbol is a red “P.” His starting location is, of course, not hard-coded into the class. Rather, the starting location is accepted as a parameter in the constructor.

    We have an entity, and now we need to draw him. Drawing is done the exact same way as with the player—through DrawEntity. However, we need a way to draw all of the non-player entities at once. The best way to do this is to store the entities in a collection and then create a new method that will loop through the collection and call DrawEntity for each entity. Plus, with a collection, we can keep track of all the entities.

    We'll use a List(Of T) to store the entities because that is what's most appropriate for the situation. Create the collection as a field of the Game module, right under the player and map definitions:

    Dim entities As New List(Of Entity)

    Notice how we also instantiate the collection.

    Next, we need to add a PacingManEntity to the collection. Put the following line at about the location that we create the Adventurer object (the line where we create the PacingMan and add it to the entities collection needs to be before the line where we draw the entities):

    entities.Add(New PacingManEntity(10, 10))

    Now we need a method that will loop through entities and draw everything. We'll call this procedure DrawEntities, and it will use a simple For Each loop to get the job done:

    Sub DrawEntities()

     For Each toBeDrawn As Entity In entities

    DrawEntity(toBeDrawn)

     Next

    End Sub

    Next, simply call the new procedure at around the location that the player is drawn through DrawEntity:

    DrawEntities()

    Run the program, and you should see a PacingManEntity somewhere off to the bottom right of the player.

    More Visual Basic.NET Articles
    More By Peyton McCullough


       · Hello, all,This is yet another article in my series introducting Visual Basic...
       · In the article you skipped over making the entities move. Learning from the article...
       · Goodness, Charles, thanks again! As with last time, my version of the code is...
     

    VISUAL BASIC.NET ARTICLES

    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway