Quote: "Then you only add blocks to the array in the area that the user wants them, therefore not having data for all empty spaces as well (meaning you can read through the array faster and it uses less of the memory)."
Right now the way it is set up, is that the user declares a height and width of their planning grid, as well as layers. This pre-determines the size they want/need. It then displays their generated grid as blank "air" blocks. I don't know that I'd want to approach it that way o.O
If you'd like to see the full source to get a better idea, email me at contact(dot)fractality(at)gmail(dot)com
It's my fractal email but it has the least traffic so I'm most likely to see the email in a timely fashion.
[Edit] Also, the z value is used to represent layers, all but one layer of z being shown at a time, displaying an x by y grid. o.O
Current code sections dealing with the grid:
Mainform:
Blockgrid struct:
Public Structure BlockGrid
Dim Block As PictureBox
Dim Layer As Integer
End Structure
Declaration in Mainform class:
Public grid(1, 1, 1) As BlockGrid
Passing information for grid dimensions from Startscreen to mainform:
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim lays As Byte
Try
Mainscr.x = Integer.Parse(tbWidth.Text)
Mainscr.y = Integer.Parse(tbHeight.Text)
Mainscr.z = Integer.Parse(tbLay.Text)
If Mainscr.z > 1 Then
For lays = 1 To Mainscr.z
Mainscr.lbLay.Items.Add(lays)
Next
Else
Mainscr.lbLay.Items.Add(1)
End If
Mainscr.Visible = True
Me.Visible = False
Mainscr.Setup()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
Setting up the grid with info from the Startscr:
Public Sub Setup()
'Creates the grid of Picture Boxes
ReDim grid(x, y, z)
Dim i As Byte
Dim j As Byte
Dim k As Byte
For i = 0 To x - 1
For j = 0 To y - 1
For k = 0 To z - 1
grid(i, j, k).Block = New PictureBox
With grid(i, j, k).Block
.Left = Integer.Parse(i.ToString) * Integer.Parse(pbSize.ToString)
.Width = pbSize
.Top = Integer.Parse(j.ToString) * Integer.Parse(pbSize.ToString) + 30
.Height = pbSize
.Image = My.Resources.air
End With
AddHandler grid(i, j, k).Block.Click, AddressOf blockChange
Controls.Add(grid(i, j, k).Block)
If k = 0 Then
grid(i, j, k).Block.Visible = True
grid(i, j, k).Layer = 1
Else
grid(i, j, k).Layer = k + 1
grid(i, j, k).Block.Visible = False
End If
Next
Next
Next
End Sub
Attempting to re-access grid in another Sub relating to a listbox of layers(The exception is thrown here during runtime, on trying to read from grid):
Private Sub lbLay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbLay.SelectedIndexChanged
Dim i As Byte
Dim j As Byte
Dim k As Byte
For i = 0 To Me.x
For j = 0 To Me.y
For k = 0 To Me.z
If grid(i, j, k).Layer = Integer.Parse(lbLay.SelectedItem) Then
grid(i, j, k).Block.Visible = True
Else
grid(i, j, k).Block.Visible = False
End If
Next
Next
Next
End Sub