0

这与其说是一个问题,不如说是一个“反隧道视觉”检查。

我正在尝试让相机/视口以 roguelike 方式工作,但我不确定我是否正确地做事。

这是我到目前为止的代码:

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;
    }
}

现在,当我改变地图的大小时,相机卡在角落里,我看不到地图!

谁能指出我正确的方向?

4

0 回答 0