-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapPainter.h
122 lines (109 loc) · 2.97 KB
/
MapPainter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include <iostream>
#include <string>
#define RAYGUI_IMPLEMENTATION
#include "extras/raygui.h"
#include "src/types.h"
#include "src/cell.h"
#include "src/stone.h"
#include "src/lava.h"
#include "src/sand.h"
#include "src/static.h"
#include "src/spray.h"
#include "src/moose.h"
#include "src/water.h"
const int screenWidth = mapSize * Cell::SIZE;
const int screenHeight = screenWidth + 60;
const std::vector<std::string> adjectives = {
"untidy",
"damaging",
"disgusting",
"nonstop",
"panoramic",
"fretful",
"left",
"ablaze",
"educated",
"animated",
"jittery",
"serious",
"elite",
"actually",
"soft",
"neat",
"tested",
"aboriginal",
"splendid",
"little"
};
typedef struct OperationPair {
Cell(*Create)();
void (*Process)(CellularData&, CellMap&);
} OperationPair;
struct OperationPair Operations[] = {
OperationPair {CreateAir, ProcessAir}, // Air
OperationPair {CreateSand, ProcessSand}, // Sand
OperationPair {CreateStatic, ProcessStatic}, // Static
OperationPair {CreateSpray, ProcessSpray}, // Spray
OperationPair {CreateMoose, ProcessMoose}, // Moose
OperationPair {CreateWater, ProcessWater}, // Water
OperationPair {CreateLava, ProcessLava},
OperationPair {CreateStone, ProcessStone}
};
Cell MakeCell(CellType type)
{
if (type >= CellType::END_TYPE) return Operations[(int)CellType::Air].Create();
return Operations[(int)type].Create();
}
CellType QuerySelectedType(int key)
{
switch (key) {
case 0:
break;
case KEY_ZERO:
return CellType::Air;
case KEY_ONE:
return CellType::Sand;
case KEY_TWO:
return CellType::Static;
case KEY_THREE:
return CellType::Spray;
case KEY_FOUR:
return CellType::Moose;
case KEY_FIVE:
return CellType::Water;
}
return CellType::Air;
}
void ProcessCell(const Cell& cell, CellularData& data, CellMap& map)
{
CellType type = cell._id;
if (type >= CellType::END_TYPE) return Operations[(int)CellType::Air].Process(data, map);
Operations[(int)type].Process(data, map);
}
void ProcessMap(CellMap& map, unsigned worldClock)
{
int mapSize = map.size();
for (int i = 0; i < mapSize; i++) {
for (int j = 0; j < mapSize; j++) {
const Cell& cell = map[i][j];
CellularData data = { i, j, worldClock };
// this is stupid
if (cell.clock < worldClock)
ProcessCell(cell, data, map);
}
}
};
void DrawUI(CellType& selectedType)
{
int height = 40;
int width = 90;
for (int i = (int)CellType::Air; i < (int)CellType::END_TYPE; i++) {
CellType type = static_cast<CellType>(i);
Rectangle pos{ height / 2 + (width)*i, screenHeight - 50, width, height };
bool clicked = GuiButton(pos, (std::string("Particle\n") + std::string(Cellnames[i])).c_str());
if (clicked) {
selectedType = type; // It just works
}
}
}