From c3349a7f518d21d402a40db61cf69260f3d34fbb Mon Sep 17 00:00:00 2001 From: nosch Date: Fri, 5 Sep 2025 20:20:58 +0200 Subject: [PATCH] added hardcode and settings --- save.json | 2 +- src/main.cpp | 65 +++++++++++++-------------------------- src/settings/hardcode.hpp | 9 ++++++ 3 files changed, 32 insertions(+), 44 deletions(-) create mode 100644 src/settings/hardcode.hpp diff --git a/save.json b/save.json index e01e9a0..264be15 100644 --- a/save.json +++ b/save.json @@ -1 +1 @@ -451 408 +495 270 diff --git a/src/main.cpp b/src/main.cpp index c43eaa9..75c53dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "render/textures.hpp" #include "tiles/tilebase.hpp" #include "saving/saving.hpp" +#include "settings/hardcode.hpp" #include #include @@ -27,8 +28,8 @@ struct Tiles { }; int main() { - int screenWidth = 1980; - int screenHeight = 1080; + int screenWidth = 1980 / 2; + int screenHeight = 1080 / 2; raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); @@ -85,54 +86,32 @@ int main() { DrawText("Middle", 190, 200, 20, WHITE); - Texture bg = tileTextures.GetTexture(0); + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { + Vector2 mousepos = GetMousePosition(); + Vector2 worldpos; + worldpos.x = mousepos.x + camera.target.x; + worldpos.y = mousepos.y + camera.target.y; - // Infinite Background - int bh = bg.height; - int bw = bg.width; - int offsetX = ((int)camera.target.x % bg.width); - int offsetY = ((int)camera.target.y % bg.height); - - if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { - storedPosition = GetMousePosition(); - storedPosition.x += camera.target.x - screenWidth / 2.0f; - storedPosition.y += camera.target.y - screenHeight / 2.0f; - - chunkx = storedPosition.x / 8 / 64 - 1; - chunky = storedPosition.y / 8 / 64 - 1; - - int tileindex = (int)storedPosition.x % (8*64) / 64 + 8 * ((int)storedPosition.y % (8*64) / 64); - - tileindex = abs(tileindex); - - std::cout << "placed at: " << chunkx << ", " << chunky << ". index: " << tileindex << "\n"; - - Coordinate chunk; - chunk.x = chunkx; - chunk.y = chunky; - - for (auto it = gamemap.layers[0].chunks.begin(); it != gamemap.layers[0].chunks.end(); ++it) { - std::cout << it->first.x << ", " << it->first.y << "\n"; + Coordinate chunkpos; + chunkpos.x = worldpos.x / CHUNKWIDTH; + chunkpos.y = worldpos.y / CHUNKWIDTH; + } - gamemap.layers[1].chunks[chunk].tiles[tileindex].spriteid = 1; - - } - - raylib::Rectangle fov{ - camera.target.x - screenWidth / 2 / zoom, - camera.target.y - screenHeight / 2 / zoom, - screenWidth / zoom, - screenHeight / zoom, - }; + raylib::Rectangle fov{ + camera.target.x - screenWidth / 2 / zoom, + camera.target.y - screenHeight / 2 / zoom, + screenWidth / zoom, + screenHeight / zoom, + }; - gamemap.Draw(fov); + gamemap.Draw(fov); - player.Draw(); + player.Draw(); - EndMode2D(); - EndDrawing(); + EndMode2D(); + EndDrawing(); } // UnloadTexture() and CloseWindow() are called automatically. diff --git a/src/settings/hardcode.hpp b/src/settings/hardcode.hpp new file mode 100644 index 0000000..7bfc90e --- /dev/null +++ b/src/settings/hardcode.hpp @@ -0,0 +1,9 @@ +#ifndef HARDCODE +#define HARDCODE + +const int CHUNKSIZE = 8; +const int TILEWIDTH = 64; +const int CHUNKWIDTH = CHUNKSIZE * TILEWIDTH; +const int CHUNKTILES = CHUNKSIZE * CHUNKSIZE; + +#endif // !HARDCODE