AnimatedScene now defines how a scene with animated sprites and actors is structured and played.
This commit is contained in:
parent
e1da089600
commit
25f7096489
10 changed files with 43 additions and 48 deletions
2
Makefile
2
Makefile
|
|
@ -72,4 +72,4 @@ money:
|
||||||
scc --exclude-dir subprojects
|
scc --exclude-dir subprojects
|
||||||
|
|
||||||
arena:
|
arena:
|
||||||
./builddir/arena
|
gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args ./builddir/arena
|
||||||
|
|
|
||||||
|
|
@ -134,9 +134,9 @@
|
||||||
"max_scale": 0.9,
|
"max_scale": 0.9,
|
||||||
"simple": true,
|
"simple": true,
|
||||||
"frames": 1,
|
"frames": 1,
|
||||||
"speed": 1.0,
|
"speed": 0.5,
|
||||||
"stationary": false,
|
"stationary": false,
|
||||||
"toggled": false,
|
"toggled": true,
|
||||||
"looped": false
|
"looped": false
|
||||||
},
|
},
|
||||||
"hairy_spider": {
|
"hairy_spider": {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"RAT_KING": {
|
"RAT_KING": {
|
||||||
"components": [
|
"components": [
|
||||||
{"_type": "BossFight",
|
{"_type": "AnimatedScene",
|
||||||
"background": "test_background",
|
"background": "test_background",
|
||||||
"floor": false,
|
"floor": false,
|
||||||
"floor_pos": "floor1",
|
"floor_pos": "floor1",
|
||||||
|
"actors": {
|
||||||
"player": {
|
"player": {
|
||||||
"sprite": "peasant_girl_rear_view",
|
"sprite": "peasant_girl_rear_view",
|
||||||
"start_pos": "player2",
|
"start_pos": "player2",
|
||||||
|
|
@ -12,10 +13,11 @@
|
||||||
"mid_cell": false
|
"mid_cell": false
|
||||||
},
|
},
|
||||||
"boss": {
|
"boss": {
|
||||||
|
"sprite": "rat_king_boss",
|
||||||
"start_pos": "boss5",
|
"start_pos": "boss5",
|
||||||
"scale": 0.6,
|
"scale": 0.6,
|
||||||
"mid_cell": true,
|
"mid_cell": true
|
||||||
"sprite": "rat_king_boss"
|
}
|
||||||
},
|
},
|
||||||
"fixtures": [
|
"fixtures": [
|
||||||
{"name": "torch_fixture", "scale_x": 0.5, "scale_y": 0.5, "cell": "torch1", "x": 66, "y": -50},
|
{"name": "torch_fixture", "scale_x": 0.5, "scale_y": 0.5, "cell": "torch1", "x": 66, "y": -50},
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ namespace boss {
|
||||||
break;
|
break;
|
||||||
case ATTACK: {
|
case ATTACK: {
|
||||||
$ui.status(L"PLAYER TURN");
|
$ui.status(L"PLAYER TURN");
|
||||||
$ui.move_player(run % 10 < 5 ? "player1" : "player2");
|
$ui.move_actor($ui.$player_sprite, "player", run % 10 < 5 ? "player1" : "player2");
|
||||||
int attack_id = std::any_cast<int>(data);
|
int attack_id = std::any_cast<int>(data);
|
||||||
boss::System::combat(attack_id);
|
boss::System::combat(attack_id);
|
||||||
state(State::PLAYER_TURN);
|
state(State::PLAYER_TURN);
|
||||||
|
|
@ -105,7 +105,7 @@ namespace boss {
|
||||||
break;
|
break;
|
||||||
case ATTACK: {
|
case ATTACK: {
|
||||||
$ui.status(L"BOSS TURN");
|
$ui.status(L"BOSS TURN");
|
||||||
$ui.move_boss(run % 10 < 5 ? "boss5" : "boss6");
|
$ui.$boss_pos = $ui.move_actor($ui.$boss_sprite, "boss", run % 10 < 5 ? "boss5" : "boss6");
|
||||||
$ui.$boss_anim.play();
|
$ui.$boss_anim.play();
|
||||||
int attack_id = std::any_cast<int>(data);
|
int attack_id = std::any_cast<int>(data);
|
||||||
boss::System::combat(attack_id);
|
boss::System::combat(attack_id);
|
||||||
|
|
|
||||||
31
boss/ui.cpp
31
boss/ui.cpp
|
|
@ -14,10 +14,10 @@ namespace boss {
|
||||||
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
||||||
$world(world),
|
$world(world),
|
||||||
$boss_id(boss_id),
|
$boss_id(boss_id),
|
||||||
$scene(world->get<components::BossFight>($boss_id)),
|
$scene(world->get<components::AnimatedScene>($boss_id)),
|
||||||
$combat_ui(true)
|
$combat_ui(true)
|
||||||
{
|
{
|
||||||
std::string sprite_name = $scene.boss["sprite"];
|
std::string sprite_name = $scene.actors["boss"]["sprite"];
|
||||||
$boss_sprite = textures::get_sprite(sprite_name);
|
$boss_sprite = textures::get_sprite(sprite_name);
|
||||||
|
|
||||||
// floor is std::optional
|
// floor is std::optional
|
||||||
|
|
@ -25,7 +25,7 @@ namespace boss {
|
||||||
$floor_sprite = textures::get_sprite(*$scene.floor);
|
$floor_sprite = textures::get_sprite(*$scene.floor);
|
||||||
}
|
}
|
||||||
|
|
||||||
$player_sprite = textures::get_sprite($scene.player["sprite"]);
|
$player_sprite = textures::get_sprite($scene.actors["player"]["sprite"]);
|
||||||
|
|
||||||
dbc::check(animation::has(sprite_name), "add boss animation to animations.json");
|
dbc::check(animation::has(sprite_name), "add boss animation to animations.json");
|
||||||
$boss_anim = animation::load(sprite_name);
|
$boss_anim = animation::load(sprite_name);
|
||||||
|
|
@ -66,8 +66,8 @@ namespace boss {
|
||||||
"[floor4|player5|player6|player7|player8|_]"
|
"[floor4|player5|player6|player7|player8|_]"
|
||||||
);
|
);
|
||||||
|
|
||||||
move_boss($scene.boss["start_pos"]);
|
$boss_pos = move_actor($boss_sprite, "boss", $scene.actors["boss"]["start_pos"]);
|
||||||
move_player($scene.player["start_pos"]);
|
move_actor($player_sprite, "player", $scene.actors["player"]["start_pos"]);
|
||||||
|
|
||||||
if($scene.floor) {
|
if($scene.floor) {
|
||||||
position_sprite($floor_sprite, $scene.floor_pos, 1.0f, 1.0f, false);
|
position_sprite($floor_sprite, $scene.floor_pos, 1.0f, 1.0f, false);
|
||||||
|
|
@ -100,13 +100,16 @@ namespace boss {
|
||||||
$combat_ui.init(cell.x, cell.y, cell.w, cell.h);
|
$combat_ui.init(cell.x, cell.y, cell.w, cell.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
sf::Vector2f UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
||||||
auto& cell = $arena.cell_for(cell_name);
|
auto& cell = $arena.cell_for(cell_name);
|
||||||
float x = float(at_mid ? cell.mid_x : cell.x);
|
float x = float(at_mid ? cell.mid_x : cell.x);
|
||||||
float y = float(at_mid ? cell.mid_y : cell.y);
|
float y = float(at_mid ? cell.mid_y : cell.y);
|
||||||
|
|
||||||
st.sprite->setPosition({x + x_diff, y + y_diff});
|
sf::Vector2f pos{x + x_diff, y + y_diff};
|
||||||
|
st.sprite->setPosition(pos);
|
||||||
st.sprite->setScale({scale_x, scale_y});
|
st.sprite->setScale({scale_x, scale_y});
|
||||||
|
|
||||||
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::render(sf::RenderWindow& window) {
|
void UI::render(sf::RenderWindow& window) {
|
||||||
|
|
@ -139,17 +142,9 @@ namespace boss {
|
||||||
$arena.show_text("status", msg);
|
$arena.show_text("status", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::move_boss(const std::string& cell_name) {
|
sf::Vector2f UI::move_actor(textures::SpriteTexture& st, const std::string& actor, const std::string& cell_name) {
|
||||||
float scale = $scene.boss["scale"];
|
float scale = $scene.actors[actor]["scale"];
|
||||||
position_sprite($boss_sprite, cell_name, scale, scale, $scene.boss["mid_cell"]);
|
return position_sprite(st, cell_name, scale, scale, $scene.actors[actor]["mid_cell"]);
|
||||||
|
|
||||||
auto& cell = $arena.cell_for(cell_name);
|
|
||||||
$boss_pos = {float(cell.mid_x), float(cell.mid_y)};
|
|
||||||
}
|
|
||||||
|
|
||||||
void UI::move_player(const std::string& cell_name) {
|
|
||||||
float scale = $scene.player["scale"];
|
|
||||||
position_sprite($player_sprite, cell_name, scale, scale, $scene.player["mid_cell"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::play_animations() {
|
void UI::play_animations() {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace boss {
|
||||||
struct UI {
|
struct UI {
|
||||||
shared_ptr<World> $world = nullptr;
|
shared_ptr<World> $world = nullptr;
|
||||||
Entity $boss_id = NONE;
|
Entity $boss_id = NONE;
|
||||||
components::BossFight& $scene;
|
components::AnimatedScene $scene;
|
||||||
gui::CombatUI $combat_ui;
|
gui::CombatUI $combat_ui;
|
||||||
SpriteTexture $boss_sprite;
|
SpriteTexture $boss_sprite;
|
||||||
SpriteTexture $player_sprite;
|
SpriteTexture $player_sprite;
|
||||||
|
|
@ -44,10 +44,9 @@ namespace boss {
|
||||||
void init();
|
void init();
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||||
void position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
sf::Vector2f position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
||||||
void status(const std::wstring& msg);
|
void status(const std::wstring& msg);
|
||||||
void move_boss(const std::string& cell_name);
|
sf::Vector2f move_actor(SpriteTexture& st, const std::string& actor, const std::string& cell_name);
|
||||||
void move_player(const std::string& cell_name);
|
|
||||||
void play_animations();
|
void play_animations();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace components {
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
if(!MAP_configured) {
|
if(!MAP_configured) {
|
||||||
components::enroll<BossFight>(MAP);
|
components::enroll<AnimatedScene>(MAP);
|
||||||
components::enroll<Combat>(MAP);
|
components::enroll<Combat>(MAP);
|
||||||
components::enroll<Position>(MAP);
|
components::enroll<Position>(MAP);
|
||||||
components::enroll<Curative>(MAP);
|
components::enroll<Curative>(MAP);
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,11 @@ namespace components {
|
||||||
float scale;
|
float scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BossFight {
|
struct AnimatedScene {
|
||||||
std::string background;
|
std::string background;
|
||||||
std::optional<std::string> floor;
|
std::optional<std::string> floor;
|
||||||
std::string floor_pos;
|
std::string floor_pos;
|
||||||
json player;
|
json actors;
|
||||||
json boss;
|
|
||||||
json fixtures;
|
json fixtures;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -152,7 +151,7 @@ namespace components {
|
||||||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||||
|
|
||||||
ENROLL_COMPONENT(Tile, display, foreground, background);
|
ENROLL_COMPONENT(Tile, display, foreground, background);
|
||||||
ENROLL_COMPONENT(BossFight, background, floor, floor_pos, player, boss, fixtures);
|
ENROLL_COMPONENT(AnimatedScene, background, floor, floor_pos, actors, fixtures);
|
||||||
ENROLL_COMPONENT(Sprite, name, scale);
|
ENROLL_COMPONENT(Sprite, name, scale);
|
||||||
ENROLL_COMPONENT(Curative, hp);
|
ENROLL_COMPONENT(Curative, hp);
|
||||||
ENROLL_COMPONENT(LightSource, strength, radius);
|
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ TEST_CASE("make sure json_mods works", "[components]") {
|
||||||
// this confirms that loading something with an optional
|
// this confirms that loading something with an optional
|
||||||
// field works with the json conversions in json_mods.hpp
|
// field works with the json conversions in json_mods.hpp
|
||||||
for(auto& comp_data : config["RAT_KING"]["components"]) {
|
for(auto& comp_data : config["RAT_KING"]["components"]) {
|
||||||
if(comp_data["_type"] == "BossFight") {
|
if(comp_data["_type"] == "AnimatedScene") {
|
||||||
auto comp = components::convert<components::BossFight>(comp_data);
|
auto comp = components::convert<components::AnimatedScene>(comp_data);
|
||||||
// the boss fight for the rat king doesn't have a stage so false=optional
|
// the boss fight for the rat king doesn't have a stage so false=optional
|
||||||
REQUIRE(comp.floor == std::nullopt);
|
REQUIRE(comp.floor == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +50,6 @@ TEST_CASE("make sure json_mods works", "[components]") {
|
||||||
|
|
||||||
components::configure_entity(world, rat_king, config["RAT_KING"]["components"]);
|
components::configure_entity(world, rat_king, config["RAT_KING"]["components"]);
|
||||||
|
|
||||||
auto boss = world.get<BossFight>(rat_king);
|
auto boss = world.get<AnimatedScene>(rat_king);
|
||||||
REQUIRE(boss.floor == std::nullopt);
|
REQUIRE(boss.floor == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ int main(int, char*[]) {
|
||||||
|
|
||||||
gui::routing::Router router;
|
gui::routing::Router router;
|
||||||
|
|
||||||
sound::mute(false);
|
sound::mute(true);
|
||||||
sound::play("ambient_1", true);
|
sound::play("ambient_1", true);
|
||||||
|
|
||||||
GameDB::create_level();
|
GameDB::create_level();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue