DrKane
2002.08.29, 10:24 PM
I'm in the middle of working on my sprites for my rpg engine. I track all entites using fine coordinates(although movements are restricted on a tile grid). My game displays 11 x 11 tiles at a time on the screen(they're offset slightly for scrolling). I've been trying to figure out how to determine where on the screen to draw my enemy sprite. Here's an example of what I've been trying wihtout much success:
void MoveSprite()
{
Point enemyPoint = GetEnemyPoint();
// code.....
SetRect(&sprite->destScreenRect, enemyPoint.h - (5 * kTileSizeH), enemyPoint.v - (5 * kTileSizeV),
enemyPoint.h + (5 * kTileSizeH), enemyPoint.v + (5 * kTileSizeH);
}
Point GetEnemyPoint()
{
Point world, screen;
for (world.h = player.position.h - (6 * 32), screen.h = 0; world.h < ( (player.position.h + 32) + (6 * 32), screen.h < (13 * 32) ); world.h++, screen.h++)
{
for (screen.v = player.position.v - (6 * 32), screen.v = 0; world.v < ( (player.position.v + 32) + (6 * 32), screen.v < (13 * 32) ); world.v++, screen.v++)
{
if ( (h == world.h) && (v == world.v) )
{
return screen;
}
}
}
}
My player sprite works fine I just can't figure out how to practically determine where on the screen to draw the enemy relative to the player's coords. Any suggestions?
void MoveSprite()
{
Point enemyPoint = GetEnemyPoint();
// code.....
SetRect(&sprite->destScreenRect, enemyPoint.h - (5 * kTileSizeH), enemyPoint.v - (5 * kTileSizeV),
enemyPoint.h + (5 * kTileSizeH), enemyPoint.v + (5 * kTileSizeH);
}
Point GetEnemyPoint()
{
Point world, screen;
for (world.h = player.position.h - (6 * 32), screen.h = 0; world.h < ( (player.position.h + 32) + (6 * 32), screen.h < (13 * 32) ); world.h++, screen.h++)
{
for (screen.v = player.position.v - (6 * 32), screen.v = 0; world.v < ( (player.position.v + 32) + (6 * 32), screen.v < (13 * 32) ); world.v++, screen.v++)
{
if ( (h == world.h) && (v == world.v) )
{
return screen;
}
}
}
}
My player sprite works fine I just can't figure out how to practically determine where on the screen to draw the enemy relative to the player's coords. Any suggestions?