camera: remove dependency against terrain
This will allow using camera for purposes other than showing the game map.
This commit is contained in:
parent
0f9e2d8958
commit
3cb276b19f
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <gfx.h>
|
||||
#include <mouse.h>
|
||||
#include <pad.h>
|
||||
#include <terrain.h>
|
||||
#include <util.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -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,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <camera.h>
|
||||
#include <camera_private.h>
|
||||
#include <pad.h>
|
||||
#include <terrain.h>
|
||||
#include <peripheral.h>
|
||||
#include <gfx.h>
|
||||
#include <util.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -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) ?
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue