0

This isn't so much a question as it is an 'anti-tunnel-vision' check.

I'm trying to get a camera/viewport working in a roguelike, but I'm not sure I'm doing things correctly.

Here's the code I've got so far:

void Map::moveCamera(int targetx,int targety) {
    //size of the map portion shown on-screen
int CAMERA_WIDTH = 80;
int CAMERA_HEIGHT = 43;

int camera_x = 0;
int camera_y = 0;

    //new camera coordinates (top-left corner of the screen relative to the map)
    int x = targetx - CAMERA_WIDTH / 2;  //coordinates so that the target is at the center of the screen
    int y = targety - CAMERA_HEIGHT / 2;

    //make sure the camera doesn't see outside the map
    if (x < 0){
        x = 0;
    }
    if (y < 0){
        y = 0;
    }

    if (x > map_width - CAMERA_WIDTH - 1) {
        x = map_width - CAMERA_WIDTH - 1;
    }
    if (y > map_height - CAMERA_HEIGHT - 1) {
        y = map_height - CAMERA_HEIGHT - 1;

    if (x != camera_x or y != camera_y) {
        computeFov();
    }
        camera_x = x;
        camera_y = y;
    }
}

Now, when I change the size of the map, the camera is stuck way up in the corner and I can't see the map!

Can anyone point me in the right direction?

dertkw
  • 7,798
  • 5
  • 37
  • 45

0 Answers0