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.

Newcomers DBPro Corner / Making a grid box, mixing it up! Array

Author
Message
Nights Bane
14
Years of Service
User Offline
Joined: 15th Dec 2009
Location:
Posted: 21st Aug 2010 18:17
I'm experimenting with my own little mining game, I figured i'd make an array/grid, and at the moment am simply trying to throw some random colouring into the grid. The following code creates a small grid, and using for loops and rnd() it should make certain blocks a different colour from the others.

The point - essentially- will be to have different soil textures every now and then to avoid the monotony of a single texture!. (im using 'color object' instead of 'texture object' here for more clarity in the beta testing stage)

the variable 'flipidi' or whatever, just refers to the reference of the array. It seemed as good a name as any!


Anyway: The bug is a runtime error, it creates a coloured 'line'(so to speak) along the x axis of the boxes, instead of individual boxes. Halp plz!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st Aug 2010 18:46 Edited at: 21st Aug 2010 18:48
You needed to position all of the different boxes correctly and your pick object command did not include all of the objects.



So many games to code.......so little time.
Nights Bane
14
Years of Service
User Offline
Joined: 15th Dec 2009
Location:
Posted: 21st Aug 2010 20:19
Thanks dude your a genuis, one thing I have to ask though is how does that %000 statement work? I only ask because I might need to increase the grid size, and I recognise it does something with remainders... so it might behave oddly if I go altering values now.

Say I want a grid size/array of array(100,100) for example, how would that alter the %000 statement? or would it at all?
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st Aug 2010 21:01
I could have simply shown it as 0, but chose to display it that way because you are using boolean for the grid. You really only needed %0, because your grid only has a value of one or zero.

%0000 corresponds with the lowest four bits of the value in grid(x,y). The lowest bit (on the right) equals 1, the next bit = 2, then next 4, the next 8 and so on and so forth. You add the bits that are set to one together to obtain the value. So, if I had %0101, you add 1 and 4 together to equal 5. %1110 corresponds to 14 (2 + 4 + 8 = 14).

The size of the grid itself does not matter; the value of the grid location is what matters. Using the four lowest bits will allow you to use values from 0 to 15. If you need more than that, add another digit and use %00000. Then you can use 0 to 31.

So many games to code.......so little time.
Nights Bane
14
Years of Service
User Offline
Joined: 15th Dec 2009
Location:
Posted: 22nd Aug 2010 23:31
Cheers alot LBFN. You're a star. Games coming on leaps and bounds now. I've even figured out UD Types! Programming is awesome, its like sudoku but you actually get something at the end of it! Really got a taste for this now.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 23rd Aug 2010 00:47
Great to hear. Best of luck to you with the game and with programming in general.

So many games to code.......so little time.

Login to post a reply

Server time is: 2024-11-27 02:16:06
Your offset time is: 2024-11-27 02:16:06