Player's aim is now updated constantly as they move, just need to solve #57 to complete it. Closes #9.
This commit is contained in:
parent
584c4e9f67
commit
a26f0b0c0a
7 changed files with 48 additions and 27 deletions
4
Makefile
4
Makefile
|
@ -34,7 +34,7 @@ tracy_build:
|
|||
meson compile -j 10 -C builddir
|
||||
|
||||
test: build
|
||||
./builddir/runtests "[inventory]"
|
||||
./builddir/runtests
|
||||
|
||||
run: build test
|
||||
ifeq '$(OS)' 'Windows_NT'
|
||||
|
@ -57,7 +57,7 @@ clean:
|
|||
meson compile --clean -C builddir
|
||||
|
||||
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:
|
||||
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'
|
||||
|
|
|
@ -27,7 +27,8 @@ namespace components {
|
|||
};
|
||||
|
||||
struct Position {
|
||||
Point location;
|
||||
Point location{0,0};
|
||||
Point aiming_at{0,0};
|
||||
};
|
||||
|
||||
struct Motion {
|
||||
|
|
14
gui/fsm.cpp
14
gui/fsm.cpp
|
@ -102,13 +102,17 @@ namespace gui {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +136,12 @@ namespace gui {
|
|||
void FSM::IDLE(Event ev, std::any data) {
|
||||
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");
|
||||
|
||||
switch(ev) {
|
||||
|
|
|
@ -45,27 +45,26 @@ namespace gui {
|
|||
$overlay_ui.render($window);
|
||||
}
|
||||
|
||||
void MainUI::health_low() {
|
||||
$overlay_ui.show_sprite("middle", "blood_splatter");
|
||||
}
|
||||
|
||||
|
||||
lel::Cell MainUI::overlay_cell(const std::string& name) {
|
||||
return $overlay_ui.$gui.cell_for(name);
|
||||
}
|
||||
|
||||
bool MainUI::play_rotate() {
|
||||
bool done = $rayview.play_rotate();
|
||||
$needs_render = !done;
|
||||
|
||||
return done;
|
||||
std::optional<Point> MainUI::play_rotate() {
|
||||
if($rayview.play_rotate()) {
|
||||
$needs_render = false;
|
||||
return std::make_optional<Point>($rayview.aiming_at);
|
||||
} else {
|
||||
$needs_render = true;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Point> MainUI::play_move() {
|
||||
std::optional<components::Position> MainUI::play_move() {
|
||||
if($rayview.play_move()) {
|
||||
$needs_render = false;
|
||||
return std::make_optional<Point>(
|
||||
$rayview.camera_target());
|
||||
return std::make_optional<Position>(
|
||||
$rayview.camera_target(),
|
||||
$rayview.aiming_at);
|
||||
} else {
|
||||
$needs_render = true;
|
||||
return std::nullopt;
|
||||
|
@ -104,6 +103,9 @@ namespace gui {
|
|||
$rayview.update_level($level);
|
||||
$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;
|
||||
|
||||
$overlay_ui.update_level(level);
|
||||
|
|
|
@ -28,8 +28,8 @@ namespace gui {
|
|||
void render_debug();
|
||||
|
||||
void plan_rotate(int dir, float amount);
|
||||
bool play_rotate();
|
||||
std::optional<Point> play_move();
|
||||
std::optional<Point> play_rotate();
|
||||
std::optional<components::Position> play_move();
|
||||
Point plan_move(int dir, bool strafe);
|
||||
void abort_plan();
|
||||
void update_level(GameLevel level);
|
||||
|
@ -40,7 +40,6 @@ namespace gui {
|
|||
void dirty();
|
||||
lel::Cell overlay_cell(const std::string& name);
|
||||
|
||||
void health_low();
|
||||
void dead_entity(DinkyECS::Entity entity);
|
||||
};
|
||||
}
|
||||
|
|
14
systems.cpp
14
systems.cpp
|
@ -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_position = world.get<Position>(player.entity);
|
||||
|
||||
player_position.aiming_at = move_to.aiming_at;
|
||||
|
||||
auto& motion = world.get<Motion>(player.entity);
|
||||
motion.dx = move_to.x - player_position.location.x;
|
||||
motion.dy = move_to.y - player_position.location.y;
|
||||
motion.dx = move_to.location.x - player_position.location.x;
|
||||
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);
|
||||
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 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);
|
||||
Entity spawn_item(World& world, const string& name);
|
||||
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_world(GameLevel &level, Entity entity);
|
||||
Position& player_position(GameLevel& level);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue