Coverage report for gui


src/
File: src/render/scenes/world/Trantorian.hpp
Date: 2024-06-25 10:57:02
Lines:
0/38
0.0%
Functions:
0/6
0.0%
Branches:
0/32
0.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** zappy
4 ** File description:
5 ** Trantorien
6 */
7
8 #ifndef TRANTORIAN_HPP_
9 #define TRANTORIAN_HPP_
10
11 #include "../../sprites/Sprite.hpp"
12 #include "../../core/Setting.hpp"
13 #include "../../../utils/Lerp.hpp"
14 #include <iostream>
15
16 class Trantorian {
17 public:
18 Trantorian(sf::Vector2f tile, sf::Vector2f targetPos)
19 : _pos(targetPos), _tile(tile), _targetPos(targetPos)
20 {
21 _sprites.push_back(std::make_shared<Sprite>("./assets/trantorian_spawn.png", 12, 0.1f));
22 _sprites[0]->disableLooping();
23 _sprites.push_back(std::make_shared<Sprite>("./assets/trantorian_run.png", 6, 0.1f));
24 _sprites.push_back(std::make_shared<Sprite>("./assets/trantorian_death.png", 13, 0.1f));
25 _sprites[2]->disableLooping();
26 }
27 ~Trantorian() {
28 }
29
30 void update(float deltaTime) {
31 _pos = Lerp::lerp(_pos, _targetPos, 1.f * deltaTime);
32 _sprites[_actualSprite]->setPosition(_pos);
33 int ret = _sprites[_actualSprite]->update(deltaTime);
34 if (ret == 1 && _actualSprite == 0) {
35 _actualSprite = 1;
36 }
37 if (_dead == true)
38 _actualSprite = 2;
39 }
40 void draw(sf::RenderWindow &window) {
41 _sprites[_actualSprite]->draw(window);
42 }
43 void setTile(sf::Vector2f tile, sf::Vector2f targetPos) {
44 if ( tile != _tile) {
45 sf::Vector2f offset = sf::Vector2f(
46 Random::random(0, 26) - 13,
47 Random::random(0, 26) - 13
48 );
49 _targetPos = targetPos + offset;
50 float distance = sqrt(pow(_targetPos.x - _pos.x, 2) + pow(_targetPos.y - _pos.y, 2));
51 if (distance > 100) {
52 _pos = _targetPos;
53 }
54 }
55 _tile = tile;
56 }
57 sf::Vector2f getTile() { return _tile; }
58 void kill() { _dead = 1; }
59 bool isDead() {
60 if (_sprites[_actualSprite]->isFinished() && _actualSprite == 2)
61 return true;
62 return false;
63 }
64
65 sf::Vector2f getPos() { return _pos; }
66
67 int _id = 0;
68 std::string _team = "team";
69 int _teamIndex = 0;
70 int _level = 1;
71 int _facing = 0;
72
73 std::vector<int> _inventory = {0, 0, 0, 0, 0, 0, 0};
74 protected:
75 private:
76 int _actualSprite = 0;
77 sf::Vector2f _pos;
78 std::vector<std::shared_ptr<Sprite>> _sprites;
79 sf::Vector2f _tile = sf::Vector2f(0, 0);
80 sf::Vector2f _targetPos = sf::Vector2f(0, 0);
81 bool _dead = false;
82 };
83
84 #endif /* !TRANTORIAN_HPP_ */
85