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

Introduce a new entity type

parent 747d8d65
......@@ -2,6 +2,7 @@
#include <gui/camera/camera.hpp>
#include <gui/screen/screen.hpp>
#include <gui/sprites/pic_sprite.hpp>
#include <gui/sprites/tourbillon_sprite.hpp>
#include <gui/sprites/bullet_sprite.hpp>
#include <gui/sprites/emp_sprite.hpp>
#include <world/world.hpp>
......@@ -730,6 +731,9 @@ void Camera::on_new_entity(const Entity* entity)
this->sprites.push_back(std::make_unique<BulletSprite>(entity));
else if (entity->get_type() == 2)
this->sprites.push_back(std::make_unique<EmpSprite>(entity));
else if (entity->get_type() == 4)
this->sprites.push_back(std::make_unique<TourbillonSprite>(entity));
}
void Camera::on_entity_deleted(const Entity* entity)
......
#include <gui/sprites/tourbillon_sprite.hpp>
#include <logging/logging.hpp>
#include <gui/camera/camera.hpp>
#include <game/game_client.hpp>
#include <world/health.hpp>
#include <world/manapool.hpp>
#include <world/team.hpp>
#include <world/location.hpp>
TourbillonSprite::TourbillonSprite(const Entity* const entity):
EntitySprite(entity)
{
if (TourbillonSprite::init == false)
{
if (!TourbillonSprite::body_texture.loadFromFile("data/images/units/tourbillon.png"))
exit(1);
TourbillonSprite::body_texture.setSmooth(true);
TourbillonSprite::init = true;
}
}
void TourbillonSprite::draw(GameClient* game) const
{
Team* team = this->entity->get<Team>();
assert(team);
Location* location = this->entity->get<Location>();
assert(location);
this->draw_shadow(game->get_camera(), this->team_colors[team->get()]);
const auto entpos = game->get_camera().world_to_camera_position(location->position());
const float x = entpos.x - game->get_camera().x;
const float y = entpos.y - game->get_camera().y;
sf::Sprite sprite(TourbillonSprite::body_texture);
const sf::Vector2u size = TourbillonSprite::body_texture.getSize();
sprite.setPosition(x - size.x/2, y - size.y);
game->get_camera().draw(sprite);
EnergyBar bar = this->standard_health_bar;
Health* entity_health = entity->get<Health>();
if (entity_health)
{
game->get_debug_hud().add_debug_line("Entity health: " + std::to_string(entity_health->get()) + "/" +std::to_string(entity_health->get_max()));
game->get_camera().draw_energy_bar({x, y - 90}, bar, entity_health->get_max().to_int(), entity_health->get().to_int());
}
EnergyBar mana_bar = this->standard_mana_bar;
ManaPool* entity_mana = entity->get<ManaPool>();
if (entity_mana)
{
game->get_debug_hud().add_debug_line("Entity mana: " + std::to_string(entity_mana->get()) + "/" +std::to_string(entity_mana->get_max()));
game->get_camera().draw_energy_bar({x, y - 80}, mana_bar, entity_mana->get_max().to_int(), entity_mana->get().to_int());
}
}
void TourbillonSprite::tick()
{
}
bool TourbillonSprite::init = false;
sf::Texture TourbillonSprite::body_texture;
#ifndef TOURBILLON_SPRITE_HPP_INCLUDED
#define TOURBILLON_SPRITE_HPP_INCLUDED
#include <gui/sprites/entity_sprite.hpp>
class TourbillonSprite: public EntitySprite
{
public:
TourbillonSprite(const Entity* const);
void draw(GameClient* game) const override final;
void tick() override final;
~TourbillonSprite() = default;
private:
static bool init;
static sf::Texture body_texture;
TourbillonSprite(const TourbillonSprite&) = delete;
TourbillonSprite(TourbillonSprite&&) = delete;
TourbillonSprite& operator=(const TourbillonSprite&) = delete;
TourbillonSprite& operator=(TourbillonSprite&&) = delete;
};
#endif /* TOURBILLON_SPRITE_HPP_INCLUDED */
......@@ -32,15 +32,15 @@ std::unique_ptr<Entity> EntityFactory::make_entity(const EntityType type)
if (type == 0)
{ // Default unit
entity->make_manipulable();
entity->add_component(std::make_unique<Health>(200));
entity->add_component(std::make_unique<Health>(50));
entity->add_component(std::make_unique<ManaPool>(300));
entity->add_component(std::make_unique<Vision>(700, false));
entity->add_component(std::make_unique<Location>(20, true));
entity->add_component(std::make_unique<Team>());
entity->add_component(std::make_unique<Mobility>(3.8_fix));
entity->add_component(std::make_unique<Mobility>(3.5_fix));
auto abilities = std::make_unique<Abilities>(6u, 0u, 0u);
abilities->add(0, std::make_unique<Attack>(300ms, 500ms, 400_fix));
abilities->add(0, std::make_unique<Attack>(300ms, 500ms, 0_fix));
abilities->add(1, std::make_unique<Blink>());
abilities->add(2, std::make_unique<Phase>());
abilities->add(3, std::make_unique<Emp>());
......@@ -60,5 +60,25 @@ std::unique_ptr<Entity> EntityFactory::make_entity(const EntityType type)
entity->add_component(std::make_unique<Location>(0, false));
entity->add_component(std::make_unique<Team>());
}
else if (type == 4)
{
entity->make_manipulable();
entity->add_component(std::make_unique<Health>(40));
entity->add_component(std::make_unique<ManaPool>(300));
entity->add_component(std::make_unique<Vision>(700, false));
entity->add_component(std::make_unique<Location>(20, true));
entity->add_component(std::make_unique<Team>());
entity->add_component(std::make_unique<Mobility>(4.8_fix));
auto abilities = std::make_unique<Abilities>(6u, 0u, 0u);
abilities->add(0, std::make_unique<Attack>(300ms, 500ms, 200_fix));
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>(500, 50));
abilities->add(5, std::make_unique<Concentrate>());
entity->add_component(std::move(abilities));
}
return entity;
}
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