added hardcode and settings

This commit is contained in:
nosch
2025-09-05 20:20:58 +02:00
parent a496a5e59a
commit c3349a7f51
3 changed files with 32 additions and 44 deletions
+1 -1
View File
@@ -1 +1 @@
451 408 495 270
+22 -43
View File
@@ -3,6 +3,7 @@
#include "render/textures.hpp" #include "render/textures.hpp"
#include "tiles/tilebase.hpp" #include "tiles/tilebase.hpp"
#include "saving/saving.hpp" #include "saving/saving.hpp"
#include "settings/hardcode.hpp"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
@@ -27,8 +28,8 @@ struct Tiles {
}; };
int main() { int main() {
int screenWidth = 1980; int screenWidth = 1980 / 2;
int screenHeight = 1080; int screenHeight = 1080 / 2;
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window"); raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
@@ -85,54 +86,32 @@ int main() {
DrawText("Middle", 190, 200, 20, WHITE); 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 Coordinate chunkpos;
int bh = bg.height; chunkpos.x = worldpos.x / CHUNKWIDTH;
int bw = bg.width; chunkpos.y = worldpos.y / CHUNKWIDTH;
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";
} }
gamemap.layers[1].chunks[chunk].tiles[tileindex].spriteid = 1;
}
raylib::Rectangle fov{
raylib::Rectangle fov{ camera.target.x - screenWidth / 2 / zoom,
camera.target.x - screenWidth / 2 / zoom, camera.target.y - screenHeight / 2 / zoom,
camera.target.y - screenHeight / 2 / zoom, screenWidth / zoom,
screenWidth / zoom, screenHeight / zoom,
screenHeight / zoom, };
};
gamemap.Draw(fov); gamemap.Draw(fov);
player.Draw(); player.Draw();
EndMode2D(); EndMode2D();
EndDrawing(); EndDrawing();
} }
// UnloadTexture() and CloseWindow() are called automatically. // UnloadTexture() and CloseWindow() are called automatically.
+9
View File
@@ -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