Quantcast
Channel: Programmers Heaven Forums RSS Feed
Viewing all articles
Browse latest Browse all 2703

Making a tile grid

$
0
0
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.

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"
    ''' <summary>
    ''' 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.
    ''' </summary>
    ''' <remarks>Called When the size, location, or # of Rows and colums Change, If the # of Rows/Colums changes the Update sub should be called instead</remarks>
    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
    ''' <summary>
    ''' This Sub Updates the Grids format when The # of Row/Colums Change
    ''' </summary>
    ''' <remarks></remarks>
    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"
    ''' <summary>
    ''' Where the Top Right corner of the grid exsist in a 2d Plane
    ''' </summary>
    ''' <value></value>
    ''' <returns>DataType1 = X, DataType2 = Y</returns>
    ''' <remarks></remarks>
    ''' 
    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"
    ''' <summary>
    ''' The Size In Pixels of the Grid
    ''' </summary>
    ''' <value>DataType1 = Width, DataType2 = Height</value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    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
    ''' <summary>
    ''' A rectangle that reresents the boarder of the grid
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>DataType1 = X, DataType2 = Y, DataType3 = Width, DataType4 = Height</remarks>
    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"
    ''' <summary>
    ''' The size of the grid in rows and colums
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>DataType1 = Rows, DataType2 = Colums</remarks>
    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


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

Viewing all articles
Browse latest Browse all 2703

Trending Articles