Skip to content

Commit

Permalink
the hero can talk to other characters
Browse files Browse the repository at this point in the history
  • Loading branch information
jube committed Oct 6, 2024
1 parent 89bbb8c commit e2de9b6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
40 changes: 39 additions & 1 deletion code/bits/WorldTravelScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

#include "Akagoria.h"
#include "HeroState.h"
#include "gf2/graphics/Scene.h"

namespace akgr {

namespace {

constexpr gf::Vec2F WorldTravelSceneWorldSize = { 1600, 900 };

constexpr float DialogDistance = 100.0f;

}

WorldTravelScene::WorldTravelScene(Akagoria* game, const WorldResources& resources)
Expand All @@ -34,6 +35,7 @@ namespace akgr {
settings.actions.emplace("down"_id, gf::continuous_action().add_scancode_control(gf::Scancode::Down));
settings.actions.emplace("left"_id, gf::continuous_action().add_scancode_control(gf::Scancode::Left));
settings.actions.emplace("right"_id, gf::continuous_action().add_scancode_control(gf::Scancode::Right));
settings.actions.emplace("operate"_id, gf::instantaneous_action().add_scancode_control(gf::Scancode::Return));

return settings;
}
Expand Down Expand Up @@ -76,6 +78,10 @@ namespace akgr {
hero.move.angular = gf::AngularMove::None;
}

if (m_action_group.active("operate"_id)) {
handle_hero_operation();
}

auto stick = m_motion_group.last_gamepad_stick_location(gf::GamepadStick::Left);

if (gf::square_length(stick) > gf::square(0.5f)) {
Expand All @@ -92,4 +98,36 @@ namespace akgr {
m_action_group.reset();
}

void WorldTravelScene::handle_hero_operation()
{
if (handle_hero_dialogs()) {
return;
}
}

bool WorldTravelScene::handle_hero_dialogs()
{
auto& hero = m_game->world_state()->hero;

for (auto& character : m_game->world_state()->characters) {
if (!character.dialog) {
continue;
}

if (character.spot.floor != hero.spot.floor) {
continue;
}

if (gf::square_distance(character.spot.location, hero.spot.location) < gf::square(DialogDistance)) {
hero.dialog.data = character.dialog;
hero.dialog.current_line = 0;
character.dialog.reset();
m_game->replace_scene(&m_game->world_act()->dialog_scene);
return true;
}
}

return false;
}

}
3 changes: 3 additions & 0 deletions code/bits/WorldTravelScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace akgr {
void do_process_event(const gf::Event& event) override;
void do_handle_actions() override;

void handle_hero_operation();
bool handle_hero_dialogs();

Akagoria* m_game = nullptr;

gf::ActionGroup m_action_group;
Expand Down

0 comments on commit e2de9b6

Please sign in to comment.