/
entitycreator.cpp
98 lines (89 loc) · 2.65 KB
/
entitycreator.cpp
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
#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
#include "entitycreator.hpp"
#include "entitymanager.hpp"
#include "entity.hpp"
#include "world.hpp"
void createPlayer(World * world, std::string name, Coord cord)
{
auto id = world->emgr.createEntity(Kind::Player);
world->emgr.getCompManager(id).createComponent<Display>(sf::Color::Black, sf::Color::Blue, "player")
.createComponent<Description>(name)
.createComponent<Position>(cord.x, cord.y)
.createComponent<Storage>();
Entity * player = world->emgr.getEntity(id);
player->flags["canPick"] = true;
player->flags["canDrop"] = true;
auto& tile = world->at(cord.x, cord.y);
tile.actor = id;
tile.occupied = true;
}
void createFloorTile(World * world, Types::FloorType type, Coord cord)
{
auto& tile = world->at(cord.x, cord.y);
tile.x = cord.x;
tile.y = cord.y;
tile.occupied = false;
using namespace Types;
switch ( type ) {
case MAGMA:
tile.floor_tile = "magma";
tile.visible = true;
tile.passable = false;
break;
case WATER:
tile.floor_tile = "water";
tile.visible = true;
tile.passable = false;
break;
case GRASS:
tile.floor_tile = "grass";
tile.visible = true;
tile.passable = true;
break;
case STONE:
tile.floor_tile = "stone";
tile.visible = true;
tile.passable = false;
break;
}
}
void createObstacle(World * world, Types::ObstacleType type, Coord cord)
{
auto& tile = world->at(cord.x, cord.y);
tile.x = cord.x;
tile.y = cord.y;
using namespace Types;
switch ( type ) {
case WALL:
tile.floor_tile = "wall";
tile.visible = true;
tile.passable = false;
break;
case HEDGE:
tile.floor_tile = "wall";
tile.visible = true;
tile.passable = false;
break;
}
}
void createItem(
World * world,
std::string item_name,
std::string item_tile,
sf::Color color,
Coord cord,
bool pickable,
bool buyable,
uint price) {
uint ent = world->emgr.createEntity(Kind::Item);
world->emgr.getCompManager(ent)
.createComponent<Item>(pickable, buyable, buyable,price)
.createComponent<Display>(sf::Color::Black, color, item_tile)
.createComponent<Description>(item_name)
.createComponent<Position>(cord.x, cord.y);
auto& tile = world->at(cord.x, cord.y);
tile.objects.push_back(ent);
tile.taken = true;
}