From 39abfaa97860e575f3afb8c1c5acd355d3a1f766 Mon Sep 17 00:00:00 2001 From: n0ffie Date: Fri, 7 Feb 2025 01:10:15 +0100 Subject: [PATCH] formating; alyson licence; Camera2D --- README.md | 6 ++--- alyson/LICENSE | 21 ++++++++++++++++ alyson/includes/alyson.hpp | 4 ++- alyson/src/alyson.cpp | 44 ++++++++++++++++++++------------- alyson/src/rlyson.c | 50 +++++++++++++++++++------------------- src/main.cpp | 9 ++++--- 6 files changed, 85 insertions(+), 49 deletions(-) create mode 100644 alyson/LICENSE diff --git a/README.md b/README.md index 65a3ece..1c87905 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Colysis -A little Videogame with a custom engine written in C/C++. -It uses [Flecs](https://github.com/SanderMertens/flecs) as a ECS framework and [Raylib](https://www.raylib.com/) as a 2D graphics library. +A little video game with a custom engine written in C/C++. +It uses [Flecs](https://github.com/SanderMertens/flecs) as an ECS framework and [Raylib](https://www.raylib.com/) as a 2D graphics library. ## Building To build the project, you need to have [CMake](https://cmake.org/) installed. @@ -33,4 +33,4 @@ cmake --build . --config Release After building, you can run the game by executing the `colysis` executable. ## License -This `colysis` is currently closed source and will not be open sourced. The engine will be licensed under the [MIT license](LICENSE) as soon as it is finished. +The game "colysis" will not be open source, but the engine will be licensed under the [MIT license](alyson/LICENSE) as soon as it is finished. diff --git a/alyson/LICENSE b/alyson/LICENSE new file mode 100644 index 0000000..2ac80e8 --- /dev/null +++ b/alyson/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2025 n0ffie (noffie.github@icloud.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/alyson/includes/alyson.hpp b/alyson/includes/alyson.hpp index b799d8e..357e244 100644 --- a/alyson/includes/alyson.hpp +++ b/alyson/includes/alyson.hpp @@ -8,7 +8,9 @@ #define MANGLE_RES_PATH(path) ASSETS_PATH "/" path -int init(); +#include + +size_t init(size_t task); void update(float dt); diff --git a/alyson/src/alyson.cpp b/alyson/src/alyson.cpp index 2e96760..d8cb8ba 100644 --- a/alyson/src/alyson.cpp +++ b/alyson/src/alyson.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -16,31 +15,42 @@ int main(int argc, char *argv[]) { Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png")); - std::cout << "alyson: init" << std::endl; - int g = init(); - if(g != 0) { - std::cout << "alyson: init failed with error code " << g << std::endl; - return g; - } + Camera2D camera = { 0 }; + camera.target = (Vector2){ 0, 0 }; + camera.offset = (Vector2){ 0, 0 }; + camera.rotation = 0.0f; + camera.zoom = 1.0f; + + init(0); while (!WindowShouldClose()) { + float dt = GetFrameTime(); + if (IsWindowResized()) { SetWindowTitle((std::string(WINDOW_TITLE) + " -- " + std::to_string(GetScreenWidth()) + "x" + std::to_string(GetScreenHeight())).c_str()); } BeginDrawing(); - DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE); - DrawTextFull( - GetFontDefault(), - WINDOW_TITLE, - { GetScreenWidth() / 2.f, GetScreenHeight() - 60.f }, - TEXT_ORIENTATION_CENTER, 0.f, - 40.f, 5.f, - 0.f, BLACK - ); + BeginMode2D(camera); + ClearBackground(RAYWHITE); + camera.rotation += dt; + camera.rotation = (int)camera.rotation % 360; - ClearBackground(RAYWHITE); + DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE); + DrawTextFull( + GetFontDefault(), + WINDOW_TITLE, + { GetScreenWidth() / 2.f, GetScreenHeight() - 60.f }, + TEXT_ORIENTATION_CENTER, 0.f, + 40.f, 5.f, + 0.f, BLACK + ); + + update(dt); + render(dt); + + EndMode2D(); EndDrawing(); } diff --git a/alyson/src/rlyson.c b/alyson/src/rlyson.c index c07b893..c8aa816 100644 --- a/alyson/src/rlyson.c +++ b/alyson/src/rlyson.c @@ -1,46 +1,46 @@ - #include #include "raylib.h" + #include "raymath.h" void DrawTextFull( - Font font, - const char *text, - Vector2 origin, - text_orientation_t orientation, - float rotation, - float fontSize, - float spacing, - float lineSpacing, - Color tint - ) + const Font font, + const char* text, + Vector2 origin, + const text_orientation_t orientation, + const float rotation, + const float fontSize, + const float spacing, + const float lineSpacing, + const Color tint + ) { - Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing); + const Vector2 textSize = MeasureTextEx(font, text, fontSize, spacing); DrawCircleV(origin, 10, RED); - Vector2 pos = origin; + const Vector2 pos = origin; origin = (Vector2){0,0}; - + switch (orientation) { - case TEXT_ORIENTATION_LEFT: - origin.x += textSize.x; - break; - case TEXT_ORIENTATION_RIGHT: - break; - case TEXT_ORIENTATION_CENTER: - origin.x += (textSize.x / 2); - break; - default: - break; + case TEXT_ORIENTATION_LEFT: + origin.x += textSize.x; + break; + case TEXT_ORIENTATION_RIGHT: + break; + case TEXT_ORIENTATION_CENTER: + origin.x += (textSize.x / 2); + break; + default: + break; } origin.y += textSize.y / 2; DrawCircleV(Vector2Add(origin, pos), 10, DARKGREEN); - SetTextLineSpacing(lineSpacing); + SetTextLineSpacing((int)lineSpacing); DrawTextPro(font, text, pos, origin, rotation, fontSize, spacing, tint); } diff --git a/src/main.cpp b/src/main.cpp index 766a3f5..c499942 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,9 +2,12 @@ #include #include -int init() { - std::cout << "colysis: init" << std::endl; - return 0; +size_t init(size_t task) { + if(task == 0) + return 2; + + + return 0; } void update(float dt) {