Skip to content

Commit

Permalink
got rid of the black space surrounding the level map
Browse files Browse the repository at this point in the history
  • Loading branch information
NotImplementedLife committed Apr 8, 2022
1 parent f5fb3b7 commit d58c2d5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/engine/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Camera
private:
sf24 x, y;
Sprite* target;
s16 bndw=32767, bndh=32767;
public:
Camera();
Camera(sf24 x, sf24 y);
Expand All @@ -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);
Expand Down
30 changes: 28 additions & 2 deletions source/engine/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions source/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d58c2d5

Please sign in to comment.