Commit 7f609494 authored by louiz’'s avatar louiz’

Draw the dash load and destination indicators

Also cap the dash damage to a value
parent ee5c6c67
......@@ -450,6 +450,14 @@ void Camera::fixup_camera_position()
this->y = this->map().get_height_in_pixels() - win_size.y;
}
sf::Vector2i Camera::world_to_screen_position(const Position& pos) const
{
auto res = this->world_to_camera_position(pos);
res.x -= this->x;
res.y -= this->y;
return res;
}
sf::Vector2i Camera::world_to_camera_position(const Position& pos) const
{
sf::Vector2i res;
......
......@@ -96,6 +96,7 @@ public:
*/
void center(const sf::Vector2i& center);
sf::Vector2i world_to_camera_position(const Position&) const;
sf::Vector2i world_to_screen_position(const Position&) const;
/**
* Convert a mouse position, screen-related, into a world position
*/
......
#include <gui/dash_cursor.hpp>
#include <world/entity.hpp>
#include <game/game_client.hpp>
#include <gui/hud/abilities_panel.hpp>
#include <world/abilities.hpp>
#include <world/location.hpp>
#include <world/abilities/dash.hpp>
#include <world/works/concentrate_work.hpp>
#include <algorithm>
#include <logging/logging.hpp>
cursor::type draw_dash_concentrate_cursor(const sf::Vector2i& mouse_position, GameClient* game)
{
log_debug("dash cursor position: " << mouse_position.x << "." << mouse_position.y);
auto ids = get_selected_entities_with_ability<Dash>(game);
assert(!ids.empty());
Entity* dashing_entity = game->get_world().get_entity_by_id(ids[0]);
auto abilities = dashing_entity->get<Abilities>();
auto dash = static_cast<Dash*>(abilities->find(AbilityType::Dash));
assert(dash);
const Position world_pos = game->get_camera().screen_to_world_position(
mouse_position.x, mouse_position.y);
Location* location = dashing_entity->get<Location>();
assert(location);
// Draw a circle at the potential destination
Vec2 dash_vector = world_pos - location->position();
if (dash_vector.length() > dash->get_max_distance())
dash_vector.set_length(dash->get_max_distance());
Position destination = location->position() + dash_vector;
auto radius = 30;
sf::CircleShape destination_circle(radius);
destination_circle.setOrigin(radius, radius);
destination_circle.setFillColor({255, 0, 0, 200});
destination_circle.scale(1.f, 0.666f);
auto screen_pos = game->get_camera().world_to_screen_position(destination);
destination_circle.setPosition(screen_pos.x, screen_pos.y);
game->get_camera().draw(destination_circle);
// draw a load bar next to the cursor
EnergyBar bar{{255, 0, 255},
{255, 255, 0},
{100, 10},
2, 0};
int current_val = 0;
auto concentrate = dynamic_cast<ConcentrateWork*>(dashing_entity->get_current_work());
if (concentrate)
{
auto task = static_cast<ConcentrateTask*>(concentrate->get_task());
if (task)
current_val = std::min(task->value().to_int(), dash->get_max_concentration().to_int());
}
game->get_camera().draw_energy_bar(
{static_cast<float>(mouse_position.x - 8),
static_cast<float>(mouse_position.y - 75)},
bar, dash->get_max_concentration().to_int(), current_val);
return cursor::Build;
}
#ifndef DASH_CURSOR_HPP_INCLUDED
#define DASH_CURSOR_HPP_INCLUDED
#include <SFML/Graphics.hpp>
#include <gui/cursor.hpp>
#include <world/entity.hpp>
class GameClient;
cursor::type draw_dash_concentrate_cursor(const sf::Vector2i& mouse_position,
GameClient* game);
#endif /* DASH_CURSOR_HPP_INCLUDED */
......@@ -12,6 +12,8 @@
#include <world/abilities/emp.hpp>
#include <world/abilities/dash.hpp>
#include <gui/dash_cursor.hpp>
#include <utility>
AbilitiesPanel::AbilitiesPanel(GameClient* game)
......@@ -112,10 +114,9 @@ AbilitiesPanel::AbilitiesPanel(GameClient* game)
log_debug("left_click to start dashing");
return game->action_cast({ids[0]}, pos, AbilityType::Dash, false);
},
[](const sf::Vector2i&)
[game](const sf::Vector2i& mouse_pos)
{
// Draw the dash load thingy
return cursor::Cast;
return draw_dash_concentrate_cursor(mouse_pos, game);
}
};
}
......
......@@ -15,9 +15,10 @@ const std::string NamedAbility<Dash>::name = "Dash";
template <>
const AbilityType NamedAbility<Dash>::ability_type = AbilityType::Dash;
Dash::Dash(const Fix16 max_distance):
Dash::Dash(const Fix16 max_distance, const Fix16 max_concentration):
ActiveAbility(TargetType::Point),
max_distance(max_distance)
max_distance(max_distance),
max_concentration(max_concentration)
{
}
......@@ -33,12 +34,13 @@ void Dash::cast(Entity* entity, World* world, const Position& pos, const bool qu
return;
}
// Otherwise, use its value for the DashWork
Task* task = concentrate->get_task();
if (!task)
auto concentrate_task = static_cast<ConcentrateTask*>(concentrate->get_task());
if (!concentrate_task)
return;
auto concentrate_task = static_cast<ConcentrateTask*>(task);
auto concentrate_value = concentrate_task->value();
log_debug("The concentrate task value is: " << concentrate_value);
concentrate_value = std::min(concentrate_value, this->get_max_concentration());
log_debug("capped to " << concentrate_value);
Team* own_team = entity->get<Team>();
assert(own_team);
......@@ -53,9 +55,19 @@ void Dash::cast(Entity* entity, World* world, const Position& pos, const bool qu
if (!health)
return;
world->callbacks->impact(entity, impacted_entity);
health->add(-concentrate_value/2);
health->add(-concentrate_value);
};
auto work = std::make_unique<DashWork>(entity, world, pos, 35, this->max_distance, 50,
on_impact, nullptr);
entity->set_work(std::move(work));
}
const Fix16 Dash::get_max_distance() const
{
return this->max_distance;
}
const Fix16 Dash::get_max_concentration() const
{
return this->max_concentration;
}
......@@ -7,13 +7,16 @@
class Dash: public ActiveAbility<Dash>
{
public:
Dash(const Fix16 max_distance);
Dash(const Fix16 max_distance, const Fix16 max_concentration);
~Dash() = default;
void cast(Entity* entity, World*, const Position& pos,
const bool queue) override final;
const Fix16 get_max_distance() const;
const Fix16 get_max_concentration() const;
private:
const Fix16 max_distance;
const Fix16 max_concentration;
Dash(const Dash&) = delete;
Dash(Dash&&) = delete;
......
......@@ -42,7 +42,7 @@ std::unique_ptr<Entity> EntityFactory::make_entity(const EntityType type)
abilities->add(1, std::make_unique<Blink>());
abilities->add(2, std::make_unique<Phase>());
abilities->add(3, std::make_unique<Emp>());
abilities->add(4, std::make_unique<Dash>(400));
abilities->add(4, std::make_unique<Dash>(400, 50));
abilities->add(5, std::make_unique<Concentrate>());
entity->add_component(std::move(abilities));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment