Enemies can be tagged as moving randomly, but it's very subtle.
This commit is contained in:
parent
222b39c403
commit
d6916b675e
4 changed files with 11 additions and 3 deletions
|
@ -33,7 +33,8 @@
|
||||||
"components": [
|
"components": [
|
||||||
{"type": "Tile", "config": {"chr": "\u17a5"}},
|
{"type": "Tile", "config": {"chr": "\u17a5"}},
|
||||||
{"type": "Combat", "config": {"hp": 100, "damage": 5}},
|
{"type": "Combat", "config": {"hp": 100, "damage": 5}},
|
||||||
{"type": "EnemyConfig", "config": {"hearing_distance": 3}}
|
{"type": "EnemyConfig", "config": {"hearing_distance": 15}},
|
||||||
|
{"type": "Motion", "config": {"dx": 0, "dy": 0, "random": true}}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"RAT": {
|
"RAT": {
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace components {
|
||||||
struct Motion {
|
struct Motion {
|
||||||
int dx;
|
int dx;
|
||||||
int dy;
|
int dy;
|
||||||
|
bool random=false;
|
||||||
DEFINE_SERIALIZABLE(Motion, dx, dy);
|
DEFINE_SERIALIZABLE(Motion, dx, dy);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,6 +69,8 @@ namespace components {
|
||||||
world.set<EnemyConfig>(entity, {config["hearing_distance"]});
|
world.set<EnemyConfig>(entity, {config["hearing_distance"]});
|
||||||
} else if(comp["type"] == "Combat") {
|
} else if(comp["type"] == "Combat") {
|
||||||
world.set<Combat>(entity, {config["hp"], config["damage"]});
|
world.set<Combat>(entity, {config["hp"], config["damage"]});
|
||||||
|
} else if(comp["type"] == "Motion") {
|
||||||
|
world.set<Motion>(entity, {config["dx"], config["dy"], config["random"]});
|
||||||
} else {
|
} else {
|
||||||
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
|
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
|
||||||
std::string(comp["type"])));
|
std::string(comp["type"])));
|
||||||
|
|
|
@ -43,7 +43,7 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player
|
||||||
|
|
||||||
Point out = position.location; // copy
|
Point out = position.location; // copy
|
||||||
if(game_map.distance(out) < config.hearing_distance) {
|
if(game_map.distance(out) < config.hearing_distance) {
|
||||||
game_map.neighbors(out);
|
game_map.neighbors(out, motion.random);
|
||||||
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
|
motion = { int(out.x - position.location.x), int(out.y - position.location.y)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,11 +192,15 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str
|
||||||
auto enemy = world.entity();
|
auto enemy = world.entity();
|
||||||
auto enemy_data = config.enemies[name];
|
auto enemy_data = config.enemies[name];
|
||||||
world.set<Position>(enemy, {game_map.place_entity(in_room)});
|
world.set<Position>(enemy, {game_map.place_entity(in_room)});
|
||||||
world.set<Motion>(enemy, {0,0});
|
|
||||||
|
|
||||||
if(enemy_data.contains("components")) {
|
if(enemy_data.contains("components")) {
|
||||||
components::configure(world, enemy, enemy_data);
|
components::configure(world, enemy, enemy_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!world.has<Motion>(enemy)) {
|
||||||
|
world.set<Motion>(enemy, {0,0});
|
||||||
|
}
|
||||||
|
|
||||||
return enemy;
|
return enemy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue