# Moving across placed tiles

This topic is 4423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay. I am working on a megaman battle network fan game and I'm stuck with a little problem: the overworld. I've created arrays to place tiles wherethe X and Y coordinances are which works fine. My character also moves fine, but he won't stay in the given coordinances of the tiles. Heres the coordinances:
	/*Tryout area.*/
MapData1.type = 2;
//bottom layer
MapData1.X[0] = -4;  	MapData1.X[1] = -4;
MapData1.Y[0] = -2;     MapData1.Y[1] = -1;
//middle layer
MapData1.X[2] = -4;  	MapData1.X[3] = -3;
MapData1.Y[2] = 0;      MapData1.Y[3] = 0;
MapData1.X[4] = -2;  	MapData1.X[5] = -1;
MapData1.Y[4] =  0;     MapData1.Y[5] = 0;
//top layer
MapData1.X[6] = -1;  	MapData1.X[7] = -1;
MapData1.Y[6] = 1;      MapData1.Y[7] = 2;


The tiles are then place perfectly, but I want my character to only wlak across these tiles. I've used this function to make sure this happens. It works, but not well at all:

void Move(bool x, bool y, bool neg)
{
static int ix=0; static int iy=0;

if(x && neg)
{
ix +=1;
if(MapData1.X[ix] < MapData1.X[ix+1] && walkx >= MapData1.X[ix])
{
b_walkx1 = true;
}
else
{
b_walkx1 = false;
}

}

else if(x && !neg)
{
ix-=1;
if(MapData1.X[ix] > MapData1.X[ix-1] && walkx <= MapData1.X[ix])
{
b_walkx2 = true;
}
else
{
b_walkx2 = false;
}
}

if (y && neg)
{
iy +=1;
//The iy stage, or the index of y IofY
if(MapData1.Y[iy] < MapData1.Y[iy+1] && walky >= MapData1.Y[iy])
{
b_walky1 = true;
}
else
{
b_walky1 = false;
}
}

else if(y && !neg)
{
iy-=1;
if(MapData1.Y[iy] > MapData1.Y[iy-1] && walky <= MapData1.Y[iy])
{

b_walky2 = true;
}
else
{
b_walky2 = false;
}
}

if(ix<=0){ix=0;}if(ix>=7){ix=7;}
if(iy<=0){iy=0;}if(iy>=7){iy=7;}

}


By looking at this, I'm trying to check to see if the next space the character will move in will be a tile or not. If so, it moves ahead by setting the b_walk*(x,y|1,2) to true or false. My results are the haracter moves, but sometimes won't go back to the last spot or the character moves too far and keeps going. I really need help with this since I've been working on this for a month now and i'm sure one of you esquisite programmers who are far more better than me would kindly help. If you do help solve this problem, I will add you to the credits. ~Thank you ~Axesor (website url for project: www.atfreeforum.com/pcn)

##### Share on other sites
Hello.
I don't understand wholy a procedure.
What is i.e walkx and walky?
But there are certain problems in your example.

static int ix=0; static int iy=0;

If just one entity (player or enemy) use that procedure, that is ok.
But since that is not part of class, I doubt it.
Using static variables in game, where two or more entities use same procedure can be very dangerous. Personalize it for player or enemy, or for anything that use such a routine.

Another one mistake is that Move procedure will work correctly ONLY if:
Move(x,0, true)
Move(x,y, false)
Move(0,y, true)
Move(0,y, false)

because if you call it with Move(x,y, true) program will execute
block of (x&neg) and later (y&neg) too.

Also you are using four bool variables to determine which direction player moved:
b_walkx1, b_walkx2, b_walky1, b_walky2
Why not use one POINT variable? Like:
POINT m_ptDirection;
m_ptDirection.x = -1; // left
m_ptDirection.x = 1; // right
m_ptDirection.y = -1; // up
m_ptDirection.y = 1; // down

m_ptDirection.x = 0;
m_ptDirection.y = 0; // not moving

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009713
• ### Who's Online (See full list)

There are no registered users currently online

×