tiles are broken :)
This commit is contained in:
+17
-5
@@ -27,12 +27,14 @@ struct Tiles {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int screenWidth = 1200;
|
int screenWidth = 1980;
|
||||||
int screenHeight = 800;
|
int screenHeight = 1080;
|
||||||
|
|
||||||
|
|
||||||
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
|
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
|
||||||
|
|
||||||
|
window.SetFullscreen(true);
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
GenDefaultTexture();
|
GenDefaultTexture();
|
||||||
@@ -46,6 +48,8 @@ int main() {
|
|||||||
player.spriteid = 0;
|
player.spriteid = 0;
|
||||||
|
|
||||||
entityTextures.LoadImage("./src/assets/playersprite.png");
|
entityTextures.LoadImage("./src/assets/playersprite.png");
|
||||||
|
std::cout << "kms\n";
|
||||||
|
tileTextures.LoadImage("./src/assets/transparent.png");
|
||||||
tileTextures.LoadImage("./src/assets/BasicTile.png");
|
tileTextures.LoadImage("./src/assets/BasicTile.png");
|
||||||
tileTextures.LoadImage("./src/assets/rock1.png");
|
tileTextures.LoadImage("./src/assets/rock1.png");
|
||||||
|
|
||||||
@@ -62,6 +66,7 @@ int main() {
|
|||||||
int chunkx = 0;
|
int chunkx = 0;
|
||||||
int chunky = 0;
|
int chunky = 0;
|
||||||
|
|
||||||
|
std::cout << "textures and includes loaded, window stuff now\n";
|
||||||
|
|
||||||
while (!window.ShouldClose()) {
|
while (!window.ShouldClose()) {
|
||||||
float deltatime = GetFrameTime();
|
float deltatime = GetFrameTime();
|
||||||
@@ -93,8 +98,8 @@ int main() {
|
|||||||
storedPosition.x += camera.target.x - screenWidth / 2.0f;
|
storedPosition.x += camera.target.x - screenWidth / 2.0f;
|
||||||
storedPosition.y += camera.target.y - screenHeight / 2.0f;
|
storedPosition.y += camera.target.y - screenHeight / 2.0f;
|
||||||
|
|
||||||
chunkx = storedPosition.x / 8 / 64;
|
chunkx = storedPosition.x / 8 / 64 - 1;
|
||||||
chunky = storedPosition.y / 8 / 64;
|
chunky = storedPosition.y / 8 / 64 - 1;
|
||||||
|
|
||||||
int tileindex = (int)storedPosition.x % (8*64) / 64 + 8 * ((int)storedPosition.y % (8*64) / 64);
|
int tileindex = (int)storedPosition.x % (8*64) / 64 + 8 * ((int)storedPosition.y % (8*64) / 64);
|
||||||
|
|
||||||
@@ -102,8 +107,15 @@ int main() {
|
|||||||
|
|
||||||
std::cout << "placed at: " << chunkx << ", " << chunky << ". index: " << tileindex << "\n";
|
std::cout << "placed at: " << chunkx << ", " << chunky << ". index: " << tileindex << "\n";
|
||||||
|
|
||||||
|
Coordinate chunk;
|
||||||
|
chunk.x = chunkx;
|
||||||
|
chunk.y = chunky;
|
||||||
|
|
||||||
gamemap.layers[1].chunks[Coordinate{chunkx, chunky}].tiles[tileindex].spriteid = 1;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
#include "tilebase.hpp"
|
#include "tilebase.hpp"
|
||||||
#include "iostream"
|
#include "iostream"
|
||||||
#include <bits/types/cookie_io_functions_t.h>
|
|
||||||
|
|
||||||
Coordinate::Coordinate() {
|
Coordinate::Coordinate() {
|
||||||
x = 0;
|
x = 0;
|
||||||
@@ -43,7 +42,8 @@ Chunk::Chunk()
|
|||||||
: position(0, 0), owner(nullptr) {
|
: position(0, 0), owner(nullptr) {
|
||||||
tiles.reserve(64);
|
tiles.reserve(64);
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
tiles.emplace_back(i, 0, this);
|
int spriteid = owner->id > 0;
|
||||||
|
tiles.emplace_back(i, spriteid, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,13 +110,15 @@ void Map::Draw(raylib::Rectangle aera) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Map::Init() {
|
void Map::Init() {
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int x = -1; x < 2; x++) {
|
for (int x = -1; x < 2; x++) {
|
||||||
for (int y = -1; y < 2; y++) {
|
for (int y = -1; y < 2; y++) {
|
||||||
layers[0].chunks.emplace(
|
layers[i].chunks.emplace(
|
||||||
std::piecewise_construct,
|
std::piecewise_construct,
|
||||||
std::forward_as_tuple(Coordinate{x, y}), // key
|
std::forward_as_tuple(Coordinate{x, y}), // key
|
||||||
std::forward_as_tuple(Coordinate{x, y}, &layers[0]) // value: construct Chunk here
|
std::forward_as_tuple(Coordinate{x, y}, &layers[i])
|
||||||
);
|
);// value: construct Chunk here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user