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  
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? 
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 / 8
    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

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - 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...





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