SGDK - Moving your character like in Shining Force 2

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
LIZARDRIVE
Newbie
Posts: 1
Joined: Fri Feb 01, 2019 10:06 am
Location: On a sunny rock
Contact:

SGDK - Moving your character like in Shining Force 2

Post by LIZARDRIVE » Sat Apr 13, 2019 6:06 pm

Hello,

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... :lol: Just think this is how the character moves in town in Shining Force 2.

Hoping it will help someone :wink:

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;
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest