How to Make a Grid-Based RPG Movement

I just decided to make an article on a fairly simple grid-based RPG movement that I made up. A grid-based RPG movement is similar to a movement in games such as 'final Fantasy (I-VI)' and 'Pokémon'. They help keep your character in set grid positions, and stop you from going through walls clearly. They basically help keep your character 'on track'.
So here it is!

Objects needed:

32x32 Player object (Active)
16x32 Left Detector (Active)
16x32 Right Detector (Active)
32x16 Top Detector (Active)
32x16 Bottom Detector (Active)
Horizontal counter (or alterable value)
Vertical counter (or alterable value)
32x32 Obstacle backgrounds

The sizes can be altered, but they will need to be altered in the same ratio, so if you make the player 50x50, everything else with size 32 will need to be 50, and everything with size 16 will need to be 25. This rambling has almost no point.

At the start of the level, the detectors need to be placed, and made invisible, so:

-Start of level
...Set position to X=X(player), Y=Y Bottom(Player)
(bottom detector)
...Set position to X=X(player), Y=Y Top(Player)
(Top detector)
...Set position to X=X Right(Player), Y=Y(Player)
(Right detector)
...Set position to X=X Left(Player), Y=Y(Player)
(Left detector)
...Make invisible
(All detectors)

Ok, now on to...

Controlling the movement

Ok, this shows the objects moving 32 pixels per move, so change the counter value if you want it different.
When the player is holding a direction, and the counters are 0, and that direction's detector is neither over an obstacle or outside the play area, the counter signalling 32 pixels in that direction is set.

Moving down:

-Repeat while (Player 1) moved down
+(Horizontal counter)=0
+(Vertical counter)=0
+Y position of (Bottom detector) < Playfield Height
+(Bottom) is over an obstacle background
...Set Vertical counter to 32

Moving up:

-Repeat while (Player 1) moved up
+(Horizontal counter)=0
+(Vertical counter)=0
+Y position of (Top detector) > 0
+(Top) is over an obstacle background
...Set (Vertical counter) to -32

Moving left:

-Repeat while (Player 1) moved left
+(Horizontal counter)=0
+(Vertical counter)=0
+X position of (Left detector) > 0
+(Left) is over an obstacle background
...Set (Horizontal counter) to -32

Moving right:

-Repeat while (Player 1) moved right
+(Horizontal counter)=0
+(Vertical counter)=0
+X position of (Right detector) < Playfield width
+(Right) is over an obstacle background
...Set (Horizontal counter) to 32

OK! That's all for movement counter settings, now onto...
ACTUAL MOVEMENT!

Now, you want this to move towards the direction, not just appear on the direction.
So, what you do is move it 4 pixels towards the direction at a time, and remove 4 from the counter. This moves it quite fast in that direction, it reaches the destination in 8 frames. It can be modified to move faster or slower, by making it move:
1 pixel per frame (very slow - takes 32 frames),
2 pixels per frame (quite slow - takes 16 frames),
8 pixels per frame (very fast - takes 4 frames),
or 16 pixels a frame (almost instant - takes 2 frames).
If you do change it though, you will have to remove the same amount from the counter as the number of pixels you move the player.
Here's the code...

Moving right:

-Horizontal counter > 0
...Set position to X=X(current object) + 4
(player & all detectors)
...Subtract 4 from (Horizontal counter)


Moving left:

-(Horizontal counter) < 0
...Set position to X=X(current object) - 4
(player & all detectors)
...Add 4 to (Horizontal counter)

Moving up:

(Vertical counter) < 0
...Set position to Y=Y(current object) - 4
(player & all detectors)
...Add 4 from (Horizontal counter)


Moving down:

-(Vertical counter) > 0
...Set position to Y=Y(current object) + 4
(player & all detectors)
...Subtract 4 from (Horizontal counter)

Well, I think that's pretty much it, it's a bit simple now, but you can add more features later, maybe.

Here's an example file showing you how it's done (if you're really that lazy... Which I assume you are...). In the example you can press tab to show/hide the detectors.

TTFN - This means Ta Ta For Now, for those of you who are, let's say... Ignorant.

PHIZZY
[Insert Evil Laugh Here]

Return to Phizzy Games - Home.