aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Animator.cpp3
-rw-r--r--src/crepe/api/Camera.h21
-rw-r--r--src/crepe/api/Color.cpp2
-rw-r--r--src/crepe/api/Config.h2
-rw-r--r--src/crepe/api/Sprite.cpp3
-rw-r--r--src/crepe/api/Sprite.h16
-rw-r--r--src/crepe/api/Vector2.h13
7 files changed, 44 insertions, 16 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 464b0fd..0043896 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -20,5 +20,8 @@ Animator::Animator(game_object_id_t id, Sprite & ss, int row, int col, int col_a
animator_rect.x = 0;
animator_rect.y = col_animator * animator_rect.h;
this->active = false;
+
+ // need to do this for to get the aspect ratio for a single clipping in the spritesheet
+ this->spritesheet.aspect_ratio = (double) animator_rect.w / (double) animator_rect.h;
}
Animator::~Animator() { dbg_trace(); }
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h
index e0cda34..137c8ed 100644
--- a/src/crepe/api/Camera.h
+++ b/src/crepe/api/Camera.h
@@ -2,6 +2,7 @@
#include "Color.h"
#include "Component.h"
+#include "api/Vector2.h"
namespace crepe {
@@ -27,20 +28,20 @@ public:
//! Background color of the camera view.
Color bg_color;
- //! Aspect ratio height for the camera.
- double aspect_height = 480;
+ //! pos The position of the camera in world units
+ Vector2 pos = {0, 0};
- //! Aspect ratio width for the camera.
- double aspect_width = 640;
+ //! screen the display size in pixels ( output resolution )
+ //Vector2 screen = {720, 480};
+ Vector2 screen = {1080, 720};
- //! X-coordinate of the camera position.
- double x = 0.0;
-
- //! Y-coordinate of the camera position.
- double y = 0.0;
+ //! viewport is the area of the world visible through the camera (in world units)
+ //Vector2 viewport = {720, 480};
+ Vector2 viewport = {2000, 1000};
+ //! scale scaling factor from world units to pixel coordinates
//! Zoom level of the camera view.
- double zoom = 1.0;
+ double zoom = 1.0f;
public:
/**
diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp
index 29bd77a..dc7c15f 100644
--- a/src/crepe/api/Color.cpp
+++ b/src/crepe/api/Color.cpp
@@ -2,7 +2,7 @@
using namespace crepe;
-const Color Color::WHITE{0xff, 0xff, 0xff};
+const Color Color::WHITE{0xff, 0xff, 0xff, 0xff};
const Color Color::RED{0xff, 0x00, 0x00};
const Color Color::GREEN{0x00, 0xff, 0x00};
const Color Color::BLUE{0x00, 0x00, 0xff};
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 0c9d116..671fd02 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -32,7 +32,7 @@ public:
*
* Only messages with equal or higher priority than this value will be logged.
*/
- Log::Level level = Log::Level::INFO;
+ Log::Level level = Log::Level::DEBUG;
/**
* \brief Colored log output
*
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp
index bd2d5cf..c219dd0 100644
--- a/src/crepe/api/Sprite.cpp
+++ b/src/crepe/api/Sprite.cpp
@@ -15,7 +15,8 @@ Sprite::Sprite(game_object_id_t id, const shared_ptr<Texture> image, const Color
: Component(id),
color(color),
flip(flip),
- sprite_image(image) {
+ sprite_image(image),
+ aspect_ratio(sprite_image->get_width() / sprite_image->get_height()) {
dbg_trace();
this->sprite_rect.w = sprite_image->get_width();
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 74a55d4..89f9121 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -1,6 +1,7 @@
#pragma once
#include <memory>
+#include <sys/types.h>
#include "../Component.h"
@@ -62,6 +63,19 @@ public:
//! Order within the sorting layer
uint8_t order_in_layer = 0;
+ //! width in world units
+ int width = 0;
+ //! height in world units
+ int height = 0;
+
+ /**
+ * \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
+ */
+ double aspect_ratio;
+
public:
/**
* \brief Gets the maximum number of instances allowed for this sprite.
@@ -82,7 +96,7 @@ private:
friend class AnimatorSystem;
//! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator
- // object is present in GameObject
+ // object is present in GameObject. this is in sprite pixels
Rect sprite_rect;
};
diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h
index c278c87..019d849 100644
--- a/src/crepe/api/Vector2.h
+++ b/src/crepe/api/Vector2.h
@@ -31,8 +31,17 @@ struct Vector2 {
//! Divides this vector by another vector element-wise and returns the result.
Vector2 operator/(const Vector2<T> & other) const;
- //! Divides this vector by a scalar and returns the result.
- Vector2 operator/(T scalar) const;
+ //! Multiplies this vector by another vector element-wise and updates this vector.
+ Vector2 & operator*=(const Vector2<T> & other);
+
+ //! Multiplies a scalar value to both components of this vector and updates this vector.
+ Vector2 & operator*=(const Vector2<T> & other);
+
+ //! Divides this vector by another vector element-wise and updates this vector.
+ Vector2 operator/(const Vector2<T> & other) const;
+
+ //! Divides a scalar value to both components of this vector and updates this vector.
+ Vector2 operator/(const T & other) const;
//! Adds another vector to this vector and updates this vector.
Vector2 & operator+=(const Vector2<T> & other);