Flawless 4-way movement

You must understand the Game Editor concepts, before post here.

Flawless 4-way movement

Postby Hblade » Wed Jan 30, 2013 6:17 pm

Throughout the years we've made plenty of RPG type walking systems, but if you look in RPG Maker the movement is flawless (While moving if you press another key, the other key is disabled for example, so if you hold up and left, your not-always- going to go up or left, you go in the last direction you pressed unless its the opposite direction your going now, in which case you stop in place). Not to mention you move via tiles, and in RPG maker the collision detection is way different.

Is there a way to use GameEditor to replicate this style of movement perfectly?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Flawless 4-way movement

Postby EvanAgain » Wed Jan 30, 2013 7:24 pm

I wrote a function for grid based movement awhile back for my ISO game. Grid based movement is easy and what you can do is basically check at each tile which direction to move next.

Code: Select all
const int MAPWIDTH = 10;
const int MAPHEIGHT = 10;
const int TILESIZE[2] = {64, 32}; //size of each tile. W x H
const int cMAPSIZE    = 100; //Amount of tiles to be created


const int cUNREACHABLETILE = 255; //The start of the unwalkable tile animation



int NodeID[cMAPSIZE] = {};
int NodeX[cMAPSIZE] = {};
int NodeY[cMAPSIZE] = {};


int  TilesID[cMAPSIZE] = {};  //TileID's and corresponding X,Y
int  TilesX[cMAPSIZE] =  {};
int  TilesY[cMAPSIZE] =  {};

int Moving = 0;

void CreateMap()
{
 int mh;
 int mw;
 int tX = 0;
 int tY = 0;
 int tNum = 0;
 char tName[10];
 
 for(mh = 0; mh < MAPHEIGHT; ++mh)
 {
     tY = (TILESIZE[0] * mh) + (TILESIZE[0]/2);
     for(mw = 0; mw < MAPWIDTH; ++mw)
     {
         tX = (TILESIZE[1] * mw) + (TILESIZE[1]/2);
         NodeX[tNum] = mw;
         NodeY[tNum] = mh;
         TilesID[tNum] = tNum;
         TilesX[tNum]  = tX;
         TilesY[tNum]  = tY;
         tNum = tNum +1;
     }
 }
 
 
}


void MoveToNode(int nID) //Actor ID, Node ID
{
    //ID 0 = Tile 0 X:0 Y:0 AI STARTING POINT
    //ID 1 = Tile 1 X:1 Y:0
    //ID 2 = Tile 2 X:0 Y:1
    //ID 3 = Tile 3 X:1 Y:1
    //ID 4 = Tile 4 X:0 Y:2
 
    int len = sizeof(TilesID)/sizeof(int);
    int i;
 
    for(i = 0; i < len; ++i)
    {
        if(TilesID[i] == nID)
        {
            MoveTo("myActor", TilesX[nID], TilesY[nID], 3, "Game Center" , "");
 
        }
    }

}

void MoveToXY(int x, int y) //Actor ID, x coordinate, y coordinate
{
    //ID 0 = Tile 0 X:0 Y:0 AI STARTING POINT
    //ID 1 = Tile 1 X:1 Y:0
    //ID 2 = Tile 2 X:0 Y:1
    //ID 3 = Tile 3 X:1 Y:1 DESTINATION
    //ID 4 = Tile 4 X:0 Y:2
    int nID;
    int len = sizeof(NodeX)/sizeof(int);
    int i;
 
    for(i = 0; i < len; ++i)
    {
        if(NodeX[i] == x)
        {
            if(NodeY[i] == y)
            {
                nID = i;
                MoveToNode(nID);
            }
        }
    }
}



Something like that. What this does is creates a grid and nodal coordinate. Then you can move to specific locations using nodes. Using something like.

Code: Select all
//ON LEFT KEY PRESS
if(!Moving)
{
    MoveToXY(currentNodeX - 1, currentNodeY);
}


Or something like that... It's basically all there. Most of the code I made was not for keyboard functions but for AI movement and was first tested with keyboard movement.


Actually, if you look over my ISO-MAPMAKER program. I use keyboard presses and functions like these, to move around.

The keyboard movement is located on the MiddlePoint Actor. The fuctions are within the code.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Flawless 4-way movement

Postby Hblade » Wed Jan 30, 2013 11:49 pm

+1, I love the way your code looks its neat and clean
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Flawless 4-way movement

Postby EvanAgain » Thu Jan 31, 2013 12:53 am

There is still a lot of modifications that need to be done with my code but.... I figure you're pretty smart :D

When my project is finished I will have to redo my AI code. The code should allow for 8-way movement as well. I set it up to be portable to many different uses and even to allow to work WITHOUT tiles.

Nodal movement is exactly like pixel per pixel movement. Except that the pixel per node ratio can be modified to make a Q-Bert style movement, or smaller distance between nodes for use in RTS games.

When my project is finished RTS functions are in my mind. In game customizable formations!! As well as movement patterns and strategy. I really want to go all out..

But I have so much work to do on this one project that it will probably be awhile...

I post all my code to the forum and once my project is complete it will be turned into a single, game template. Everything will be managable even by "noobs". They won't even have to understand how the functions work, just that they can plug the functions into the actor and go.

At least, this is how I envision it XD


HBlade, Keep up the good work. I have noticed a lot of good things come from you lately. One of your programs, a "Struct" creator? Well, that tool, if modified for my purposes, will come in VERY useful!

I haven't really gotten around to checking out many other things because, Big Project/Lone Wolf. XD Good luck, and awesome work!
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Flawless 4-way movement

Postby Hblade » Thu Jan 31, 2013 8:46 pm

Thank you Evan! :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron