Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Advanced] Creating a Game Map in Vb.Net PART ONE [Advanced]
#1
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
Pm me if you need assistance with anything.
Reply
#2
Awesome Tut man...

Thanks
[Image: 20r9vh4.jpg]
Reply
#3
(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.
Pm me if you need assistance with anything.
Reply
#4
Very nuce tutorial, thanks !
Reply
#5
Wow. This is amazing. I love the power of classes. Good job man!
Reply
#6
nice tutorial dude, do you have any pics of what this can achieve?
Reply
#7
Awesome tut! Thanks for making such a great contribution to this community!
Reply
#8
Very nice tut. I' actually getting into making games now for the first time!
[Image: inm4jO.png]
[ AIM: YoRelapse | Gamertag: N/A | MSN: YoRelapse@live.com ]
Reply
#9
nice tut dude

thank you for the tut Big Grin
Reply
#10
love it, i will try this later Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [VB.NET] Advanced MessageBox Control BlackSpider 14 12,110 03-04-2015, 11:22 PM
Last Post: longwest
  [SOURCE] Advanced Webcam Viewer TalishHF 4 3,847 08-25-2014, 01:20 AM
Last Post: dark_move
  VB.Net Make a Real AntiVirus (AV) - Part 1 goranpilkic 27 30,011 08-25-2014, 12:43 AM
Last Post: dark_move
  [TUT]Creating Advanced Web Browser with Awesome Theme Imaking31 0 1,320 05-25-2013, 03:12 AM
Last Post: Imaking31
  Free Advanced Port Scanner SOURCE [ VB.NET ] Filefinder 6 5,750 01-22-2013, 04:27 AM
Last Post: TalishHF

Forum Jump:


Users browsing this thread: 2 Guest(s)