Original Post
I know there have been tons of topics on this, I've gone back through the last year of posts, still having problems... Ok, I have a simple tile map, I can smooth scroll it fine, my problem occurs when I attempt to involve the mouse, I believe my problem is with my screen to world coords... Below is my code, it's probaly all messed up now, been screwing with this for awhile now... Process Mouse Move to Function This is a snipet from the moving function like i said my codes all screwed up now, any ideas? Edit: forgot to add tile demensions #define MAPWIDTH 64 //total map width #define MAPHEIGHT 64 //total map height #define SCREENWIDTH 25 //tiles on screen #define SCREENHEIGHT 19 //tiles on screen #define MAPTILEWIDTH 64 //map tile width #define MAPTILEHEIGHT 48 //map tile height #define CHARTILEWIDTH 96 //player tile width #define CHARTILEHEIGHT 96 //player tile height
int CApp::ProcessMouse()
{
int Tile = 0;
POINT Point;
int TileX;
int TileY;
int UnitTile;
int OffsetX, OffsetY;
GetCursorPos(&Point);
MouseX = Point.x;
MouseY = Point.y;
OffsetX = Camera->ScreenX % MAPTILEWIDTH;
OffsetY = Camera->ScreenY % MAPTILEHEIGHT;
FinalMouseX = MouseX - OffsetX + Camera->ScreenX - (UNITTILEWIDTH / 2);
FinalMouseY = MouseY - OffsetY + Camera->ScreenY - UNITTILEHEIGHT;
int i;
for(i = 0; i < vecUnits.size(); i++)
{
if(App->LeftButtonDown)
{
vecUnits->CheckPosition(MouseX, MouseY);
}
if(App->RightButtonDown)
{
vecUnits->MoveTo(FinalMouseX, FinalMouseY);
}
}
return Tile;
}
void CUnit::MoveTo(int x, int y)
{
if(UnitSelected)
{
FinalPosition.x = x;
FinalPosition.y = y;
}
}
FindDirection(Position.x, Position.y, FinalPosition.x, FinalPosition.y);
if(FinalPosition.x >= 0 && FinalPosition.y >= 0)
{
if(FinalPosition.x > Position.x && FinalPosition.y == Position.y)
{
Position.x +=1;
Camera->ScreenX +=1;
}
//continues with ifs..