Here is a simple piece of code we came up with thanks to Stef.
The idea is to be able to move your character in 4 directions only, allowing you to deviate from the direction you are focusing on.
This sentence makes no sense... Just think this is how the character moves in town in Shining Force 2.
Hoping it will help someone
Code: Select all
void move()
{
static u16 prev_dir = 0;
u16 pad = JOY_readJoypad(JOY_1);
u16 dir = pad & BUTTON_DIR;
u16 dir_com = prev_dir & dir;
if (dir != prev_dir) dir ^= dir_com;
if(dir & BUTTON_LEFT)
{
Sprites[0].PosX--;
}
else if(dir & BUTTON_RIGHT)
{
Sprites[0].PosX++;
}
if(dir & BUTTON_UP)
{
Sprites[0].PosY--;
}
else if(dir & BUTTON_DOWN)
{
Sprites[0].PosY++;
}
if (!dir_com) prev_dir = dir;
}