Skip to main content
gamedev.net
🔒 Locked

Scrolling

Started by minich21 Apr 5, 2005 at 10:04 AM 2 replies 1.4k views
Original Post
minich21
minich21
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

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;

}


Move to Function

void CUnit::MoveTo(int x, int y)
{
	if(UnitSelected)
	{
		FinalPosition.x = x;
		FinalPosition.y = y;
	}
}


This is a snipet from the moving function

	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..



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
Wuzzbent
Wuzzbent
Don't know if this will help but...

mx = mouse.x / screen.width
my = mouse.y / screen.height

clickx = mx * tile_width - viewx Mod tile_width
clicky = my * tile_heigth - viewy Mod tile_height
-Wuzzbent
minich21
minich21
So this will give me world coords then? I'll have to try it out. cause my problem is that I click and the char moves to the spot I click in screen coords. which would work great if i didn't have scrolling.
Wuzzbent
Wuzzbent
Yes it will, but I made a little mistake, was doing a quick reply as I was in a hurry..

it's...

ClickX = Mouse.X / TILE_WIDTH
ClickY = Mouse.Y / TILE_HEIGHT

PosX = ClickX * TILE_WIDTH - CameraX Mod TILE_WIDTH
PosY = ClickY * TILE_HEIGHT - CameraY Mod TILE_HEIGHT


This will convert your Click cordz to real world cordz , works for me anyways

Wuzzbent
-Wuzzbent

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.