So, is there an implemented 2d boxes or pixel-perfect/circle collision, or we are supposed to write them ourselves? I'd like to know if i will be capatible to do everything which will fulfill my needings before i purchase .
:sign0085:
@Edit
And is there any handful arrays library?
Because setting every value of array is pretty tought.
Multi-dimensional arrays are possible with B4A (I've not gone beyond 2 dimensions yet though), as well as your logic for looping the arrays and drawing the maps, yep.. they're do-able in B4A.
Multi-dimensional arrays are possible with B4A (I've not gone beyond 2 dimensions yet though), as well as your logic for looping the arrays and drawing the maps, yep.. they're do-able in B4A.
I have a maze program I am working on, which is similar to your 2d map.
I have a 2d array
B4X:
Dim Maze (20,20) As Boolean
Then after generating the maze in this array (True = a wall, False = empty space) I draw it with
B4X:
Sub DrawMaze
Dim DestRect As Rect
For i = 0 To 19
For j = 0 To 19
DestRect.Initialize (i*CellSize, j*CellSize, (i+1)*CellSize , (j+1)*CellSize)
If Maze (i,j) Then
MazeCanvas.DrawBitmap ( Wall, Null, DestRect)
Else
MazeCanvas.DrawBitmap ( Empty, Null, DestRect)
End If
Next
Next
Activity.Invalidate
End Sub
here you go, 2 dimensions array of panels which displays with a random color.
B4X:
Sub Globals
Dim p(10,10) As Panel 'use imageview if u wanna use tiles images
End Sub
Sub Activity_Create(FirstTime As Boolean)
For i = 0 To 9
For j = 0 To 9
p(i,j).Initialize("")
Activity.AddView(p(i,j), i * 10%x, j * 10%y, 10%x, 10%y)
p(i,j).Color = Rnd(Colors.Black,Colors.white) 'set your image to panel or imageview here
Next
Next
End Sub
Okay, tell me if that code would be valid&working for your method please:
B4X:
Dim Table As String
Table = File.ReadString(File.DirInternal,"ScoreTable.txt")
Dim ArrayOf6Dimensions(3,3,3) As Int
Dim Line as Int
Line = 0
c = Table.IndexOf(Level)
Table = Table.SubString(c)
For y = 0 To 2
For x = 0 to 2
d=Table.IndexOf(",")
ArrayOf6Dimensions(y,y,y) = Table.SubString2(Line,d)
Table = Table.SubString(d + 1)
Next
Line = Line + 4
Next
Lets assume your map is stored in assets, and is named Map.txt. Map.txt contains integers
B4X:
1,2,3
4,5,6
7,8,9
so a 3x3 map just for illustration
First load up the StringUtils library
Then use this code to extract the data into a 3x3 array of Integers called MyMap
B4X:
Dim MyMap (3,3)As Int ' this would normally be a global - I put it here
' so you can see what the code is working on
Dim su As StringUtils
Dim Table As List
Dim Dummy () As String
Table = su.LoadCSV(File.DirAssets, "Map.txt", ",")
For i=0 To 2
For j= 0 To 2
Dummy = Table.Get (i)
MyMap (i,j)= Dummy(j)
Next
Next
If you add the file (inthe Files tab of the IDE), it will be stored in the apk, and be available via File.DirAssets. It is also stored in the "Files" directory of your app, so you can edit it from there - it will be updated when you compile your code.
You are correct, it is THAT simple, and it allows you to tinker with your map without messing with your code. I think this method is superior to hardcoding.
Dim MyMap (3,3)As Int ' this would normally be a global - I put it here
' so you can see what the code is working on
Dim su As StringUtils
Dim Table As List
Dim Dummy () As String
Table = su.LoadCSV(File.DirAssets, "Map.txt", ",")
For i=0 To 2
Dummy = Table.Get (i)
For j= 0 To 2
MyMap (i,j)= Dummy(j)
Next
Next