Skip to content

Commit 6b0c7fe

Browse files
committed
Add basic entities
1 parent bbf2056 commit 6b0c7fe

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

src/generate.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,35 @@ World generateOverworld(State *state) {
107107
}
108108
}
109109

110+
std::bernoulli_distribution zombieDistrib(0.001);
111+
112+
std::bernoulli_distribution archerDistrib(0.0005);
113+
114+
std::bernoulli_distribution boomerDistrib(0.0001);
115+
116+
for (int c = 0; c < 1000; c++) {
117+
for (int l = 0; l < 1000; l++) {
118+
if (world[c][l].type == BlockType::EMPTY) {
119+
if (zombieDistrib(gen)) {
120+
auto entity = Entity();
121+
entity.type = EntityType::ZOMBIE;
122+
entity.position = Position(c, l);
123+
state->entities.push_back(entity);
124+
} else if (archerDistrib(gen)) {
125+
auto entity = Entity();
126+
entity.type = EntityType::ARCHER;
127+
entity.position = Position(c, l);
128+
state->entities.push_back(entity);
129+
} else if (boomerDistrib(gen)) {
130+
auto entity = Entity();
131+
entity.type = EntityType::BOOMER;
132+
entity.position = Position(c, l);
133+
state->entities.push_back(entity);
134+
}
135+
}
136+
}
137+
}
138+
110139
return world;
111140
}
112141

@@ -145,6 +174,8 @@ void generate(State *state) {
145174
std::uniform_int_distribution<int> playerPosDistrib(100, 900);
146175
state->playerPosition = Position(playerPosDistrib(gen), playerPosDistrib(gen));
147176

177+
state->entities.clear();
178+
148179
switch (state->level) {
149180
case Level::OVERWORLD:
150181
state->world = generateOverworld(state);

src/main.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@ int main() {
1313
PlaySound(".\\assets\\amogus-drip.wav", nullptr, SND_ASYNC | SND_FILENAME | SND_LOOP);
1414

1515
SetConsoleOutputCP(65001);
16-
17-
while (true) {
18-
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
19-
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &bufferInfo);
20-
21-
if (bufferInfo.dwSize.X >= 150 && bufferInfo.dwSize.Y >= 30) break;
22-
23-
std::cout << "Zwiększ rozmiar okna do min. 150x30 (aktualny " << bufferInfo.dwSize.X << "x"
24-
<< bufferInfo.dwSize.Y << "), a następnie naciśnij ENTER!" << std::endl;
25-
26-
while (!wasKeyPressed(VK_RETURN));
27-
}
28-
2916
setCursorVisibility(false);
3017

3118
auto state = State();

src/render.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,28 @@ void render(State *state) {
317317
auto y = lStartPos - lStart + l;
318318

319319
if (x >= 0 && x <= 1000 && y >= 0 && y <= 1000) {
320-
if (state->world[x][y].item.has_value()) {
320+
auto entity = std::find_if(
321+
std::begin(state->entities), std::end(state->entities),
322+
[x, y](Entity entity) {
323+
return entity.position.x == x && entity.position.y == y;
324+
}
325+
);
326+
327+
if (entity != std::end(state->entities)) {
328+
switch ((*entity).type) {
329+
case EntityType::ZOMBIE:
330+
std::cout << "z";
331+
break;
332+
case EntityType::ARCHER:
333+
std::cout << "a";
334+
break;
335+
case EntityType::BOOMER:
336+
std::cout << "b";
337+
break;
338+
default:
339+
std::cout << "t";
340+
}
341+
} else if (state->world[x][y].item.has_value()) {
321342
std::cout << "i";
322343
} else {
323344
switch (state->world[x][y].type) {

src/state.h

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <optional>
55
#include <sstream>
66
#include <iomanip>
7+
#include <map>
78

89
enum class Screen {
910
MAIN_MENU, SETTINGS, SETTINGS_DIFFICULTY_LEVEL, PLAY_DIFFICULTY_LEVEL, PLAY_LEVEL,
@@ -52,6 +53,10 @@ class Position {
5253

5354
int x = 0;
5455
int y = 0;
56+
57+
bool operator<(Position const &r) const {
58+
return this->x < r.x;
59+
}
5560
};
5661

5762
enum class ItemType {
@@ -107,6 +112,16 @@ class Block {
107112

108113
typedef std::vector<std::vector<Block>> World;
109114

115+
enum class EntityType {
116+
ZOMBIE, ARCHER, BOOMER
117+
};
118+
119+
class Entity {
120+
public:
121+
EntityType type = EntityType::ZOMBIE;
122+
Position position = Position(0, 0);
123+
};
124+
110125
class State {
111126
public:
112127
bool exit = false;
@@ -148,4 +163,6 @@ class State {
148163
int maxArrows = 5;
149164

150165
int keys = 0;
166+
167+
std::vector<Entity> entities;
151168
};

0 commit comments

Comments
 (0)