Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Creating and Drawing a Game Map in 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

Creating and Drawing a Game Map in VB.NET (FIXED PER REQUEST)
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2008-07-08

    Table of Contents:
  • Creating and Drawing a Game Map in VB.NET (FIXED PER REQUEST)
  • Creating the Map Array and a Basic Map
  • Drawing the Map
  • Creating the Entity Class

  • 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


    Creating and Drawing a Game Map in VB.NET (FIXED PER REQUEST) - Creating the Map Array and a Basic Map


    (Page 2 of 4 )

    Great. We now have three simple tiles to work with, and we can begin to work with the map array. As stated before, the map will be represented by a two-dimensional array. In this way, we can treat the array as a coordinate system of sorts. One dimension's index will represent the x-coordinate of the tile, and the other dimension's index will represent the y-coordinate of the tile. This works out to be nice and neat.

    As with player, our map array will be a field of the Game module. This is the easiest way to work with it. Let's go ahead and create a field for the map. Let's make the map 60x20. So, the upper bound for the x-coordinate will be 59, and the upper bound for the y-coordinate will be 19:

    Dim map(59, 19) As Tile

    Next, we need a map. Ordinarily, we may want to automatically generate a map, or else read an existing map from a file. However, let's keep this basic for now and create a map by hand. More ambitious projects will have to wait until later. Let's start with something simple. We'll make a large square room occupying the entire available space. We can create a room like this with a loop. We'll loop through every space in the map. This will require one loop for the x-coordinates and another embedded within that for the y-coordinates. If we're at the edge of the map, we'll place a WallTile. Otherwise, we need a BlankTile. Let's put this in a method called CreateBasicMap:


    Sub CreateBasicMap()


     ' Get the x- and y- coordinates for the right and bottom

     ' edges of the map

     Dim xLimit As Integer = map.GetUpperBound(0)

     Dim yLimit As Integer = map.GetUpperBound(1)


     For x As Integer = 0 To xLimit

     For y As Integer = 0 To yLimit

     If x = 0 Or x = xLimit Or y = 0 Or y = yLimit Then

     map(x, y) = New WallTile()

     Else

     map(x, y) = New BasicTile()

     End If

     Next

     Next

    End Sub

    We use a For loop because we need to be able to go tile-by-tile and also check to see if we're at an edge. The outer loop iterates over the x values, and the inner loop iterates over the y values. So, the method essentially creates the map column-by-column. Also, notice the use of the Or operator. We check multiple conditions, any of which, if true, indicate that we're at an edge of the map. Go ahead and call CreateBasicMap in Main:

    CreateBasicMap()

    More Visual Basic.NET Articles
    More By Peyton McCullough


       · Main() will fail after the change to the Adventurer class. The new constructor...
       · You're right. Main seems to have been quietly changed on my end, without any mention...
     

    VISUAL BASIC.NET ARTICLES

    - LINQ to XML Programming Using Visual Basic.N...
    - 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...

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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