aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/CMakeLists.txt5
-rw-r--r--src/crepe/api/Color.cpp53
-rw-r--r--src/crepe/api/Color.h34
-rw-r--r--src/crepe/api/Point.h14
-rw-r--r--src/crepe/api/Sprite.h28
-rw-r--r--src/crepe/api/Transform.h13
-rw-r--r--src/crepe/api/game.cpp26
-rw-r--r--src/crepe/api/game.h16
-rw-r--r--src/crepe/api/spritesheet.cpp6
-rw-r--r--src/crepe/api/spritesheet.h4
10 files changed, 175 insertions, 24 deletions
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index 96b55cf..dcac0ae 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -4,6 +4,7 @@ target_sources(crepe PUBLIC
resource_manager.cpp
Resource.cpp
game.cpp
+ Color.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
@@ -15,4 +16,8 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
resource_manager.h
Component.h
AudioSource.h
+ Sprite.h
+ Color.h
+ Transform.h
+ Point.h
)
diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp
new file mode 100644
index 0000000..c73ce6c
--- /dev/null
+++ b/src/crepe/api/Color.cpp
@@ -0,0 +1,53 @@
+
+
+#include "Color.h"
+
+
+using namespace crepe::api;
+
+Color Color::white = Color(255,255,255,0);
+Color Color::red = Color(255,0,0,0);
+Color Color::green = Color(0,255,0,0);
+Color Color::blue = Color(0,0,255,0);
+Color Color::black = Color(0,0,0,0);
+Color Color::cyan = Color(0,255,255,0);
+Color Color::yellow = Color(255,255,0,0);
+Color Color::magenta= Color(255,0,255,0);
+
+Color::Color(double red, double green, double blue, double alpha){
+ this->a = alpha;
+ this->r = red;
+ this->g = green;
+ this->b = blue;
+};
+
+const Color& Color::get_white(){
+ return Color::white;
+};
+
+const Color& Color::get_red(){
+ return Color::red;
+};
+const Color& Color::get_green(){
+ return Color::green;
+};
+const Color& Color::get_blue(){
+ return Color::blue;
+};
+
+const Color& Color::get_black(){
+ return Color::black;
+};
+
+const Color& Color::get_cyan(){
+ return Color::cyan;
+};
+
+const Color& Color::get_yellow(){
+ return Color::yellow;
+};
+
+const Color& Color::get_magenta(){
+ return Color::magenta;
+};
+
diff --git a/src/crepe/api/Color.h b/src/crepe/api/Color.h
new file mode 100644
index 0000000..207434e
--- /dev/null
+++ b/src/crepe/api/Color.h
@@ -0,0 +1,34 @@
+#pragma once
+
+namespace crepe::api {
+
+class Color {
+
+public:
+ Color(double red, double green, double blue, double alpha);
+ static const Color & get_white();
+ static const Color & get_red();
+ static const Color & get_green();
+ static const Color & get_blue();
+ static const Color & get_cyan();
+ static const Color & get_magenta();
+ static const Color & get_yellow();
+ static const Color & get_black();
+
+private:
+ double r;
+ double g;
+ double b;
+ double a;
+
+ static Color white;
+ static Color red;
+ static Color green;
+ static Color blue;
+ static Color cyan;
+ static Color magenta;
+ static Color yellow;
+ static Color black;
+};
+
+} // namespace crepe::api
diff --git a/src/crepe/api/Point.h b/src/crepe/api/Point.h
new file mode 100644
index 0000000..463aa7c
--- /dev/null
+++ b/src/crepe/api/Point.h
@@ -0,0 +1,14 @@
+#pragma once
+
+
+
+namespace crepe::api {
+
+class Point {
+public:
+ double x;
+ double y;
+};
+
+
+}
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
new file mode 100644
index 0000000..84eeb83
--- /dev/null
+++ b/src/crepe/api/Sprite.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "Component.h"
+#include "api/Color.h"
+#include "facade/Texture.h"
+#include <cstdint>
+
+
+namespace crepe::api {
+
+struct flip_settings{
+ bool flipX : 1;
+ bool flipY : 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;
+ Color color;
+ flip_settings flip;
+ uint8_t sortingLayer;
+ uint8_t orderInLayer;
+
+
+};
+
+}
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
new file mode 100644
index 0000000..d4dfafc
--- /dev/null
+++ b/src/crepe/api/Transform.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "api/Component.h"
+#include "api/Point.h"
+namespace crepe::api {
+
+class Transform : public Component {
+public:
+ Point position; // Translation (shift)
+ double rotation; // Rotation, in radians
+ double scale; // Multiplication factoh
+};
+} // namespace crepe::api
diff --git a/src/crepe/api/game.cpp b/src/crepe/api/game.cpp
index 02a0132..01920a9 100644
--- a/src/crepe/api/game.cpp
+++ b/src/crepe/api/game.cpp
@@ -2,17 +2,29 @@
#include "game.h"
-#include "api/spritesheet.h"
+#include "core/renderSystem.h"
#include "facade/SdlContext.h"
-#include "facade/Texture.h"
-#include <vector>
-void game::render(std::vector<crepe::Texture*> & draw, std::vector<crepe::api::Spritesheet*> & ss){
- auto& ctx = crepe::SdlContext::get_instance();
-
- ctx.loop(*draw[0], *ss[0]);
+Engine::Engine(int windowHeight, int window_with){
+ crepe::SdlContext& ctx = crepe::SdlContext::get_instance();
}
+void Engine::loop() {
+
+ bool running = true;
+ crepe::SdlContext& ctx = crepe::SdlContext::get_instance();
+ RenderSystem rendering;
+
+ while (running) {
+ ctx.handleEvents(running);
+
+ ctx.clearScreen();
+
+ rendering.render();
+
+ ctx.presentScreen();
+ }
+}
diff --git a/src/crepe/api/game.h b/src/crepe/api/game.h
index 7cde954..64027fa 100644
--- a/src/crepe/api/game.h
+++ b/src/crepe/api/game.h
@@ -1,15 +1,17 @@
#pragma once
-#include "api/spritesheet.h"
-#include "facade/Texture.h"
-#include <vector>
-class game {
+class Engine{
public:
- game(){}
- ~game(){}
+ Engine(int windowWith, int windowHeight);
+ ~Engine() = default;
- void render(std::vector<crepe::Texture*>&, std::vector<crepe::api::Spritesheet*>&);
+ void loop();
+
+
+private:
+ int window_height;
+ int window_width;
};
diff --git a/src/crepe/api/spritesheet.cpp b/src/crepe/api/spritesheet.cpp
index 93a2b65..7f5da38 100644
--- a/src/crepe/api/spritesheet.cpp
+++ b/src/crepe/api/spritesheet.cpp
@@ -30,12 +30,6 @@ void Spritesheet::select_sprite(const int x, const int y){
m_clip.y = y * m_clip.h;
}
-void Spritesheet::draw_selected_sprite(const int x, const int y){
- auto& ctx = SdlContext::get_instance();
- SDL_Rect tmp = { x, y, m_clip.w, m_clip.h};
- SDL_RenderCopy(ctx.m_game_renderer, this->m_spritesheet, &this->m_clip, &tmp);
-}
-
void Spritesheet::load(std::unique_ptr<api::Resource> res, const int row, const int col){
auto& ctx = SdlContext::get_instance();
diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h
index 7f46296..503dcef 100644
--- a/src/crepe/api/spritesheet.h
+++ b/src/crepe/api/spritesheet.h
@@ -24,14 +24,10 @@ private:
void load(std::unique_ptr<api::Resource> res, const int row, const int col);;
SDL_Texture* get_texture() const;
-
-
private:
SDL_Texture* m_spritesheet;
SDL_Rect m_clip;
-
- friend class SdlContext;
};
}