diff options
-rw-r--r-- | src/crepe/api/Animator.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Animator.h | 26 | ||||
-rw-r--r-- | src/crepe/api/Camera.h | 2 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 12 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 2 | ||||
-rw-r--r-- | src/crepe/manager/Mediator.h | 2 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 4 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.cpp | 2 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.h | 3 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 1 |
10 files changed, 33 insertions, 23 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index dc99fd4..8b91859 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,7 +7,7 @@ using namespace crepe; -Animator::Animator(uint32_t id, Sprite & ss, int max_row, int max_col, +Animator::Animator(uint32_t id, Sprite & ss, unsigned int max_row, unsigned int max_col, const Animator::Data & ctx) : Component(id), spritesheet(ss), diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index dab6697..e0399a8 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -2,6 +2,8 @@ #include "Component.h" #include "Sprite.h" +#include "types.h" +#include <sys/types.h> namespace crepe { @@ -20,26 +22,26 @@ public: struct Data { //! frames per second for animation - int fps = 1; + unsigned int fps = 1; //! The current col being animated. - int curr_col = 0; + unsigned int curr_col = 0; //! The current row being animated. - int curr_row = 0; + unsigned int curr_row = 0; //! should the animation loop bool looping = false; //! starting frame for cycling - int cycle_start = 0; + unsigned int cycle_start = 0; //! end frame for cycling (-1 --> use last frame) int cycle_end = -1; //! offset in pixels. // TODO implement - int offset_x = 0; + unsigned int white_space = 0; }; public: @@ -100,12 +102,15 @@ public: * \brief Constructs an Animator object that will control animations for a sprite sheet. * * \param id The unique identifier for the component, typically assigned automatically. - * \param ctx animator data + * \param ss the reference to the spritesheet + * \param max_row maximum of rows inside the given spritesheet + * \param max_col maximum of columns inside the given spritesheet + * \param ctx extra animation data for more control * * This constructor sets up the Animator with the given parameters, and initializes the * animation system. */ - Animator(uint32_t id, Sprite & ss, int max_row, int max_col, const Animator::Data & ctx); + Animator(game_object_id_t id, Sprite & ss, unsigned int max_row, unsigned int max_col, const Animator::Data & ctx); ~Animator(); // dbg_trace public: @@ -113,16 +118,13 @@ public: Sprite & spritesheet; //! The maximum number of columns in the sprite sheet. - const int col; + const unsigned int col; //! The maximum number of rows in the sprite sheet. - const int row; + const unsigned int row; Animator::Data data; -private: - //! AnimatorSystem adjust the private member parameters of Animator; - friend class AnimatorSystem; }; } // namespace crepe // diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index f626379..84ca9e1 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -23,7 +23,7 @@ public: double zoom = 1; //! offset postion from the game object transform component - vec2 offset; + vec2 postion_offset; }; public: diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index a1230db..0ccc296 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -20,11 +20,14 @@ class AnimatorSystem; */ class Sprite : public Component { public: + //! settings to flip the image struct FlipSettings { + //! horizantal flip bool flip_x = false; + //! vertical flip bool flip_y = false; }; - + struct Data { //! Color tint of the sprite Color color = Color::WHITE; @@ -50,10 +53,13 @@ public: vec2 size; //! independent sprite angle. rotating clockwise direction in degrees - double angle_offset = 0; + float angle_offset = 0; //! independent sprite scale multiplier - double scale_offset = 1; + float scale_offset = 1; + + //! independent sprite offset position + vec2 position_offset; }; public: diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 0097070..9533b8a 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -243,7 +243,7 @@ SDL_FRect SDLContext::get_dst_rect(const DstRect & ctx) const { size *= cam.render_scale * ctx.img_scale * data.scale_offset; - vec2 screen_pos = (ctx.pos - cam.cam_pos + (cam.zoomed_viewport) / 2) * cam.render_scale + vec2 screen_pos = (ctx.pos + data.position_offset - cam.cam_pos + (cam.zoomed_viewport) / 2) * cam.render_scale - size / 2 + cam.bar_size; return SDL_FRect{ diff --git a/src/crepe/manager/Mediator.h b/src/crepe/manager/Mediator.h index 71bd1c9..5b53bcc 100644 --- a/src/crepe/manager/Mediator.h +++ b/src/crepe/manager/Mediator.h @@ -5,6 +5,7 @@ // TODO: remove these singletons: #include "EventManager.h" #include "SaveManager.h" +#include "../facade/SDLContext.h" namespace crepe { @@ -28,6 +29,7 @@ struct Mediator { OptionalRef<SceneManager> scene_manager; OptionalRef<SaveManager> save_manager = SaveManager::get_instance(); OptionalRef<EventManager> event_manager = EventManager::get_instance(); + OptionalRef<SDLContext> sdl_context = SDLContext::get_instance(); }; } // namespace crepe diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 20da644..aaa8bdf 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -24,9 +24,9 @@ void InputSystem::update() { RefVector<Transform> transform_vec = mgr.get_components_by_id<Transform>(current_cam.game_object_id); Transform & cam_transform = transform_vec.front().get(); - int camera_origin_x = cam_transform.position.x + current_cam.data.offset.x + int camera_origin_x = cam_transform.position.x + current_cam.data.postion_offset.x - (current_cam.viewport_size.x / 2); - int camera_origin_y = cam_transform.position.y + current_cam.data.offset.y + int camera_origin_y = cam_transform.position.y + current_cam.data.postion_offset.y - (current_cam.viewport_size.y / 2); for (const SDLContext::EventData & event : event_list) { diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 111ad7d..0ba71ec 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -33,7 +33,7 @@ SDLContext::CameraValues RenderSystem::update_camera() { const Transform & transform = mgr.get_components_by_id<Transform>(cam.game_object_id).front().get(); SDLContext::CameraValues cam_val = this->context.set_camera(cam); - cam_val.cam_pos = transform.position + cam.data.offset; + cam_val.cam_pos = transform.position + cam.data.postion_offset; return cam_val; } throw std::runtime_error("No active cameras in current scene"); diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index eaf1213..91b386f 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -79,8 +79,7 @@ private: */ private: - // FIXME: retrieve sdlcontext via mediator after #PR57 - SDLContext & context = SDLContext::get_instance(); + SDLContext & context = this->mediator.sdl_context; }; } // namespace crepe diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 9d6b537..145bc5e 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -57,6 +57,7 @@ public: .order_in_layer = 2, .size = {0, 100}, .angle_offset = 0, + .position_offset = {100,0}, }); auto & anim = game_object.add_component<Animator>(test_sprite, 4, 4, |