PDA

View Full Version : The "canMove" function



C-Dawg
10-18-2006, 09:13 PM
Saffith uses the "canMove" function, which I presume checks whether a given location is walkable on layer 0. I'd like to use this function too, but I don't see it posted anywhere.

Any clues?

EDIT - Nevermind, I found it.

// Check whether the trap can move into a certain tile.
// Returns true if the tile on layer 0 is within the
// range of the screen and no part of it is solid.
bool canMove(int x, int y)
{
if(x<0 || x>240 || y<0 || y>160)
return false;

return Screen->ComboS[y+(x>>4)]==0;
}
}

EDIT 2 - Aaaaand now I'm getting an error message that "screen" is undefined. What the...

EDIT 3 - Apparently the "screen" pointer can only be used INSIDE an ffc script. It cannot be placed in a global function.

Saffith
10-18-2006, 09:35 PM
I'm guessing it doesn't like where you put it:

ffc script foo
{
void run()
{
}

// Here is fine
}

// Here, outside of the script, Screen is undefined
// I believe the same is true of Link and Game
(Edit: Ah, beaten to it.)

By the way, that function returns false if any part of a tile is unwalkable, not if that exact point is. I've been meaning to work out a more precise version, but I haven't done that just yet.

C-Dawg
10-18-2006, 09:46 PM
Thats good enough. Im working on the charging Moblin boss and wall-hugging spark from Link's Awakening, and they stick with a grid.

DarkDragon
10-20-2006, 07:53 AM
EDIT 3 - Apparently the "screen" pointer can only be used INSIDE an ffc script. It cannot be placed in a global function.

There's no reason this must be true, and should be fixed.