aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-10-22 15:37:00 +0200
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-10-22 15:37:00 +0200
commitf1857fc2d4ddec71b3f0395903f8446cf96b8d0c (patch)
treefeb0a1b4f80cb67ca9af89545ae67a2c03e2f23b /src/crepe/api
parentb151274f9009eb9f86e4df29ca2c75f5b01d4092 (diff)
fixed everything and can now work with new compiler, example rendering and made it work with component manager
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/AudioSource.cpp2
-rw-r--r--src/crepe/api/CMakeLists.txt9
-rw-r--r--src/crepe/api/Sprite.cpp18
-rw-r--r--src/crepe/api/Sprite.h18
-rw-r--r--src/crepe/api/Texture.cpp29
-rw-r--r--src/crepe/api/Texture.h25
-rw-r--r--src/crepe/api/Transform.cpp13
-rw-r--r--src/crepe/api/Transform.h4
8 files changed, 79 insertions, 39 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp
index a5b6d6a..90c1b07 100644
--- a/src/crepe/api/AudioSource.cpp
+++ b/src/crepe/api/AudioSource.cpp
@@ -1,6 +1,6 @@
#include "AudioSource.h"
-#include "facade/Sound.h"
+#include "Sound.h"
#include <memory>
using namespace crepe::api;
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index 9a02580..b046301 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -2,10 +2,19 @@ target_sources(crepe PUBLIC
# AudioSource.cpp
BehaviorScript.cpp
Script.cpp
+ Color.cpp
+ Texture.cpp
+ Sprite.cpp
+ Transform.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
# AudioSource.h
BehaviorScript.h
Script.h
+ Point.h
+ Transform.h
+ Color.h
+ Sprite.h
+ Texture.h
)
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp
new file mode 100644
index 0000000..b0c0971
--- /dev/null
+++ b/src/crepe/api/Sprite.cpp
@@ -0,0 +1,18 @@
+
+
+#include "Sprite.h"
+#include "api/Texture.h"
+#include "util/log.h"
+#include <memory>
+#include <utility>
+
+using namespace std;
+using namespace crepe;
+using namespace crepe::api;
+
+Sprite::Sprite(unique_ptr<Texture> image, const Color & color,
+ const flip_settings & flip) : color(color), flip(flip), sprite_image(std::move(image)) {
+ dbg_trace();
+}
+
+Sprite::~Sprite() { dbg_trace(); }
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 84eeb83..3dd9b4a 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -2,26 +2,28 @@
#include "Component.h"
#include "api/Color.h"
-#include "facade/Texture.h"
+#include "api/Texture.h"
+#include <SDL2/SDL_rect.h>
#include <cstdint>
+#include <memory>
namespace crepe::api {
struct flip_settings{
- bool flipX : 1;
- bool flipY : 1;
+ bool flip_x: 1;
+ bool flip_y : 1;
};
class Sprite : public Component {
public:
- Sprite(crepe::Texture& image, const Color& color, const flip_settings& flip ) : sprite_image(&image), color(color), flip(flip){}
- crepe::Texture* sprite_image;
+ Sprite(std::unique_ptr<Texture> image, const Color& color, const flip_settings& flip );
+ ~Sprite();
+ std::unique_ptr<Texture> sprite_image;
Color color;
flip_settings flip;
- uint8_t sortingLayer;
- uint8_t orderInLayer;
-
+ uint8_t sorting_in_layer;
+ uint8_t order_in_layer;
};
diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp
index b4e3aa8..2d170c3 100644
--- a/src/crepe/api/Texture.cpp
+++ b/src/crepe/api/Texture.cpp
@@ -1,39 +1,34 @@
+#include "Asset.h"
+#include "SdlContext.h"
#include "util/log.h"
#include "Texture.h"
-#include "SdlContext.h"
#include <SDL2/SDL_render.h>
+#include <iostream>
+#include <string>
-using namespace crepe;
+using namespace crepe::api;
-Texture::Texture(std::unique_ptr<api::Resource> res) {
+Texture::Texture(std::unique_ptr<Asset> res) {
dbg_trace();
this->load(std::move(res));
}
Texture::Texture(const char * src) {
dbg_trace();
- this->load(std::make_unique<api::Resource>(src));
+ this->load(std::make_unique<Asset>(src));
}
-Texture::~Texture(){
+Texture::~Texture() {
dbg_trace();
- if(this->m_texture){
+ if (this->m_texture != nullptr) {
SDL_DestroyTexture(m_texture);
}
}
-void Texture::load(std::unique_ptr<api::Resource> res) {
- dbg_trace();
- SdlContext& ctx = SdlContext::get_instance();
- m_texture = ctx.setTextureFromPath(res->canonical(), srcrect, 1, 1);
-}
-
-SDL_Texture* Texture::get_texture() const{
- return m_texture;
-}
+void Texture::load(std::unique_ptr<Asset> res) {
+ SdlContext & ctx = SdlContext::get_instance();
+ m_texture = ctx.texture_from_path(res->canonical());
-SDL_Rect& Texture::get_rect() {
- return srcrect;
}
diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h
index db2f1f9..b376b44 100644
--- a/src/crepe/api/Texture.h
+++ b/src/crepe/api/Texture.h
@@ -1,31 +1,32 @@
#pragma once
-#include "SDL_rect.h"
-#include "api/baseResource.h"
-#include "api/Resource.h"
+#include "Asset.h"
#include <SDL2/SDL_render.h>
#include <memory>
-namespace crepe {
+namespace crepe {
+ class SdlContext;
+}
+namespace crepe::api {
-class Texture : public api::BaseResource{
+class Texture {
public:
Texture(const char * src);
- Texture(std::unique_ptr<api::Resource> res);
+ Texture(std::unique_ptr<Asset> res);
~Texture();
- SDL_Texture* get_texture() const;
- SDL_Rect& get_rect() ;
+
private:
- void load(std::unique_ptr<api::Resource> res);
+ void load(std::unique_ptr<Asset> res);
+
private:
- SDL_Texture* m_texture;
- SDL_Rect srcrect;
+ SDL_Texture * m_texture = nullptr;
+
+ friend class crepe::SdlContext;
};
} // namespace crepe
-
diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp
new file mode 100644
index 0000000..c83461f
--- /dev/null
+++ b/src/crepe/api/Transform.cpp
@@ -0,0 +1,13 @@
+
+
+#include "Transform.h"
+#include "api/Point.h"
+#include "util/log.h"
+
+using namespace crepe::api;
+
+Transform::Transform(Point & point, double rot, double scale)
+ : position(point), rotation(rot), scale(scale) {
+ dbg_trace();
+}
+Transform::~Transform() { dbg_trace(); }
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
index d4dfafc..a34ebb1 100644
--- a/src/crepe/api/Transform.h
+++ b/src/crepe/api/Transform.h
@@ -1,11 +1,13 @@
#pragma once
-#include "api/Component.h"
+#include "Component.h"
#include "api/Point.h"
namespace crepe::api {
class Transform : public Component {
public:
+ Transform(Point&, double, double);
+ ~Transform();
Point position; // Translation (shift)
double rotation; // Rotation, in radians
double scale; // Multiplication factoh