So, I've designed a simple 9 panel world map for my character to play around in. The problem is, getting him to travel inside of it accurately is giving me some trouble.
The concept is simple. There are nine areas, shaped like a box with nine smaller boxes:
1 2 3
4 5 6
7 8 9
And here is the code for him to travel inside it:
if(level == 1)
{
if(getX() > 697)
{
level = 2;
}
if(getY() > 497)
{
level = 4;
}
}
if(level == 2)
{
if(getX() > 694)
{
level = 3;
}
if(getX() < 4)
{
level = 1;
}
if(getY() > 494)
{
level = 5;
}
}
if(level == 3)
{
if(getX() < 4)
{
level = 2;
}
if(getY() > 494)
{
level = 6;
}
}
if(level == 4)
{
if(getX() > 694)
{
level = 5;
}
if(getY() < 4)
{
level = 1;
}
if(getY() > 494)
{
level = 7;
}
}
if(level == 5)
{
if(getX() > 694)
{
level = 6;
}
if(getX() < 4)
{
level = 4;
}
if(getY() > 494)
{
level = 8;
}
if(getY() < 4)
{
level = 2;
}
}
if(level == 6)
{
if(getX() < 4)
{
level = 5;
}
if(getY() < 4)
{
level = 3;
}
if(getY() > 494)
{
level = 9;
}
}
if(level == 7)
{
if(getX() > 694)
{
level = 8;
}
if(getY() < 4)
{
level = 4;
}
}
if(level == 8)
{
if(getX() < 4)
{
level = 7;
}
if(getX() > 694)
{
level = 9;
}
if(getY() < 4)
{
level = 5;
}
}
if(level == 9)
{
if(getX() < 4)
{
level = 8;
}
if(getY() < 4)
{
level = 6;
}
}
Now, a pro can spot the problem immediately. But I'm NOT a pro, so it took me a while.
When he travels from an area of a greater number to an area of a lesser number, all works well because the if conditions for the lesser numbers has already been checked and found to be false.
However, if he is traveling from say, area 1 and heads downward, then it checks the condition for area 1 and then takes him to area 4, and THEN in the same act cycle checks the condition for 4 and takes him to area 7.
Crap.
Anyone know of a way around this? Is there a way to have him only execute only ONE of these if statements per act cycle?
A solution would be to break up each statement into it's own method, but... talk about sloppy programming. that's a LOT of excessive methods to stick into the act method.
Can anyone help me?
TIA
-Minion

