improved placement a little bit at least

This commit is contained in:
noschXL
2025-09-03 08:20:28 +02:00
parent 9ed0561040
commit 7a7d0ad6d7
+9 -17
View File
@@ -2,6 +2,8 @@
#include "entities/entitybase.hpp"
#include "render/textures.hpp"
#include "tiles/tilebase.hpp"
#include <cmath>
#include <cstdlib>
void PlayerController(Entity &e, float deltatime) {
raylib::Vector2 acceleration = {0,0};
@@ -18,8 +20,8 @@ void PlayerController(Entity &e, float deltatime) {
}
int main() {
int screenWidth = 1920;
int screenHeight = 1080;
int screenWidth = 1200;
int screenHeight = 800;
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
@@ -79,32 +81,22 @@ int main() {
int offsetX = ((int)camera.target.x % bg.width);
int offsetY = ((int)camera.target.y % bg.height);
//for (int i = -1; i <= GetScreenWidth() / bw + 1; i++) {
// for (int j = -1; j <= GetScreenHeight() / bh + 1; j++) {
// DrawTexture(
// bg,
// camera.target.x - offsetX - screenWidth / 2.0f + i * bw,
// camera.target.y - offsetY - screenHeight / 2.0f + j * bh,
// WHITE
// );
// }
//}
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
storedPosition = GetMousePosition();
storedPosition.x += camera.target.x;
storedPosition.y += camera.target.y;
storedPosition.x += camera.target.x - screenWidth / 2.0f;
storedPosition.y += camera.target.y - screenHeight / 2.0f;
chunkx = storedPosition.x / 8 / 64;
chunky = storedPosition.y / 8 / 64;
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";
gamemap.layers[0].chunks[Coordinate{chunkx, chunky}].tiles[tileindex].spriteid = 1;
gamemap.layers[1].chunks[Coordinate{chunkx, chunky}].tiles[tileindex].spriteid = 1;
}