moving 1 to another position if keyhit is true?

BlitzMax Forums/BlitzMax Beginners Area/moving 1 to another position if keyhit is true?

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.

No no, I meant do it like this:


; Assumes global X and Y
; Remember to check for moving outside of the array,
; and to include some sort of delay.

Function moveblock()

	If KeyHit(KEY_RIGHT)

   		array[X,Y] = 0
   		X = X + 1
   		array[X,Y] = 1
		
	EndIf
	
	If KeyHit(KEY_LEFT)
	
   		array[X,Y] = 0
   		X = X - 1
   		array[X,Y] = 1

	EndIf 
	
	If KeyHit(KEY_DOWN)
	
   		array[X,Y] = 0
   		Y = Y + 1
   		array[X,Y] = 1	

	EndIf
	
	If KeyHit(KEY_UP)
	
   		array[X,Y] = 0
   		Y = Y - 1
   		array[X,Y] = 1

	EndIf

End Function


Your method requires only one variable. Imagine a 3 x 3 array is numbered like this:

    0 1 2
    # # #
0 # 0 1 2
1 # 3 4 5
2 # 6 7 8


If BoxPos was say 5, then by the above grid, it is stored in column 2, row 1. The array is a 3 x 3 grid. 5 Mod 3 = 2, the column number, and 5 / 3 = 1, the row number. Try it for other values of BoxPos to see how it works. However, this method is far slower and less natural than the one above - use the one with the X and the Y.

Ryan