This is PSEUDOCODE
This is how I'm converting mouse to world coordinates:
Code: Select all
worldX = mouseX * cam.scale + player.x
Code: Select all
dx = (goalX - player.x);
dy = (goalY - player.y);
player.x += (dx) * 1/50;
player.y += (dy) * 1/50;
I print out both the worldX coordinates and mouseX coordinates and they equal the same even though the player is not following the mouse...
I also have a camera class and the basic code for the camera is:
scale(1,1);
Code: Select all
cam.x = ((-player.x + player.mass * 0.5) + Game.width/sX * 0.5)* sX;
cam.y = ((-player.y + player.mass * 0.5) + Game.height/sY * 0.5)* sY;
And to finish it off I have to methods that actually translate the screen based on the camera's coordinates
Code: Select all
g2.translate(x,y);
g2.scale(sX,sY);
-- Draw everything in the world
g2.translate(-x, -y);