Support Forums
[Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] (/showthread.php?tid=6158)



[Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - hockeynut35 - 04-12-2010

This tutorial took me about two hours to write so please show some appreciation.

Note: I myself have only made two game maps, as they are pretty advanced. Good luck, all will go smooth if you follow this properly.

Step 1.

The first thing you need to do is create a class title "BasicTile" (BasicTile.vb).

Now you will have this:

Code:
Public Class BasicTile

End Class




Step 2.

The next thing you must do is set the BasicTile class to inherit from the "Tile" Class.

To do this Insert "Inherits Tile" In between "Public Class BasicTile" and "End Clas".

You will now have this:

Code:
Public Class BasicTile
Inherits Tile

End Class

Note: The Inherit statement must be on it's own line or your will receive an error.

Step 3.

Now Vb.net should prompt you to create a constructor for the default parent class.

We shall call it "Tile's Constructor".

Make sure you have this code:

Code:
Public Sub New()
MyBase.New(".", ConsoleColor.Gray, ConsoleColor.Black, True)
End Sub

Step 4.

Now that the basic floor tiles are setup, we need to create a wall tile.

Create a class called "WallTile" (WallTile.vb)

Use this as the code:

Code:
Public Class WallTile
Inherits Tile

Public Sub New()
MyBase.New("#", ConsoleColor.Gray, ConsoleColor.Black, False)
End Sub
End Class

Step 5.

The last basic tile to create is a blank tile. This is used to cover any excess space in the map.

Make a class called "BlankTile"...(BlankTile.vb)

Use this code:

Code:
Public Class BlankTile
Inherits Tile

Public Sub New()
MyBase.New(" ", ConsoleColor.Black, ConsoleColor.Black, False)
End Sub
End Class

Step 6.
This begins to get tricky

Now that we have our three basic tiles, we need to create the map array.

We will make the field for the map 60 x 20:

Code:
Dim map(59, 19) As Tile

Step 7.

Now for the actual map. We are going to make a square room occupying the whole area. This requires a loop for the x-coordinates and another loop within that for the y-coordinates. At the edge of the map we will simply place, "WallTille", and we will fill the rest with "BlankTile".

Put in a method calle "CreateBasicMap"

Code:
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

Step 8.

Now to create that loop.

Call it. "Createbasicmap" in: "main".

Code:
CreateBasicMap()

Easy enough right?

Step 9.

Now we are going to draw the screen

We'll put the in a another method, so we do not to clog up Main. The method will be called "DrawMap":

Code:
Sub DrawMap()
For y As Integer = 0 To map.GetUpperBound(1)
Console.SetCursorPosition(0, y)
For x As Integer = 0 To map.GetUpperBound(0)
DrawTile(x, y)
Next
Next
End Sub

This tutorial took me about two hours to write so please show some appreciation.

Note: I myself have only made two game maps, as they are pretty advanced. Good luck, all will go smooth if you follow this properly.

Step 1.

The first thing you need to do is create a class title "BasicTile" (BasicTile.vb).

Now you will have this:

Code:
Public Class BasicTile

End Class




Step 2.

The next thing you must do is set the BasicTile class to inherit from the "Tile" Class.

To do this Insert "Inherits Tile" In between "Public Class BasicTile" and "End Clas".

You will now have this:

Code:
Public Class BasicTile
Inherits Tile

End Class

Note: The Inherit statement must be on it's own line or your will receive an error.

Step 3.

Now Vb.net should prompt you to create a constructor for the default parent class.

We shall call it "Tile's Constructor".

Make sure you have this code:

Code:
Public Sub New()
MyBase.New(".", ConsoleColor.Gray, ConsoleColor.Black, True)
End Sub

Step 4.

Now that the basic floor tiles are setup, we need to create a wall tile.

Create a class called "WallTile" (WallTile.vb)

Use this as the code:

Code:
Public Class WallTile
Inherits Tile

Public Sub New()
MyBase.New("#", ConsoleColor.Gray, ConsoleColor.Black, False)
End Sub
End Class

Step 5.

The last basic tile to create is a blank tile. This is used to cover any excess space in the map.

Make a class called "BlankTile"...(BlankTile.vb)

Use this code:

Code:
Public Class BlankTile
Inherits Tile

Public Sub New()
MyBase.New(" ", ConsoleColor.Black, ConsoleColor.Black, False)
End Sub
End Class

Step 6.
This begins to get tricky

Now that we have our three basic tiles, we need to create the map array.

We will make the field for the map 60 x 20:

Code:
Dim map(59, 19) As Tile

Step 7.

Now for the actual map. We are going to make a square room occupying the whole area. This requires a loop for the x-coordinates and another loop within that for the y-coordinates. At the edge of the map we will simply place, "WallTille", and we will fill the rest with "BlankTile".

Put in a method calle "CreateBasicMap"

Code:
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

Step 8.

Now to create that loop.

Call it. "Createbasicmap" in: "main".

Code:
CreateBasicMap()

Easy enough right?

Step 10.

More loops.

The outermost loop goes by row, and the inner loop goes by column. At the start of each iteration of the outer loop, we set the cursor to the beginning of the appropriate row. As we draw the tiles, the cursor will automatically shift right.

Create another method called, "DrawTile"

Input the code:

Code:
Sub DrawTile(ByVal x As Integer, ByVal y As Integer)
Console.ForegroundColor = map(x, y).ForeGroundColor
Console.BackgroundColor = map(x, y).BackgroundColor
Console.Write(map(x, y).Symbol)
Console.ResetColor()
End Sub

Be active and look for part two! It might be up by the end of the night, if not tomorrow!

HockeyBlackhat


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - RaZoR03 - 04-18-2010

Awesome Tut man...

Thanks


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - hockeynut35 - 04-18-2010

(04-18-2010, 12:11 AM)RaZoR03 Wrote: Awesome Tut man...

Thanks

Your welcome. Nice to finally have some appreciation for my longest/ hardest tut.


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - Julie - 04-18-2010

Very nuce tutorial, thanks !


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - Alex Meanberg - 07-06-2011

Wow. This is amazing. I love the power of classes. Good job man!


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - Bigandrewgold - 07-08-2011

nice tutorial dude, do you have any pics of what this can achieve?


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - specizripn - 07-08-2011

Awesome tut! Thanks for making such a great contribution to this community!


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - Relapse - 07-12-2011

Very nice tut. I' actually getting into making games now for the first time!


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - ƃu∀ ıʞƃu∀ - 11-27-2012

nice tut dude

thank you for the tut Big Grin


RE: [Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced] - ax5 - 12-16-2012

love it, i will try this later Smile