Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Making a tile grid

hobbyGuyhobbyGuy Posts: 2Member
Hi, I am a hobby programmer as my name would imply. I'm currently using visual basic .net 2010. It was free from microsoft and I pick it up faster than C#. I plan to move over to C# once i feel comfortable with VB. So here is the Gist. Im making a game in my free time. Right now im making a Tile map to act as the structure for executing the game. I dont know as much as i should about the whole process of making a game but then again i dont plan on it being professional quality. Its just for my own enjoyment. That said Im just looking for helpful advice and Tips from the people who know their stuff. Since i dont have the time to learn everything i need to i find it a best pratice to seek help from others who know more than i do. Ok i think that about covers it. If there is anything that i should of said but didnt pls let me know. I understand that ur using ur time to help me so i really want to make this as easy on you a possible.


This is the class im using as a base. I dont want to add textures to this class i want to abstract it so that its easier to repurpose it later. Im going to make a derived class to hanlde adding textures to the tile Map later. before i move on to that i really want to make sure that this class is satisfactory and am hoping somebody can give me a little forsight. Ok now that ive rambled ur brains out here is the code.
[code]

Public Class Grid

Private _Heigth, _Width, _Rows, _Colums As Integer
Private _DrawingRectangle As Linker4(Of Integer, Integer, Integer, Integer)
Private _TileLocations(0, 0), _GridLocation As Linker(Of Integer, Integer)

#Region "Formatting"
'''
''' This Sub formats the X,Y values in a 2d Plane to represent a logical grid, IS structured in a 2d array in this format all X then Y.
'''
''' Called When the size, location, or # of Rows and colums Change, If the # of Rows/Colums changes the Update sub should be called instead
Protected Overridable Sub Format_Grid()
'Must Define before Call - GridLocation,TileHeight,TileWidth.
'_GridLocations Must be Resized Before Formating.
'X,Y = points in a 2d plane
Dim X, Y As Integer
X = _GridLocation.Data_oF_DataType1
Y = _GridLocation.Data_oF_DataType2
'Formats the data to represent a grid going along X then Y
For Lp As Integer = 0 To _TileLocations.GetUpperBound(0)
Y = _GridLocation.Data_oF_DataType2
For Lp2 As Integer = 0 To _TileLocations.GetUpperBound(1)
_TileLocations(Lp, Lp2) = New Linker(Of Integer, Integer)(X, Y)
Y += _Heigth
Next
X += _Width
Next
End Sub
'''
''' This Sub Updates the Grids format when The # of Row/Colums Change
'''
'''
Protected Overridable Sub Update()
'Typically Called when the grids rows or colums change
'Call format_Grid when sizes or locations change
ReDim Preserve _TileLocations(_Rows, _Colums)
Format_Grid()
End Sub
#End Region

#Region "Location"
'''
''' Where the Top Right corner of the grid exsist in a 2d Plane
'''
'''
''' DataType1 = X, DataType2 = Y
'''
'''
Public Property Grid_Location As Linker(Of Integer, Integer)
Get
Return _GridLocation
End Get
Set(value As Linker(Of Integer, Integer))
_GridLocation = value
Format_Grid()
End Set
End Property
Public Property Grid_X As Integer
Get
Return Grid_Location.Data_oF_DataType1
End Get
Set(value As Integer)
Grid_Location.Data_oF_DataType1 = value
Format_Grid()
End Set
End Property
Public Property Grid_Y As Integer
Get
Return Grid_Location.Data_oF_DataType2
End Get
Set(value As Integer)
Grid_Location.Data_oF_DataType2 = value
Format_Grid()
End Set
End Property
#End Region

#Region "Size"
'''
''' The Size In Pixels of the Grid
'''
''' DataType1 = Width, DataType2 = Height
'''
'''
Public ReadOnly Property Grid_Size As Linker(Of Integer, Integer)
Get
Return New Linker(Of Integer, Integer)(Grid_Width, Grid_Height)
End Get
End Property
Public ReadOnly Property Grid_Height As Integer
Get
Return _Heigth * _Rows
End Get
End Property
Public ReadOnly Property Grid_Width As Integer
Get
Return _Width * _Colums
End Get
End Property
'''
''' A rectangle that reresents the boarder of the grid
'''
'''
'''
''' DataType1 = X, DataType2 = Y, DataType3 = Width, DataType4 = Height
Public ReadOnly Property Display_Rectangle As Linker4(Of Integer, Integer, Integer, Integer)
Get
Return New Linker4(Of Integer, Integer, Integer, Integer)(Grid_X, Grid_Y, Grid_Width, Grid_Height)
End Get
End Property
#End Region

#Region "Rows/Colums"
'''
''' The size of the grid in rows and colums
'''
'''
'''
''' DataType1 = Rows, DataType2 = Colums
Public Property Rows_Colums As Linker(Of Integer, Integer)
Get
Return New Linker(Of Integer, Integer)(Rows, Colums)
End Get
Set(value As Linker(Of Integer, Integer))
Rows = value.Data_oF_DataType1
Colums = value.Data_oF_DataType2
Update()
End Set
End Property
Public Property Rows As Integer
Get
Return _Rows
End Get
Set(value As Integer)
_Rows = value
Update()
End Set
End Property
Public Property Colums As Integer
Get
Return _Colums
End Get
Set(value As Integer)
_Colums = value
Update()
End Set
End Property
Public Function Find_Row(ByVal Row As Integer) As Linker(Of Integer, Integer)()
Dim Pt(Colums) As Linker(Of Integer, Integer)
For LP As Integer = 0 To Colums
Pt(LP) = New Linker(Of Integer, Integer)(0, 0)
Pt(LP) = _TileLocations(Colums, LP)
Next
Return Pt
End Function
Public Function Find_Colum(ByVal Colum As Integer) As Linker(Of Integer, Integer)()
Dim Pt(Rows) As Linker(Of Integer, Integer)
For lP As Integer = 0 To Rows
Pt(lP) = New Linker(Of Integer, Integer)(0, 0)
Pt(lP) = _TileLocations(lP, Rows)
Next
Return Pt
End Function
#End Region
End Class

[/code]

Thank You for looking this over. If u have any advice that could help me become a better coder it would be appricated. Thank you
Sign In or Register to comment.