Files
FactoryBuilder/src/tiles/tilebase.hpp
T
2025-09-03 00:08:16 +02:00

94 lines
1.6 KiB
C++

#ifndef TILEBASE_HPP
#define TILEBASE_HPP
#include "../render/textures.hpp"
#include <unordered_map>
#include <vector>
#include <array>
#include "iostream"
// Forward declarations
struct Chunk;
struct Layer;
struct Map;
struct Coordinate {
int x, y;
Coordinate();
Coordinate(int X, int Y);
};
struct Tile {
ID id;
ID spriteid;
int animationframe;
std::vector<int> inventory;
Chunk* owner; // pointer instead of reference
void Draw();
void Update(float deltatime);
Tile(ID Id, ID spriteId, Chunk* owner);
Tile(); // default constructor (needed for containers)
};
struct Chunk {
Coordinate position;
std::vector<Tile> tiles; // dynamic instead of fixed array
Layer* owner;
void Draw(raylib::Rectangle aera);
Chunk(Coordinate pos, Layer* Owner);
Chunk(); // default constructor
};
struct CoordinateHash {
std::size_t operator()(const Coordinate& c) const noexcept;
};
struct CoordinateEq {
bool operator()(const Coordinate& a, const Coordinate& b) const noexcept;
};
struct Layer {
std::unordered_map<Coordinate, Chunk, CoordinateHash, CoordinateEq> chunks;
ID id;
bool DEBUG;
Map* owner;
void Draw(raylib::Rectangle aera);
Layer(ID Id, Map* Owner);
Layer(); // default constructor
};
enum Actions{
place,
destroy,
rotate,
open,
close,
drop,
};
struct packet {
Actions action;
Coordinate position;
int data;
};
struct Map {
std::array<Layer, 4> layers; // ground/water/void/decoration
int worldtime;
bool DEBUG;
Map();
void Draw(raylib::Rectangle aera);
void Init();
void Update(float deltatime, packet datapacket);
};
#endif // !TILEBASE_HPP