Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Quick Question for a little 2d game.

Author
Message
Morb
14
Years of Service
User Offline
Joined: 28th Aug 2009
Location:
Posted: 7th Oct 2015 23:41
So, I am currently trying to build some kind of arkanoid clone and I would like to be able to do the following:
- Make a txt file with a grid of data name for example level 3 that would look like
0,0,1,2,3,1,2,1,0,0
0,0,1,2,3,1,2,1,0,0
0,0,1,2,3,1,2,1,0,0
0,0,1,2,3,1,2,1,0,0
0,0,0,0,0,0,0,0,0,0
- Load the file, read the data, and then build the screen where a 0 would be a blank space, a 1 a yellow brick a 2 a green brick and so on

So far i'm on this track of progress
Dim BrickData(2) [2 dimensional array to read line X and col Y right?]
open to read 1,"Level3.txt"
i'm guessing i'll need 2 "for/next" loop one "the size" of the "data width" and one for the "height"
How can I read each value and store it in the array separately?

And after that, How can I read each index of said array.

Thanks in advance, i remember finding a great code example for this but I could not find it with the search...

Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Oct 2015 00:04 Edited at: 8th Oct 2015 00:10
So what you stated there, Dim BrickData(2) , produces a single dimension array. The figure 2 represents the length of the array + 1 in dark basic terminology, counting from 0, 1, 2. What you do with index zero is entirely up to you.

To make it a multidimensioned array, you need an additional parameter in your declaration. So if your level is 10 rows by 10 columns, you would write Dim BrickData(10,10); (or BrickData(9,9) as you would in most programming languages)

You could then loop through the array as I have done here:


This is pretty easy to understand after some practice; but the assumed limitation of this approach is that the array permits just one game level, and all game levels are the same size. Assumed because this depends on how the array is used.

You can store more than one piece of information in each array entry using a User Defined Type, as shown in the help files. I have shown in the snippet how I obtained the texture number from the brick data, using the texture field name at the end.

Login to post a reply

Server time is: 2024-04-26 03:57:28
Your offset time is: 2024-04-26 03:57:28