Results 1 to 3 of 3

Thread: Moving through arrays, selecting certain rows and columns.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2012
    Posts
    19

    Moving through arrays, selecting certain rows and columns.

    Hello, it's me again!
    I'm slowly making progress on my terrible game!
    If you havn't seen any of my previous posts here is the low-down:

    100 tiles are created automatically on form load, names tile1 to tile 100

    Array is loaded from a textfile of 10,10 (not stored as a 10,10 just parsed from line to line, which I feel needs to be changed asap)

    Each tile is then given a corresponding graphic (e.g. grass, water, lava) and soon hopefully I will add interaction with certain tiles

    There is also a simple hero that moves about from tile to tile (not in the array, just physically placed on top of each tile)

    Now. If at all possible, I wish to be able to write bigger arrays, like as big as need be and when the character moves to the right, the tiles in the far left column will disappear and a new set will move in from the right

    There will always be 100 tiles on the screen.

    example, the ones in bold are visible to the player, the others would be visible if the player moved in their direction!

    Code:
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,1,1,1,1,1,1
    1,1,1,1,1,1,1,3,3,3,1,1,1

    Here is my current code...
    I'm thinking I might need to put it in the character movement part of the code with the key listeners...

    http://pastebin.com/ACC99X2N

    Thankyou for reading

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Moving through arrays, selecting certain rows and columns.

    the easiest way i can think of, is to use a datagridview:

    vb Code:
    1. DataGridView1.AllowUserToAddRows = False
    2. DataGridView1.AllowUserToDeleteRows = False
    3. DataGridView1.AllowUserToOrderColumns = False
    4. DataGridView1.AllowUserToResizeColumns = False
    5. DataGridView1.AllowUserToResizeRows = False
    6. DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    7. DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
    8. DataGridView1.ColumnHeadersVisible = False
    9. DataGridView1.RowHeadersVisible = False
    10. DataGridView1.GridColor = Color.White
    11.  
    12. 'create a 10*10 grid
    13. For x As Integer = 1 To 10
    14.     DataGridView1.Columns.Add(New DataGridViewImageColumn)
    15.     DataGridView1.Rows.Add()
    16. Next
    17.  
    18. 'load images
    19. For r As Integer = 0 To 9
    20.     For c As Integer = 0 To 9
    21.         DataGridView1.Rows(r).Cells(c).Value = New Bitmap("filename")
    22.     Next
    23. Next

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Moving through arrays, selecting certain rows and columns.

    A datagridview ? I donno paul, something about that gives me an uneasy feeling. A datagridview is a complex control and it seems overkill to use this to store relatively simple level data. If I were doing this, I would write a class specifically to handle storing information about a two dimensional plane. I would provide methods to extend it, shrink it and edit its data and when writing this class I would pay particular attention to performance, so I wouldn't utilize too many abstractions and objects. Imagine if you had to call this 100 times a second, you would want it to be able manipulate its data as fast as possible. The possibility of this performance need is why I would avoid using a datagridview.

    If you want OP I could whip up a small example of the kind of approach I would take to storing this tiling information.

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