Sprite is now a component we can place on anything to render it.
This commit is contained in:
parent
9c37960283
commit
6bca6d021e
8 changed files with 50 additions and 26 deletions
|
@ -14,8 +14,8 @@
|
|||
"player": {
|
||||
},
|
||||
"worldgen": {
|
||||
"enemy_probability": 20,
|
||||
"empty_room_probability": 10,
|
||||
"device_probability": 20
|
||||
"enemy_probability": 100,
|
||||
"empty_room_probability": 0,
|
||||
"device_probability": 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
},
|
||||
{"_type": "Device",
|
||||
"config": {"test": true},
|
||||
"events": ["Events::GUI::STAIRS_DOWN"]}
|
||||
"events": ["Events::GUI::STAIRS_DOWN"]},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
},
|
||||
"STAIRS_UP": {
|
||||
|
@ -29,7 +30,8 @@
|
|||
},
|
||||
{"_type": "Device",
|
||||
"config": {"test": true},
|
||||
"events": ["Events::GUI::STAIRS_UP"]}
|
||||
"events": ["Events::GUI::STAIRS_UP"]},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
},
|
||||
"SPIKE_TRAP": {
|
||||
|
@ -44,7 +46,8 @@
|
|||
},
|
||||
{"_type": "Device",
|
||||
"config": {"test": true},
|
||||
"events": ["Events::GUI::TRAP"]}
|
||||
"events": ["Events::GUI::TRAP"]},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,15 +11,29 @@
|
|||
{"_type": "EnemyConfig", "hearing_distance": 5}
|
||||
]
|
||||
},
|
||||
"KNIGHT": {
|
||||
"components": [
|
||||
{"_type": "Tile", "display": "\u088d",
|
||||
"foreground": [131, 213, 238],
|
||||
"background": [30, 20, 75]
|
||||
},
|
||||
{"_type": "Combat", "hp": 200, "damage": 15, "dead": false},
|
||||
{"_type": "Motion", "dx": 0, "dy": 0, "random": false},
|
||||
{"_type": "LightSource", "strength": 70, "radius": 2},
|
||||
{"_type": "EnemyConfig", "hearing_distance": 5},
|
||||
{"_type": "Sprite", "name": "armored_knight"}
|
||||
]
|
||||
},
|
||||
"EVIL_EYE": {
|
||||
"components": [
|
||||
{"_type": "Tile", "display": "\u08ac",
|
||||
"foreground": [75, 200, 125],
|
||||
{"_type": "Tile", "display": "\u0758",
|
||||
"foreground": [205, 164, 246],
|
||||
"background": [30, 20, 75]
|
||||
},
|
||||
{"_type": "Combat", "hp": 100, "damage": 50, "dead": false},
|
||||
{"_type": "Motion", "dx": 0, "dy": 0, "random": false},
|
||||
{"_type": "EnemyConfig", "hearing_distance": 10}
|
||||
{"_type": "EnemyConfig", "hearing_distance": 10},
|
||||
{"_type": "Sprite", "name": "evil_eye"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
{"_type": "Tile", "display": "\u0f08",
|
||||
"foreground": [24, 120, 189],
|
||||
"background": [230,120, 120]
|
||||
}
|
||||
},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
},
|
||||
"SWORD_RUSTY": {
|
||||
|
@ -22,7 +23,8 @@
|
|||
{"_type": "Tile", "display": "\u1e37",
|
||||
"foreground": [24, 120, 189],
|
||||
"background": [24, 120, 189]
|
||||
}
|
||||
},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
},
|
||||
"SWORD_LIGHT_AND_FLAME": {
|
||||
|
@ -36,7 +38,8 @@
|
|||
"foreground": [24, 205, 210],
|
||||
"background": [24, 205, 210]
|
||||
},
|
||||
{"_type": "Weapon", "damage": 30}
|
||||
{"_type": "Weapon", "damage": 30},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
},
|
||||
"CHEST_SMALL": {
|
||||
|
@ -48,7 +51,8 @@
|
|||
"foreground": [150, 100, 189],
|
||||
"background": [150, 100, 189]
|
||||
},
|
||||
{"_type": "Loot", "amount": 10}
|
||||
{"_type": "Loot", "amount": 10},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
],
|
||||
"inventory_count": 1
|
||||
},
|
||||
|
@ -62,7 +66,8 @@
|
|||
"foreground": [24, 205, 210],
|
||||
"background": [24, 205, 210]
|
||||
},
|
||||
{"_type": "LightSource", "strength": 60, "radius": 1.8}
|
||||
{"_type": "LightSource", "strength": 60, "radius": 1.8},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
},
|
||||
"POTION_HEALING_SMALL": {
|
||||
|
@ -75,7 +80,8 @@
|
|||
"foreground": [255, 205, 189],
|
||||
"background": [255, 205, 189]
|
||||
},
|
||||
{"_type": "Curative", "hp": 20}
|
||||
{"_type": "Curative", "hp": 20},
|
||||
{"_type": "Sprite", "name": "barrel"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace components {
|
|||
ENROLL_COMPONENT(Combat, hp, damage, dead);
|
||||
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||
ENROLL_COMPONENT(Device, config, events);
|
||||
ENROLL_COMPONENT(Sprite, name);
|
||||
|
||||
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
|
||||
for (auto &i : data) {
|
||||
|
@ -31,5 +32,6 @@ namespace components {
|
|||
components::enroll<Motion>(component_map);
|
||||
components::enroll<LightSource>(component_map);
|
||||
components::enroll<Device>(component_map);
|
||||
components::enroll<Sprite>(component_map);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,10 @@ namespace components {
|
|||
void configure_events(std::vector<std::string> &event_names);
|
||||
};
|
||||
|
||||
struct Sprite {
|
||||
string name;
|
||||
};
|
||||
|
||||
void configure(ComponentMap& component_map);
|
||||
|
||||
// these need to be here if you're using components::convert outside of components.cpp
|
||||
|
|
|
@ -343,19 +343,12 @@ void Raycaster::set_level(GameLevel level) {
|
|||
auto& player = world->get_the<components::Player>();
|
||||
$map = $textures.convert_char_to_texture(tiles.$tile_ids);
|
||||
|
||||
world->query<components::Position>([&](const auto ent, auto &pos) {
|
||||
world->query<components::Sprite>([&](const auto ent, auto& sprite) {
|
||||
// player doesn't need a sprite
|
||||
if(player.entity == ent) return;
|
||||
|
||||
if(world->has<components::Combat>(ent)) {
|
||||
fmt::println("enemy: {}, pos={},{}", ent, pos.location.x, pos.location.y);
|
||||
auto sprite_txt = $textures.sprite_textures.at("evil_eye");
|
||||
fmt::println("entity {} will have sprite named {}", ent, sprite.name);
|
||||
auto sprite_txt = $textures.sprite_textures.at(sprite.name);
|
||||
$sprites.try_emplace(ent, sprite_txt);
|
||||
} else {
|
||||
fmt::println("item or device: {}, pos={},{}", ent, pos.location.x, pos.location.y);
|
||||
auto sprite_txt = $textures.sprite_textures.at("barrel");
|
||||
$sprites.try_emplace(ent, sprite_txt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -234,6 +234,8 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config
|
|||
|
||||
int rand_entity = Random::uniform<int>(0, keys.size() - 1);
|
||||
std::string key = keys[rand_entity];
|
||||
// BUG: this may crash if PLAYER_TILE isn't first
|
||||
if(key == "PLAYER_TITLE") key = keys[rand_entity + 1];
|
||||
auto entity_data = entity_db[key];
|
||||
|
||||
// pass that to the config as it'll be a generic json
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue