2D Array Help

Blitz3D Forums/Blitz3D Programming/2D Array Help

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

It would be best to set up something like values for each color\type of block. So you wouldn't need to use types, you'd just go through the array and:
TotalBlocksX = 16 ;16 blocks width-wise, where each image should have 40 pixels in width.
TotalBlocksY = 7 ;7 rows of blocks, each one having 40 pixels too in height. 

 Dim Blocks(TotalBlocksX,TotalBlocksY) 



Restore Level_1

For W = 0 To TotalBlocksX-1
      For H = 0 To TotalBlocksY-1
            Read Blocks(W,H)
      Next
Next

.Level_1 
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
Data 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
Data 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
Data 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

Then you could have differente block images for each color\type of block (the main reason for keeping different coloured blocks is, besides being able to draw "pictures" every level and make nice mozaics\patterns with the blocks, enabling items to fall down; each item depending on the block type, of course. There also can be different hardness between the block colors, so as to have blocks that need more than one hit to break).

In order to draw the blocks, judging you'd have 3 types of blocks:
For W = 0 To TotalBlocksX-1
      For H = 0 To TotalBlocksY-1
    
            Select Blocks(W,H)
                       Case 0
                                DrawImage Block1,W*40,H*40
                       Case 1
                                DrawImage Block2,W*40,H*40
                       Case 2
                                DrawImage Block3,W*40,H*40 
           End Select
      
      Next
Next