diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-04 10:56:53 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-04 10:56:53 +0100 |
commit | a11824956b478e356fa684c9d88b980aa22cb19a (patch) | |
tree | d743b0415040d68db4f5cf35b2fc58bab41f0e46 /src/crepe/api | |
parent | 683ae28b81a66f18bbadbe7ae70eb8ddd952c293 (diff) |
implemented feedback, cameraValues need better name?
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Animator.cpp | 29 | ||||
-rw-r--r-- | src/crepe/api/Animator.h | 22 | ||||
-rw-r--r-- | src/crepe/api/Camera.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/Camera.h | 19 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 25 |
6 files changed, 58 insertions, 46 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 1234967..dc99fd4 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,20 +7,23 @@ using namespace crepe; -Animator::Animator(game_object_id_t id, const Animator::Data & ctx) +Animator::Animator(uint32_t id, Sprite & ss, int max_row, int max_col, + const Animator::Data & ctx) : Component(id), + spritesheet(ss), + row(max_row), + col(max_col), data(ctx) { dbg_trace(); - this->data.spritesheet.mask.h /= this->data.col; - this->data.spritesheet.mask.w /= this->data.row; - this->data.spritesheet.mask.x = 0; - this->data.spritesheet.mask.y = this->data.col * this->data.spritesheet.mask.h; + this->spritesheet.mask.h /= this->col; + this->spritesheet.mask.w /= this->row; + this->spritesheet.mask.x = this->data.curr_row * this->spritesheet.mask.w; + this->spritesheet.mask.y = this->data.curr_col * this->spritesheet.mask.h; // need to do this for to get the aspect ratio for a single clipping in the spritesheet - Sprite & ss = this->data.spritesheet; - ss.data.aspect_ratio - = static_cast<double>(this->data.spritesheet.mask.w) / this->data.spritesheet.mask.h; + this->spritesheet.aspect_ratio + = static_cast<double>(this->spritesheet.mask.w) / this->spritesheet.mask.h; } Animator::~Animator() { dbg_trace(); } @@ -43,12 +46,14 @@ void Animator::set_cycle_range(int start, int end) { } void Animator::set_anim(int col) { - this->data.curr_row = 0; - this->data.curr_col = col; + Animator::Data & ctx = this->data; + this->spritesheet.mask.x = ctx.curr_row = 0; + ctx.curr_col = col; + this->spritesheet.mask.y = ctx.curr_col * this->spritesheet.mask.h; } void Animator::next_anim() { Animator::Data & ctx = this->data; - ctx.curr_row = ctx.curr_row++ % ctx.row; - ctx.spritesheet.mask.x = ctx.curr_row * ctx.spritesheet.mask.w; + ctx.curr_row = ctx.curr_row++ % this->row; + this->spritesheet.mask.x = ctx.curr_row * this->spritesheet.mask.w; } diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 74abd5e..1fe2b6f 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -18,20 +18,13 @@ class SDLContext; class Animator : public Component { public: struct Data { - //! A reference to the Sprite sheet containing. - Sprite & spritesheet; - //! The maximum number of columns in the sprite sheet. - const int col; - - //! The maximum number of rows in the sprite sheet. - const int row; //! frames per second for animation - int fps; + int fps = 1; //! The current col being animated. - int curr_col; + int curr_col = 0; //! The current row being animated. int curr_row = 0; @@ -113,10 +106,19 @@ public: * This constructor sets up the Animator with the given parameters, and initializes the * animation system. */ - Animator(uint32_t id, const Animator::Data & ctx); + Animator(uint32_t id, Sprite & ss, int max_row, int max_col, const Animator::Data & ctx); ~Animator(); // dbg_trace public: + //! A reference to the Sprite sheet containing. + Sprite & spritesheet; + + //! The maximum number of columns in the sprite sheet. + const int col; + + //! The maximum number of rows in the sprite sheet. + const int row; + Animator::Data data; private: diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index ff41710..b042c35 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -6,7 +6,12 @@ using namespace crepe; -Camera::Camera(game_object_id_t id, const Data & ctx) : Component(id), data(ctx) { +Camera::Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, + const Data & ctx) + : Component(id), + screen(screen), + viewport_size(viewport_size), + data(ctx) { dbg_trace(); } diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index e466d36..f626379 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -17,16 +17,10 @@ class Camera : public Component { public: struct Data { //! Background color of the camera view. - const Color bg_color; - - //! screen the display size in pixels ( output resolution ) - const ivec2 screen; - - //! viewport is the area of the world visible through the camera (in world units) - const vec2 viewport_size; + const Color bg_color = Color::WHITE; //! Zoom level of the camera view. - double zoom; + double zoom = 1; //! offset postion from the game object transform component vec2 offset; @@ -38,12 +32,19 @@ public: * \param id Unique identifier for the camera component. * \param ctx the camera component data */ - Camera(game_object_id_t id, const Data & ctx); + Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, + const Data & ctx); ~Camera(); // dbg_trace only public: Camera::Data data; + //! screen the display size in pixels ( output resolution ) + const ivec2 screen; + + //! viewport is the area of the world visible through the camera (in world units) + const vec2 viewport_size; + public: /** * \brief Gets the maximum number of camera instances allowed. diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index fe495a1..3a1acac 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -20,7 +20,7 @@ Sprite::Sprite(game_object_id_t id, Texture & texture, const Sprite::Data & ctx) this->mask.w = this->texture.get_width(); this->mask.h = this->texture.get_height(); - this->data.aspect_ratio = static_cast<double>(this->mask.w) / this->mask.h; + this->aspect_ratio = static_cast<double>(this->mask.w) / this->mask.h; } Sprite::~Sprite() { dbg_trace(); } diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index aef6a8d..d82ae8d 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -27,16 +27,16 @@ public: struct Data { //! Color tint of the sprite - Color color; + Color color = Color::WHITE; //! Flip settings for the sprite FlipSettings flip; //! Layer sorting level of the sprite - const int sorting_in_layer; + const int sorting_in_layer = 0; //! Order within the sorting layer - const int order_in_layer; + const int order_in_layer = 0; /** * \size width and height of the sprite in game units @@ -53,15 +53,8 @@ public: double angle_offset = 0; //! independent sprite scale multiplier - double scale = 1; + double scale_offset = 1; - /** - * \aspect_ratio ratio of the img so that scaling will not become weird - * - * cannot be const because if Animator component is addded then ratio becomes scuffed and - * does it need to be calculated again in the Animator - */ - float aspect_ratio; }; public: @@ -71,8 +64,6 @@ public: * \param texture asset of the image * \param ctx all the sprite data */ - //TODO: texture is outside the Sprite::Data because of the deleted copy constructer. eventually - // texture will go into data when it becomes asset Sprite(game_object_id_t id, Texture & texture, const Data & ctx); ~Sprite(); @@ -82,6 +73,14 @@ public: Data data; private: + /** + * \aspect_ratio ratio of the img so that scaling will not become weird + * + * cannot be const because if Animator component is addded then ratio becomes scuffed and + * does it need to be calculated again in the Animator + */ + float aspect_ratio; + //! Reads the mask of sprite friend class SDLContext; |