I'm trying to create a larn type game though I am having some issues with it. I am attempting to use a 2D array created from reading a file and then based on the values in the array it uses that as its world e.g. if there was a W it would be a wall, E for enemy etc.
I'm having some issues with movement, I know how to shift a value but was wondering if there was a way to have a value swapped such as if i wanted my character to move up it could swap with the value above it.
Please let me know if it's at all possible, the project im working on seems to have really thrown me into the deep end
CodePudding user response:
As I mentioned in the comment, swapping is easy, here's a subroutine that demonstrates it;
Sub SwapArrayCells(Arr As Variant, c11 As Integer, c12 As Integer, c21 As Integer, c22 As Integer)
Dim tmp As Variant
tmp = Arr(c11, c12)
Arr(c11, c12) = Arr(c21, c22)
Arr(c21, c22) = tmp
End Sub
However, generally you don't use a subroutine to do cell swaps, you just use those three assignment statements in-line (with the appropriate local variable names).
The problem that I mentioned in the comments is that if the other cells have things in them, like terrain, then you will be swapping the terrain around which would change your map.