K Kamac Active Member Licensed User Longtime User Jul 7, 2011 #1 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. Last edited: Jul 7, 2011
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.
Erel B4X founder Staff member Licensed User Longtime User Jul 8, 2011 #2 For now you will need to write the collision detection method yourself. You can use the Array keyword to fill an array: B4X: Expand Collapse Copy Dim s() As String s = Array As String("a", "b", "c") Upvote 0
For now you will need to write the collision detection method yourself. You can use the Array keyword to fill an array: B4X: Expand Collapse Copy Dim s() As String s = Array As String("a", "b", "c")
K Kamac Active Member Licensed User Longtime User Jul 8, 2011 #3 For now you will need to write the collision detection method yourself. Click to expand... Hmm. Allright. You can use the Array keyword to fill an array: Click to expand... I'd rather mean of arrays to create maps (multi-dimensional). Here's an example of what i mean wrote in C/C++ B4X: Expand Collapse Copy Map[5][5]={ { 1,1,1,1,1 }, { 1,0,0,0,1 }, { 1,0,0,0,1 }, { 1,0,0,0,1 }, { 1,1,1,1,1 }, }; And here's how i would draw map with it: B4X: Expand Collapse Copy For(int y, y<5; y++) { For(int x, x<5; x++) { if(Map[y][x] == 1) { //Print some image of wall } } } I don't really know if that's possible in B4A. Upvote 0
For now you will need to write the collision detection method yourself. Click to expand... Hmm. Allright. You can use the Array keyword to fill an array: Click to expand... I'd rather mean of arrays to create maps (multi-dimensional). Here's an example of what i mean wrote in C/C++ B4X: Expand Collapse Copy Map[5][5]={ { 1,1,1,1,1 }, { 1,0,0,0,1 }, { 1,0,0,0,1 }, { 1,0,0,0,1 }, { 1,1,1,1,1 }, }; And here's how i would draw map with it: B4X: Expand Collapse Copy For(int y, y<5; y++) { For(int x, x<5; x++) { if(Map[y][x] == 1) { //Print some image of wall } } } I don't really know if that's possible in B4A.
S ssg Well-Known Member Licensed User Longtime User Jul 8, 2011 #4 Hi Kamac, 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. Cheers! Upvote 0
Hi Kamac, 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. Cheers!
K Kamac Active Member Licensed User Longtime User Jul 8, 2011 #5 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. Click to expand... Could you provide some sample please? Upvote 0
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. Click to expand... Could you provide some sample please?
K kickaha Well-Known Member Licensed User Longtime User Jul 8, 2011 #6 I have a maze program I am working on, which is similar to your 2d map. I have a 2d array B4X: Expand Collapse Copy 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: Expand Collapse Copy 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 Upvote 0
I have a maze program I am working on, which is similar to your 2d map. I have a 2d array B4X: Expand Collapse Copy 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: Expand Collapse Copy 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
S ssg Well-Known Member Licensed User Longtime User Jul 8, 2011 #7 here you go, 2 dimensions array of panels which displays with a random color. B4X: Expand Collapse Copy 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 Upvote 0
here you go, 2 dimensions array of panels which displays with a random color. B4X: Expand Collapse Copy 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
S ssg Well-Known Member Licensed User Longtime User Jul 8, 2011 #8 ahh... kickaha beat me to it! more samples for you then! Cheers! Upvote 0
K Kamac Active Member Licensed User Longtime User Jul 8, 2011 #9 I know all of these guys, i just don't know if it is possible to assign values to my 2 dimensional array. So if i have: B4X: Expand Collapse Copy Dim Maze (5,5) As Integer I want to draw my maze. 0 for grass, 1 for wall and 2 for sand. In C++ i can write to my array like that: B4X: Expand Collapse Copy Maze(5,5) = { { 1,1,1,1,1 }, { 1,2,2,2,1 }, { 1,0,0,0,1 }, { 1,0,0,0,1 }, { 1,1,1,1,1 }, }; And i don't know how can i write my map as in C++ i did. @kickaha How do you define how your maze will look like? That's what i'm asking for . Upvote 0
I know all of these guys, i just don't know if it is possible to assign values to my 2 dimensional array. So if i have: B4X: Expand Collapse Copy Dim Maze (5,5) As Integer I want to draw my maze. 0 for grass, 1 for wall and 2 for sand. In C++ i can write to my array like that: B4X: Expand Collapse Copy Maze(5,5) = { { 1,1,1,1,1 }, { 1,2,2,2,1 }, { 1,0,0,0,1 }, { 1,0,0,0,1 }, { 1,1,1,1,1 }, }; And i don't know how can i write my map as in C++ i did. @kickaha How do you define how your maze will look like? That's what i'm asking for .
K kickaha Well-Known Member Licensed User Longtime User Jul 8, 2011 #10 There is no way to directly assign values to multi-dimensional arrays that is similar to C++, you would have to assign each value separately. When I am defining an array like that, I populate it from a text file, that way the map is separate and can be changed without changing the code. The maze program that the code is from generates the maze, so each value is set individually. Upvote 0
There is no way to directly assign values to multi-dimensional arrays that is similar to C++, you would have to assign each value separately. When I am defining an array like that, I populate it from a text file, that way the map is separate and can be changed without changing the code. The maze program that the code is from generates the maze, so each value is set individually.
K Kamac Active Member Licensed User Longtime User Jul 8, 2011 #11 Okay, tell me if that code would be valid&working for your method please: B4X: Expand Collapse Copy 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 Or paste your method ? Upvote 0
Okay, tell me if that code would be valid&working for your method please: B4X: Expand Collapse Copy 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 Or paste your method ?
K kickaha Well-Known Member Licensed User Longtime User Jul 8, 2011 #12 Sorry mate, but I really cannot follow your code. I do it this way: Lets assume your map is stored in assets, and is named Map.txt. Map.txt contains integers B4X: Expand Collapse Copy 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: Expand Collapse Copy 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 Now thats (for me) the easy way Upvote 0
Sorry mate, but I really cannot follow your code. I do it this way: Lets assume your map is stored in assets, and is named Map.txt. Map.txt contains integers B4X: Expand Collapse Copy 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: Expand Collapse Copy 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 Now thats (for me) the easy way
K Kamac Active Member Licensed User Longtime User Jul 8, 2011 #13 It's really easy! Thanks :icon_clap: I have one question; Do i have to include the .txt with .apk then :sign0104:? Or the .txt is packed into it. Upvote 0
It's really easy! Thanks :icon_clap: I have one question; Do i have to include the .txt with .apk then :sign0104:? Or the .txt is packed into it.
K kickaha Well-Known Member Licensed User Longtime User Jul 8, 2011 #14 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. Upvote 0
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.
K Kamac Active Member Licensed User Longtime User Jul 9, 2011 #15 Thanks alot for your help . Upvote 0
K kickaha Well-Known Member Licensed User Longtime User Jul 9, 2011 #16 No - one spotted my error, code should have been B4X: Expand Collapse Copy 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 Upvote 0
No - one spotted my error, code should have been B4X: Expand Collapse Copy 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