TazGraph Project v0.1.0
Loading...
Searching...
No Matches
GridComponent.h
1#pragma once
2
3#include "../../../Components.h"
4
5#define GRID_EMPTY_TILE 0x0000
6#define GRID_SOLID_TILE 0x0001
7#define GRID_ROWS 4
8#define GRID_COLUMNS 4
9#define GRID_ELEMENT_WIDTH 8
10#define GRID_ELEMENT_HEIGHT 8
11#define TILE_NUM_GRID_ELEMENTS (GRID_ROWS * GRID_COLUMNS) //16
12#define MAX_MAP_TILE_HEIGHT 20
13#define MAX_MAP_WIDTH_TILES 100
14#define MAX_MAP_GRID_HEIGHT (MAX_MAP_TILE_HEIGHT * GRID_ROWS) //80
15#define MAX_MAP_GRID_WIDTH (MAX_MAP_TILE_HEIGHT * GRID_COLUMNS) //100
16
17constexpr size_t GRID_CELL_NUM = 16;
18
19class GridComponent : public Component //GridComp --> ColliderComp
20{
21private:
22 std::bitset<GRID_CELL_NUM> bitset ;
23public:
24 glm::ivec2 position;
25 int scaledTile;
26 ColliderComponent* collider = nullptr;
27
28 GridComponent() = default;
29
31 {
32
33 }
34
35 GridComponent(int xpos, int ypos, int tscaled, std::bitset<GRID_CELL_NUM> collider_bitSet = std::bitset<GRID_CELL_NUM>())
36 {
37 position.x = xpos;
38 position.y = ypos;
39
40 scaledTile = tscaled;
41
42 bitset = collider_bitSet.set();
43 }
44
45 void init() override
46 {
47 auto flippedBitset = ~bitset;
48
49 if (flippedBitset.none()) {
50 //entity->addComponent<ColliderComponent>((position.x), (position.y), GRID_ELEMENT_WIDTH * GRID_COLUMNS);
51 }
52 else {
53 glm::ivec2 gridPos;
54
55 for (auto gridindex = 0; gridindex < TILE_NUM_GRID_ELEMENTS; gridindex++)
56 { //SetGridTileBlock
57 if (bitset[gridindex]) {
58 gridPos.x = (gridindex % GRID_COLUMNS) * GRID_ELEMENT_WIDTH;
59 gridPos.y = (int)(gridindex / GRID_ROWS) * GRID_ELEMENT_HEIGHT;
60
61 //entity->addComponent<ColliderComponent>((position.x + gridPos.x), (position.y + gridPos.y), GRID_ELEMENT_WIDTH);
62
63 }
64 }
65 }
66
67 }
68
69 void update(float deltaTime) override
70 {
71
72 }
73
74 std::string GetComponentName() override {
75 return "GridComponent";
76 }
77};
Definition ColliderComponent.h:12
Definition GECS.h:123
Definition GridComponent.h:20