I'm working on a new game, and it involves grid movement. I first set it up using a bunch of if statements, but then a friend helped me realize there was an easier way. I thought it was neat, and could help some people out. Also, there are many other things you can do with this method as well. Let me know what you think, or if you need help understanding something better.
This should go in the Step event for the object you are controlling.
CODE
x=x
y=y
//This is the amount of that you move each time
mspace = 32
/*These are the grid limits, and they set the grid boundries. Right now their for a 10x10 grid.
If your grid is bigger, change the xrbound and the ydbound*/
xlbound = mspace*0
xrbound = mspace*9
ydbound = mspace*9
yubound = mspace*0
y = min( max( y - mspace * keyboard_check_pressed( vk_up )+ mspace * keyboard_check_pressed( vk_down ), yubound ), ydbound )
x = min( max( x - mspace * keyboard_check_pressed( vk_left )+ mspace * keyboard_check_pressed( vk_right ), xlbound ), xrbound )
~LC~
This post has been edited by LarsonCreativity: Feb 28 2010, 10:59 AM