From d58c2d590d3772525f1152660049d1097dc4ae5a Mon Sep 17 00:00:00 2001 From: NotImplementedLife Date: Fri, 8 Apr 2022 18:15:10 +0300 Subject: [PATCH] got rid of the black space surrounding the level map --- include/engine/camera.hpp | 3 +++ source/engine/camera.cpp | 30 ++++++++++++++++++++++++++++-- source/level.cpp | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/engine/camera.hpp b/include/engine/camera.hpp index 4caf1ae..81358b2 100644 --- a/include/engine/camera.hpp +++ b/include/engine/camera.hpp @@ -11,6 +11,7 @@ class Camera private: sf24 x, y; Sprite* target; + s16 bndw=32767, bndh=32767; public: Camera(); Camera(sf24 x, sf24 y); @@ -20,6 +21,8 @@ class Camera void set_x(const sf24& value); void set_y(const sf24& value); + void set_bounds(s16 w, s16 h); + void move(sf24 x, sf24 y); void follow(Sprite* spr); diff --git a/source/engine/camera.cpp b/source/engine/camera.cpp index 39b4021..91de708 100644 --- a/source/engine/camera.cpp +++ b/source/engine/camera.cpp @@ -15,9 +15,29 @@ Camera::Camera(sf24 x, sf24 y) this->y = y; }; -s16 Camera::get_x() const { return target ? (s16)(target->pos_x) : (s16)x; } +s16 Camera::get_x() const +{ + if(!target) return (s16)x; + + s16 _x = (s16)(target->pos_x); + + if(_x<120) return 120; + if(_x>bndw) return bndw; + + return _x; +} -s16 Camera::get_y() const { return target ? (s16)(target->pos_y) : (s16)y; } +s16 Camera::get_y() const +{ + if(!target) return (s16)y; + + s16 _y = (s16)(target->pos_y); + + if(_y<80) return 80; + if(_y>bndh) return bndh; + + return _y; +} void Camera::set_x(const sf24& value) { x = value; target=NULL; } @@ -30,6 +50,12 @@ void Camera::move(sf24 x, sf24 y) target=NULL; } +void Camera::set_bounds(s16 w, s16 h) +{ + bndw = w-120-1; + bndh = h-80-1; +} + #include "error.hpp" void Camera::follow(Sprite* spr) diff --git a/source/level.cpp b/source/level.cpp index 8d6c493..338b76f 100644 --- a/source/level.cpp +++ b/source/level.cpp @@ -513,6 +513,8 @@ void Level::init() LOAD_GRIT_SPRITE_TILES(star, 0x1C0, 0xA5, TMP_SPRITE_PALETTE); LOAD_GRIT_SPRITE_TILES(goddess_icon, 0x1C8, 0xAA, TMP_SPRITE_PALETTE); + camera->set_bounds(600,840); + LevelBackgroundBage* bg_page = new LevelBackgroundBage(); set_background(3, bg_page, 0x10);