Function moveblock() If KeyHit(KEY_LEFT) For Local x:Int = 0 To 9 For Local y:Int = 0 To 9 If array:Int[x,y] = 1 array[x+1,y] EndIf Next Next EndIf End Function
if I fill my array with 0's and assign just one position the number one. I can draw a box at that position in the array if it equals 1.
Now, If i wanted the box to move position I would set a different position in the array the number 1. Then when I run the code the box is drawn at a different location. I do this by manually assigning the value outside of a loop before I run the code.
Looking at the code above I'm trying to move the box from one position in the array to the next available position in the array using keyhit().
It's obviously not working. I'll try some more ideas but a little help would be appreciated.
Heres is all the code :
Strict Rem Array Movement for game End Rem 'Setup Graphics Mode Graphics 800,600,16,0 'set Alpha SetMaskColor 0,0,0 'load image Global box:TImage = LoadImage("icon.png",MASKEDIMAGE) 'Array Origin Global mapx:Int, mapy:Int mapx = 10 mapy = 10 'Setup array Global array:Int[10,10] ' Fill array with data For Local x:Int = 0 To 9 For Local y:Int = 0 To 9 array:Int[x,y] = 0 Next Next 'set 1 position of array to 1. I do this manually. Change to have the box drawn elsewhere. array:Int[0,0] = 1 Repeat Cls drawblock() moveblock() FlushMem Flip Until KeyHit(KEY_ESCAPE) Function drawblock() For Local x:Int = 0 To 9 For Local y:Int = 0 To 9 If array:Int[x,y] = 1 DrawImage box,Mapx+x*50,mapy+y*50,0 EndIf Next Next End Function Function moveblock() If KeyHit(KEY_LEFT) For Local x:Int = 0 To 9 For Local y:Int = 0 To 9 If array:Int[x,y] = 1 array[x+1,y] EndIf Next Next EndIf End Function
the image is here :