Player's aim is now updated constantly as they move, just need to solve #57 to complete it. Closes #9.

master
Zed A. Shaw 23 hours ago
parent 584c4e9f67
commit a26f0b0c0a
  1. 4
      Makefile
  2. 3
      components.hpp
  3. 18
      gui/fsm.cpp
  4. 28
      gui/main_ui.cpp
  5. 5
      gui/main_ui.hpp
  6. 14
      systems.cpp
  7. 3
      systems.hpp

@ -34,7 +34,7 @@ tracy_build:
meson compile -j 10 -C builddir meson compile -j 10 -C builddir
test: build test: build
./builddir/runtests "[inventory]" ./builddir/runtests
run: build test run: build test
ifeq '$(OS)' 'Windows_NT' ifeq '$(OS)' 'Windows_NT'
@ -57,7 +57,7 @@ clean:
meson compile --clean -C builddir meson compile --clean -C builddir
debug_test: build debug_test: build
gdb --nx -x .gdbinit --ex run --args builddir/runtests -e "[inventory]" gdb --nx -x .gdbinit --ex run --args builddir/runtests -e
win_installer: win_installer:
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'

@ -27,7 +27,8 @@ namespace components {
}; };
struct Position { struct Position {
Point location; Point location{0,0};
Point aiming_at{0,0};
}; };
struct Motion { struct Motion {

@ -101,14 +101,18 @@ namespace gui {
} }
} }
void FSM::ROTATING(Event ) { void FSM::ROTATING(Event) {
if($main_ui.play_rotate()) { if(auto aim = $main_ui.play_rotate()) {
auto& player_pos = System::player_position($level);
player_pos.aiming_at = *aim;
state(State::IDLE); state(State::IDLE);
} }
} }
void FSM::COMBAT_ROTATE(Event ) { void FSM::COMBAT_ROTATE(Event) {
if($main_ui.play_rotate()) { if(auto aim = $main_ui.play_rotate()) {
auto& player_pos = System::player_position($level);
player_pos.aiming_at = *aim;
state(State::IN_COMBAT); state(State::IN_COMBAT);
} }
} }
@ -132,6 +136,12 @@ namespace gui {
void FSM::IDLE(Event ev, std::any data) { void FSM::IDLE(Event ev, std::any data) {
using enum Event; using enum Event;
auto& player_pos = System::player_position($level);
fmt::println("AIMING AT: {},{}; POS: {},{}",
player_pos.aiming_at.x, player_pos.aiming_at.y,
player_pos.location.x, player_pos.location.y);
sound::stop("walk"); sound::stop("walk");
switch(ev) { switch(ev) {

@ -45,27 +45,26 @@ namespace gui {
$overlay_ui.render($window); $overlay_ui.render($window);
} }
void MainUI::health_low() {
$overlay_ui.show_sprite("middle", "blood_splatter");
}
lel::Cell MainUI::overlay_cell(const std::string& name) { lel::Cell MainUI::overlay_cell(const std::string& name) {
return $overlay_ui.$gui.cell_for(name); return $overlay_ui.$gui.cell_for(name);
} }
bool MainUI::play_rotate() { std::optional<Point> MainUI::play_rotate() {
bool done = $rayview.play_rotate(); if($rayview.play_rotate()) {
$needs_render = !done; $needs_render = false;
return std::make_optional<Point>($rayview.aiming_at);
return done; } else {
$needs_render = true;
return std::nullopt;
}
} }
std::optional<Point> MainUI::play_move() { std::optional<components::Position> MainUI::play_move() {
if($rayview.play_move()) { if($rayview.play_move()) {
$needs_render = false; $needs_render = false;
return std::make_optional<Point>( return std::make_optional<Position>(
$rayview.camera_target()); $rayview.camera_target(),
$rayview.aiming_at);
} else { } else {
$needs_render = true; $needs_render = true;
return std::nullopt; return std::nullopt;
@ -104,6 +103,9 @@ namespace gui {
$rayview.update_level($level); $rayview.update_level($level);
$rayview.position_camera(player.x + 0.5, player.y + 0.5); $rayview.position_camera(player.x + 0.5, player.y + 0.5);
// BUG #57: I think this is in the wrong direction?
player_position.aiming_at = $rayview.aiming_at;
$compass_dir = 0; $compass_dir = 0;
$overlay_ui.update_level(level); $overlay_ui.update_level(level);

@ -28,8 +28,8 @@ namespace gui {
void render_debug(); void render_debug();
void plan_rotate(int dir, float amount); void plan_rotate(int dir, float amount);
bool play_rotate(); std::optional<Point> play_rotate();
std::optional<Point> play_move(); std::optional<components::Position> play_move();
Point plan_move(int dir, bool strafe); Point plan_move(int dir, bool strafe);
void abort_plan(); void abort_plan();
void update_level(GameLevel level); void update_level(GameLevel level);
@ -40,7 +40,6 @@ namespace gui {
void dirty(); void dirty();
lel::Cell overlay_cell(const std::string& name); lel::Cell overlay_cell(const std::string& name);
void health_low();
void dead_entity(DinkyECS::Entity entity); void dead_entity(DinkyECS::Entity entity);
}; };
} }

@ -396,12 +396,15 @@ void System::device(World &world, Entity actor, Entity item) {
} }
} }
void System::plan_motion(World& world, Point move_to) { void System::plan_motion(World& world, Position move_to) {
auto& player = world.get_the<Player>(); auto& player = world.get_the<Player>();
auto& player_position = world.get<Position>(player.entity); auto& player_position = world.get<Position>(player.entity);
player_position.aiming_at = move_to.aiming_at;
auto& motion = world.get<Motion>(player.entity); auto& motion = world.get<Motion>(player.entity);
motion.dx = move_to.x - player_position.location.x; motion.dx = move_to.location.x - player_position.location.x;
motion.dy = move_to.y - player_position.location.y; motion.dy = move_to.location.y - player_position.location.y;
} }
/* /*
@ -554,3 +557,8 @@ void System::remove_from_container(World& world, Entity cont_id, const std::stri
auto entity = container.get(slot_id); auto entity = container.get(slot_id);
container.remove(entity); container.remove(entity);
} }
Position& System::player_position(GameLevel& level) {
auto& player = level.world->get_the<components::Player>();
return level.world->get<components::Position>(player.entity);
}

@ -18,7 +18,7 @@ namespace System {
void init_positions(World &world, SpatialMap &collider); void init_positions(World &world, SpatialMap &collider);
void device(World &world, Entity actor, Entity item); void device(World &world, Entity actor, Entity item);
void plan_motion(World& world, Point move_to); void plan_motion(World& world, Position move_to);
std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir); std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir);
Entity spawn_item(World& world, const string& name); Entity spawn_item(World& world, const string& name);
bool drop_item(GameLevel& level, Entity item); bool drop_item(GameLevel& level, Entity item);
@ -36,4 +36,5 @@ namespace System {
void remove_from_container(World& world, Entity cont_id, const std::string& name); void remove_from_container(World& world, Entity cont_id, const std::string& name);
void remove_from_world(GameLevel &level, Entity entity); void remove_from_world(GameLevel &level, Entity entity);
Position& player_position(GameLevel& level);
} }

Loading…
Cancel
Save