please work git
This commit is contained in:
+7
-17
@@ -45,8 +45,7 @@ int main() {
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
Vector2 storedPosition = { 0, 0 };
|
||||
bool shouldDrawPlaceholder = false;
|
||||
float zoom = 1;
|
||||
|
||||
|
||||
while (!window.ShouldClose())
|
||||
@@ -60,9 +59,10 @@ int main() {
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
|
||||
camera.target = { player.rect.x + player.rect.width / 2.0f, player.rect.y + player.rect.height / 2.0f};
|
||||
|
||||
if (IsKeyDown(KEY_Q)) camera.zoom += 0.1f;
|
||||
if (IsKeyDown(KEY_Q)) zoom += 0.1f;
|
||||
|
||||
DrawText("Middle", 190, 200, 20, WHITE);
|
||||
|
||||
@@ -85,21 +85,11 @@ int main() {
|
||||
// }
|
||||
//}
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
storedPosition = GetMousePosition();
|
||||
shouldDrawPlaceholder = true;
|
||||
}
|
||||
|
||||
if (shouldDrawPlaceholder) {
|
||||
gamemap.layers[0].chunks[Vector2{(storedPosition.x / 512),(storedPosition.y / 512)}].tiles[(int)((((int)storedPosition.y % 512) / 64) * 8 + ((int)storedPosition.x % 512) / 64)].spriteid = 1;
|
||||
placeholder.Draw(storedPosition.x, storedPosition.y, WHITE);
|
||||
}
|
||||
|
||||
raylib::Rectangle fov{
|
||||
camera.target.x - screenWidth / 2 * camera.zoom,
|
||||
camera.target.y - screenHeight / 2 * camera.zoom,
|
||||
screenWidth * camera.zoom,
|
||||
screenHeight * camera.zoom,
|
||||
camera.target.x - screenWidth / 2 / zoom,
|
||||
camera.target.y - screenHeight / 2 / zoom,
|
||||
screenWidth / zoom,
|
||||
screenHeight / zoom,
|
||||
};
|
||||
|
||||
gamemap.Draw(fov);
|
||||
|
||||
+23
-14
@@ -20,25 +20,30 @@ Layer::Layer()
|
||||
// ----------------- Chunk -----------------
|
||||
Chunk::Chunk(Vector2 pos, Layer* Owner)
|
||||
: position(pos), owner(Owner) {
|
||||
|
||||
tiles.reserve(64);
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
tiles[i].owner = this;
|
||||
tiles[i].id = i;
|
||||
tiles[i].spriteid = 0;
|
||||
tiles.emplace_back(i, 0, this);
|
||||
}
|
||||
}
|
||||
|
||||
Chunk::Chunk()
|
||||
: position(0, 0), owner(nullptr) {
|
||||
tiles.reserve(64);
|
||||
for (int i = 0; i < 64; i++) {
|
||||
tiles[i].owner = this;
|
||||
tiles[i].id = i;
|
||||
tiles[i].spriteid = 0;
|
||||
tiles.emplace_back(i, 0, this);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------- Tile -----------------
|
||||
Tile::Tile(ID Id, ID Spriteid, Chunk* Owner)
|
||||
: id(Id), spriteid(Spriteid), animationframe(0), owner(Owner) {}
|
||||
: id(Id), spriteid(Spriteid), animationframe(0), owner(Owner) {
|
||||
|
||||
int posx = owner->position.x * 64 * 8 + id % 8 * 64;
|
||||
int posy = owner->position.y * 64 * 8 + id / 8 * 64;
|
||||
|
||||
}
|
||||
|
||||
Tile::Tile()
|
||||
: id(0), spriteid(1), animationframe(0), owner(nullptr) {}
|
||||
@@ -58,8 +63,8 @@ void Tile::Draw() {
|
||||
int posx = owner->position.x * 64 * 8 + id % 8 * 64;
|
||||
int posy = owner->position.y * 64 * 8 + id / 8 * 64;
|
||||
|
||||
std::cout << "Tile at "<< posx << ", " << posy << "\n";
|
||||
std::cout << "Owner at "<< owner->position.x << ", " << owner->position.y << "\n";
|
||||
//std::cout << "Tile at "<< posx << ", " << posy << "\n";
|
||||
//std::cout << "Owner at "<< owner->position.x << ", " << owner->position.y << "\n";
|
||||
|
||||
DrawTextureEx(tileTextures.GetTexture(spriteid), Vector2({(float)posx,(float)posy}), 0, 1, WHITE);
|
||||
|
||||
@@ -71,19 +76,19 @@ void Chunk::Draw(raylib::Rectangle aera) {
|
||||
int y = i / 8;
|
||||
raylib::Rectangle box{x * 64 + position.x * 8 * 64, y * 64 + position.y * 8 * 64, 64, 64};
|
||||
|
||||
//if (box.CheckCollision(aera)) {
|
||||
if (box.CheckCollision(aera)) {
|
||||
tiles[i].Draw();
|
||||
//}
|
||||
}
|
||||
;}
|
||||
}
|
||||
|
||||
void Layer::Draw(raylib::Rectangle aera) {
|
||||
for (auto it = chunks.begin(); it != chunks.end(); ++it) {
|
||||
raylib::Rectangle box{it->first.x * 64 * 8, it->first.y * 64 * 8, 64 * 8, 64 * 8};
|
||||
|
||||
//if (box.CheckCollision(aera)) {
|
||||
if (box.CheckCollision(aera)) {
|
||||
it->second.Draw(aera);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +101,11 @@ void Map::Draw(raylib::Rectangle aera) {
|
||||
void Map::Init() {
|
||||
for (int x = -1; x < 2; x++) {
|
||||
for (int y = -1; y < 2; y++) {
|
||||
layers[0].chunks[Vector2{(float)x,(float)y}] = Chunk(Vector2{ (float)x, (float)y }, &layers[0]);
|
||||
layers[0].chunks.emplace(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(Vector2{(float)x, (float)y}), // key
|
||||
std::forward_as_tuple(Vector2{(float)x, (float)y}, &layers[0]) // value: construct Chunk here
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ struct Tile {
|
||||
|
||||
struct Chunk {
|
||||
raylib::Vector2 position;
|
||||
Tile tiles[64]; // dynamic instead of fixed array
|
||||
std::vector<Tile> tiles; // dynamic instead of fixed array
|
||||
Layer* owner;
|
||||
|
||||
void Draw(raylib::Rectangle aera);
|
||||
|
||||
Reference in New Issue
Block a user