diff --git a/src/camera/CMakeLists.txt b/src/camera/CMakeLists.txt index 1cb1f63..2ef522a 100644 --- a/src/camera/CMakeLists.txt +++ b/src/camera/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(camera "src/camera.c" "src/pad.c" "src/mouse.c" "src/touch.c") target_include_directories(camera PUBLIC "inc" PRIVATE "privinc") -target_link_libraries(camera PUBLIC container mouse pad peripheral terrain util PRIVATE gfx) +target_link_libraries(camera PUBLIC container mouse pad peripheral util PRIVATE gfx) diff --git a/src/camera/inc/camera.h b/src/camera/inc/camera.h index 8356bd8..98cb240 100644 --- a/src/camera/inc/camera.h +++ b/src/camera/inc/camera.h @@ -14,6 +14,11 @@ extern "C" struct camera { + struct camera_dim + { + long w, h; + } dim; + int x, y, x_speed, y_speed; unsigned int xt, yt; bool pan; diff --git a/src/camera/src/camera.c b/src/camera/src/camera.c index 73f8bf4..e8f9cd5 100644 --- a/src/camera/src/camera.c +++ b/src/camera/src/camera.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -78,8 +77,8 @@ void camera_update_pos(struct camera *const cam) if (cam->x > 0) cam->x = 0; - else if (cam->x < -MAP_W) - cam->x = -MAP_W; + else if (cam->x < -cam->dim.w) + cam->x = -cam->dim.w; const int y = cam->y + cam->y_speed; @@ -87,8 +86,8 @@ void camera_update_pos(struct camera *const cam) if (cam->y > 0) cam->y = 0; - else if (cam->y < -MAP_H) - cam->y = -MAP_H; + else if (cam->y < -cam->dim.h) + cam->y = -cam->dim.h; } bool camera_translate(const struct camera *const cam, const struct util_rect *const dim, diff --git a/src/camera/src/pad.c b/src/camera/src/pad.c index d61ef8b..f123980 100644 --- a/src/camera/src/pad.c +++ b/src/camera/src/pad.c @@ -1,8 +1,8 @@ #include #include #include -#include #include +#include #include #include @@ -21,7 +21,7 @@ static void cursor_update(struct camera *const cam, const struct pad *const p) c->x -= STEP; else if (pad_pressed(p, PAD_KEY_RIGHT) && (c->x + STEP < screen_w) - && (c->x != c->x_init || cam->x <= -MAP_W)) + && (c->x != c->x_init || cam->x <= -cam->dim.w)) c->x += STEP; if (pad_pressed(p, PAD_KEY_UP) @@ -30,7 +30,7 @@ static void cursor_update(struct camera *const cam, const struct pad *const p) c->y -= STEP; else if (pad_pressed(p, PAD_KEY_DOWN) && (c->y + STEP < screen_h) - && (c->y != c->y_init || cam->y <= -MAP_H)) + && (c->y != c->y_init || cam->y <= -cam->dim.h)) c->y += STEP; c->state = pad_pressed(p, PAD_KEY_A) || pad_pressed(p, PAD_KEY_B) ? diff --git a/src/game/src/game.c b/src/game/src/game.c index 3c03dd5..dc3d55b 100644 --- a/src/game/src/game.c +++ b/src/game/src/game.c @@ -28,6 +28,12 @@ int game(void) { .sel_periph = PERIPHERAL_TYPE_KEYBOARD_MOUSE, .padn = i, + .dim = + { + .w = MAP_W, + .h = MAP_H, + }, + .pl = { .team = PLAYER_COLOR_BLUE, diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c index 14e4680..956b692 100644 --- a/src/player/src/human_player.c +++ b/src/player/src/human_player.c @@ -751,6 +751,7 @@ int human_player_init(const struct human_player_cfg *const cfg, peripheral_init(&p_cfg, &h->periph); cursor_init(&h->cam.cursor); + h->cam.dim = cfg->dim; h->top_gui = true; memmove(h->gui_res, h->pl.resources, sizeof h->gui_res); return 0;