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 "tiles/tilebase.hpp"
#include "saving/saving.hpp"
#include "settings/hardcode.hpp"
#include <cmath>
#include <cstdlib>
@@ -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.
+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