diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/crepe/api/Color.cpp | 53 | ||||
-rw-r--r-- | src/crepe/api/Color.h | 34 | ||||
-rw-r--r-- | src/crepe/api/Point.h | 14 | ||||
-rw-r--r-- | src/crepe/api/Sprite.h | 28 | ||||
-rw-r--r-- | src/crepe/api/Transform.h | 13 | ||||
-rw-r--r-- | src/crepe/api/baseResource.h | 11 | ||||
-rw-r--r-- | src/crepe/api/game.cpp | 30 | ||||
-rw-r--r-- | src/crepe/api/game.h | 17 | ||||
-rw-r--r-- | src/crepe/api/map_asset.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/map_asset.h | 14 | ||||
-rw-r--r-- | src/crepe/api/resource_manager.cpp | 25 | ||||
-rw-r--r-- | src/crepe/api/resource_manager.h | 57 | ||||
-rw-r--r-- | src/crepe/api/spritesheet.cpp | 38 | ||||
-rw-r--r-- | src/crepe/api/spritesheet.h | 34 |
16 files changed, 381 insertions, 2 deletions
diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index b512d27..a5b6d6a 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -1,6 +1,6 @@ #include "AudioSource.h" -#include "../Sound.h" +#include "facade/Sound.h" #include <memory> using namespace crepe::api; diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 86623de..cecc2f1 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -7,4 +7,3 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.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/baseResource.h b/src/crepe/api/baseResource.h new file mode 100644 index 0000000..2513f4d --- /dev/null +++ b/src/crepe/api/baseResource.h @@ -0,0 +1,11 @@ +#pragma once + +namespace crepe::api { + +class BaseResource { +public: + virtual ~BaseResource() = default; +}; + +} + diff --git a/src/crepe/api/game.cpp b/src/crepe/api/game.cpp new file mode 100644 index 0000000..01920a9 --- /dev/null +++ b/src/crepe/api/game.cpp @@ -0,0 +1,30 @@ + + + +#include "game.h" +#include "core/renderSystem.h" +#include "facade/SdlContext.h" + + +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 new file mode 100644 index 0000000..64027fa --- /dev/null +++ b/src/crepe/api/game.h @@ -0,0 +1,17 @@ +#pragma once + + + +class Engine{ + +public: + Engine(int windowWith, int windowHeight); + ~Engine() = default; + + void loop(); + + +private: + int window_height; + int window_width; +}; diff --git a/src/crepe/api/map_asset.cpp b/src/crepe/api/map_asset.cpp new file mode 100644 index 0000000..bbabe2b --- /dev/null +++ b/src/crepe/api/map_asset.cpp @@ -0,0 +1,12 @@ + + + + +#include "map_asset.h" + +Map::Map(const std::string& content){ + this->m_content = content; +} + +Map::~Map(){ +} diff --git a/src/crepe/api/map_asset.h b/src/crepe/api/map_asset.h new file mode 100644 index 0000000..a4f3df7 --- /dev/null +++ b/src/crepe/api/map_asset.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Resource.h" +#include <string> + + +using namespace crepe::api; + +class Map : public Resource { + +public: + Map(const std::string& ); + ~Map(); +}; diff --git a/src/crepe/api/resource_manager.cpp b/src/crepe/api/resource_manager.cpp new file mode 100644 index 0000000..0ecdae5 --- /dev/null +++ b/src/crepe/api/resource_manager.cpp @@ -0,0 +1,25 @@ + + +#include "resource_manager.h" +#include <string> +#include <unordered_map> + +using namespace crepe::api; + +ResourceManager& ResourceManager::get_instance(){ + static ResourceManager instance; + return instance; +} + + +ResourceManager::~ResourceManager(){ + m_resources.clear(); +} + + +void ResourceManager::Unload(const std::string& file_path){ + if(m_resources.find(file_path) != m_resources.end()){ + m_resources.erase(file_path); + } +} + diff --git a/src/crepe/api/resource_manager.h b/src/crepe/api/resource_manager.h new file mode 100644 index 0000000..a646d95 --- /dev/null +++ b/src/crepe/api/resource_manager.h @@ -0,0 +1,57 @@ +#pragma once + + + +#include <memory> +#include <string> +#include <unordered_map> +#include <utility> + +#include "api/baseResource.h" + + +namespace crepe::api{ + +class ResourceManager{ + + +private: + + std::unordered_map< std::string, std::unique_ptr<BaseResource>> m_resources; + + +protected: + ResourceManager() = default; + ~ResourceManager(); + +public: + ResourceManager(const ResourceManager &) = delete; + ResourceManager(ResourceManager &&) = delete; + ResourceManager &operator=(const ResourceManager &) = delete; + ResourceManager &operator=(ResourceManager &&) = delete; + + static ResourceManager& get_instance(); + + + +public: + template<typename T> + T* Load(const std::string& file_path){ + + if (m_resources.find(file_path) != m_resources.end()) { + return static_cast<T*>(m_resources[file_path].get()); + } + + auto resource = std::make_unique<T>(file_path.c_str()); + if (resource) { + m_resources[file_path] = std::move(resource); + return static_cast<T*>(m_resources[file_path].get() ); + } + + return nullptr; + } + + void Unload(const std::string& file_path); + +}; +} diff --git a/src/crepe/api/spritesheet.cpp b/src/crepe/api/spritesheet.cpp new file mode 100644 index 0000000..7f5da38 --- /dev/null +++ b/src/crepe/api/spritesheet.cpp @@ -0,0 +1,38 @@ + + +#include "spritesheet.h" +#include "SDL_rect.h" +#include "SDL_render.h" +#include "api/Resource.h" +#include "facade/SdlContext.h" +#include <memory> + + +using namespace crepe::api; + +Spritesheet::Spritesheet(const char* src, const int row, const int col){ + this->load(std::make_unique<api::Resource>(src), row, col); +} + +Spritesheet::Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col){ + this->load(std::move(res), row, col); +} + +Spritesheet::~Spritesheet(){ + + if (this->m_spritesheet) { + SDL_DestroyTexture(this->m_spritesheet); + } +} + +void Spritesheet::select_sprite(const int x, const int y){ + m_clip.x = x * m_clip.w; + m_clip.y = y * m_clip.h; +} + +void Spritesheet::load(std::unique_ptr<api::Resource> res, const int row, const int col){ + auto& ctx = SdlContext::get_instance(); + + this->m_spritesheet = ctx.setTextureFromPath(res->canonical(), this->m_clip, row, col); +} + diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h new file mode 100644 index 0000000..503dcef --- /dev/null +++ b/src/crepe/api/spritesheet.h @@ -0,0 +1,34 @@ +#pragma once + + + + +#include "Resource.h" +#include "SDL_rect.h" +#include "SDL_render.h" +#include <memory> + + +namespace crepe::api { + +class Spritesheet{ + +public: + Spritesheet(const char * src, const int row , const int col); + Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col); + ~Spritesheet(); + + void select_sprite(const int x, const int y); + void draw_selected_sprite(const int x, const int y); +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; +}; + +} + |