aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-12 22:51:01 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-12 23:19:03 +0200
commit3cb276b19fa21699aa7241956f5b11d1d5b24fe3 (patch)
tree39303246e4fa8ed9f61b439e05824b08ae1cfe50
parent0f9e2d89589f05847fb7dc808da1594f0961b5b4 (diff)
camera: remove dependency against terrain
This will allow using camera for purposes other than showing the game map.
-rw-r--r--src/camera/CMakeLists.txt2
-rw-r--r--src/camera/inc/camera.h5
-rw-r--r--src/camera/src/camera.c9
-rw-r--r--src/camera/src/pad.c6
-rw-r--r--src/game/src/game.c6
-rw-r--r--src/player/src/human_player.c1
6 files changed, 20 insertions, 9 deletions
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 <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,
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 <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) ?
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;