Results 1 to 3 of 3

Thread: [VB.Net]2d Map Creator

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    [VB.Net]2d Map Creator

    Features
    Allows you to create maps for a game and then export them with their properties to an XML file.

    Drawbacks
    It's pure visual basic.net, which isn't necessarily a drawback, but still vb.net is not know for it's outstanding graphics rendering. That's why most games made in vb.net use XNA or DirectX to handle the graphics. Also in my 2d Map Engine, I use a method that loads the tiles on the screen that's currently being viewed as opposed to loading the whole map and scrolling through that map which cuts down a lot of lag time.

    Plans
    Maybe make it multi-layered. With multi-layered engines you can create the bottom layer as just ground sprites and then the upper layer(s) would store structures(buildings, tree, etc..) and movables(creatures, npc's, etc..). I also plan to implement the method mentioned in the drawback.

    Notes
    I plan for this to tie into loading my 2d Map Tile-Based Engine. Eventually I may convert this to XNA. Also, I don't include the sprites. You'll need to have your own sprites, and store them in a "Sprite" folder.

    Full Project - Minus .Exe
    MapGenerator.zip

    Image
    Name:  map generator.jpg
Views: 3633
Size:  35.2 KB
    Last edited by dday9; Jun 10th, 2013 at 11:11 AM. Reason: Added a drawback
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: [VB.Net]2d Map Creator

    Hi Dave,

    Nice work as usual. I found a couple of bugs, though:

    The very first time you run the code, My.Settings.tile_location is set to String.Empty, so the code bugs out on the highlighted line. (tile_location will also be String.Empty). Of course, as this sub is called from the Form1 Load event handler, on a 64 bit OS the error will be swallowed while in Debug mode and the form will still show, but without any images.
    Code:
    Private tile_location As String = My.Settings.tile_location
    Private tile_list As New List(Of Map_Tile)
    
    Private Sub load_images()
        If tile_location = String.Empty Then
            MessageBox.Show("Please navigate to the folder that stores your tiles.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Dim fbd As New FolderBrowserDialog
            fbd.RootFolder = Environment.SpecialFolder.MyComputer
    
            If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
                My.Settings.tile_location = fbd.SelectedPath
                My.Settings.Save()
    
                Dim FileDirectory As New IO.DirectoryInfo(tile_location)
                Dim FileJpg As IO.FileInfo() = FileDirectory.GetFiles("*.jpg")
                Dim FileGif As IO.FileInfo() = FileDirectory.GetFiles("*.gif")
                Dim FileBmp As IO.FileInfo() = FileDirectory.GetFiles("*.bmp")
                Dim FilePng As IO.FileInfo() = FileDirectory.GetFiles("*.png")
    In the Board_MouseClick and board_MouseMove Subs, when you are filling blocks of multiple tiles the tiles may not go right up to the edges of the board. For example, select RadioButton3 or RadioButton5 (3x3 or 5x5) and click in the tile at location 1,1 (remembering 0,0 is the top left tile). I think this is being caused by your conditionals such as:
    Code:
    If xind - 1 > 0 AndAlso yind + 2 < board_size.Height - 1 Then
    where they should be:
    Code:
     If xind - 1 >= 0 AndAlso yind + 2 <= board_size.Height - 1 Then

    When I first ran the code, the Save Button did not appear since the splitter panel had resized so as to hide it (confused me for a while ). Perhaps you could set the panel it is on to be SplitContainer3's FixedPanel, and/or allow scroll bars for the panels on the left hand side of the Form.


    Finally, as there are 2500 tiles on the map, it's taking a fair bit of time to add all the tiles to Panel2. I think you might be able to speed up the loading of the Form by using SuspendLayout for Panel2 while you are creating its tiles; something like:
    Code:
    'Load board
    SplitContainer1.Panel2.SuspendLayout()
    Call load_board()
    SplitContainer1.Panel2.ResumeLayout()

    I always enjoy your projects. Keep 'em coming!

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: [VB.Net]2d Map Creator

    Of course, as this sub is called from the Form1 Load event handler, on a 64 bit OS the error will be swallowed while in Debug mode and the form will still show, but without any images.
    Ah that's something I didn't think about. I was always running it with a location all ready picked out, so that's something I must've overlooked!

    For example, select RadioButton3 or RadioButton5 (3x3 or 5x5) and click in the tile at location 1,1 (remembering 0,0 is the top left tile). I think this is being caused by your conditionals such as
    Rookie mistake

    When I first ran the code, the Save Button did not appear since the splitter panel had resized so as to hide it (confused me for a while ). Perhaps you could set the panel it is on to be SplitContainer3's FixedPanel, and/or allow scroll bars for the panels on the left hand side of the Form.
    Could you post a screen shot of that for me, I wasn't able to reproduce it.

    I think you might be able to speed up the loading of the Form by using SuspendLayout for Panel2 while you are creating its tiles; something like:
    Cool, I had no idea about Suspend/Resume Layout! That would definitely help out.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width