Mynotoar
Active member
Hey again guys!
I've been working on an Ice Puzzle: you're a character (e.g. '*') in a grid (2D array) and you can move using the arrow keys - when you move, you keep going in that direction until you hit a surface. The aim is to pick up a key, which progresses you to the next level. There are three elements that need to be placed on the grid as different characters: the player (*), the block (█), the key (~).
I've got everything mostly working, and I'm at the point where I can change around the layout of the board from the initialised variables outside the Sub. The problem is, it's messy, and it's not intuitive for even me to work with, let alone someone else who wanted to tinker with the code. I'll give an example (I don't want to post the full code simply because it's so long.)
As you can see, it's a tad convoluted. I assign all the values using this Sub.
What I want to be able to do for the BlockCoordinates is have coordinates within the array. So I imagine it might look something like this:
Dim BlockCoords(,) As Integer = {{1,2},{2,2}}
The problem is, I don't know how initialising multidimensional arrays works - like in that example, what do 1,2 and 2,2 refer to? How could I specifically assign a down and across value on the grid from those? Essentially, I want to be able to declare all the coordinates in one line so that I can save the level files elsewhere and call them as and when. I'm not even entirely sure if I want to be using 2D arrays or nested arrays. Basically, I just need some clarification on how these things work ^^'.
Hope y'all can help, much love.
I've been working on an Ice Puzzle: you're a character (e.g. '*') in a grid (2D array) and you can move using the arrow keys - when you move, you keep going in that direction until you hit a surface. The aim is to pick up a key, which progresses you to the next level. There are three elements that need to be placed on the grid as different characters: the player (*), the block (█), the key (~).
I've got everything mostly working, and I'm at the point where I can change around the layout of the board from the initialised variables outside the Sub. The problem is, it's messy, and it's not intuitive for even me to work with, let alone someone else who wanted to tinker with the code. I'll give an example (I don't want to post the full code simply because it's so long.)
VB.NET:
Dim PlayerCoord() As Integer = {7, 4} 'Player Coordinates, read DOWN and then ACROSS.
Dim BlockDown() As Integer = {7, 6, 2, 1} 'Block Coordinates DOWN
Dim BlockAcross() As Integer = {3, 4, 7, 3} 'Block Coordinates ACROSS
Dim KeyDown As Integer = 7 'Key Coordinates DOWN
Dim KeyAcross As Integer = 2 'Key Coordinates ACROSS
As you can see, it's a tad convoluted. I assign all the values using this Sub.
VB.NET:
Sub PlaceObjectElements()
For i = 0 To BlockAcross.Count - 1
PlayGrid(BlockDown(i), BlockAcross(i)) = BlockCursor
Next
PlayGrid(KeyDown, KeyAcross) = KeyCursor
PlayGrid(PlayerCoord(0), PlayerCoord(1)) = PlayerCursor
End Sub
What I want to be able to do for the BlockCoordinates is have coordinates within the array. So I imagine it might look something like this:
Dim BlockCoords(,) As Integer = {{1,2},{2,2}}
The problem is, I don't know how initialising multidimensional arrays works - like in that example, what do 1,2 and 2,2 refer to? How could I specifically assign a down and across value on the grid from those? Essentially, I want to be able to declare all the coordinates in one line so that I can save the level files elsewhere and call them as and when. I'm not even entirely sure if I want to be using 2D arrays or nested arrays. Basically, I just need some clarification on how these things work ^^'.
Hope y'all can help, much love.