Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - 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 
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? 
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: 4 stars4 stars4 stars4 stars4 stars / 3
    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 - Checking for Entity Collision


    (Page 3 of 4 )

    You may, however, have noticed a problem with TryMove. If the entity trying to move faces a wall, then TryMove returns False as it should since no move can be made. However, if the entity trying to move faces another entity, then TryMove will return True.

    You can test this out by getting in the way of the PacingManEntity. He'll walk right through you. Clearly, this is not what we want, but, thankfully, this can be easily fixed by modifying TryMove. TryMove simply needs to loop through all of the entities to determine if the destination tile is inhabited by another entity, or if the player inhabits the destination tile.

    All of this is easy, though. We simply need to compare the X and Y properties of each entity to the x- and y-coordinates of the destination tile. Here's the entire TryMove method, rewritten:

    Function TryMove(ByVal toBeMoved As Entity, ByVal xChange As Integer, ByVal ychange As Integer) As Boolean

     Dim x As Integer = toBeMoved.X + xChange

     Dim y As Integer = toBeMoved.Y + ychange

     For Each gameEntity As Entity In entities

     If gameEntity.X = x And gameEntity.Y = y Then

     Return False

     End If

     Next

     If map(x, y).Passable = True _

     And (player.X <> x Or player.Y <> y) Then

    RedrawTile(toBeMoved.X, toBeMoved.Y)

    toBeMoved.X = x

    toBeMoved.Y = y

    DrawEntity(toBeMoved)

     Return True

     End If

     Return False

    End Function

    Now TryMove works properly, checking not only the Passable property of the destination tile but also the location of the player and all of the other entities. The player and the PacingManEntity should no longer walk over each other. Instead, they should stop, blocked.

    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

    - Understanding Delegates using Visual Basic.N...
    - 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...





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