-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonnagesView.cpp
More file actions
107 lines (92 loc) · 2.71 KB
/
PersonnagesView.cpp
File metadata and controls
107 lines (92 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "PersonnagesView.h"
#include "Modeles.h"
#include "Monstre.h"
#include "Vues.h"
#include "Zone.h"
#include "Animation.h"
Animation* PersonnagesView::m_joueurAnimation = 00;
PersonnagesView::PersonnagesView() :
Vue(Vues::m_window)
{
}
PersonnagesView::~PersonnagesView()
{
for(Animation* anim : m_animations)
{
if(anim != 00)
{
delete anim;
anim = 00;
}
}
}
void PersonnagesView::init(Zone* zone)
{
if(m_joueurAnimation == 00)
{
m_joueurAnimation = new Animation(m_window, Modeles::m_joueur);
}
m_animations.push_back(m_joueurAnimation);
m_yOrderAnims.insert(std::pair<int, Animation*>(
Modeles::m_joueur.getPosition().getPositionY(),
m_joueurAnimation));
for(Monstre* monstre : zone->m_monstres)
{
m_animations.push_back(new Animation(m_window, *monstre));
m_yOrderAnims.insert(std::pair<int, Animation*>(
monstre->getPosition().getPositionY(),
m_animations.at(m_animations.size()-1)));
}
}
void PersonnagesView::update(sf::Time deltaTemps)
{
bool retirerMorts = (Modeles::m_phase==Modeles::PRET) && Modeles::m_nouvellePhase;
if(retirerMorts)
{
retirerMorts = false;
for(int i=m_animations.size()-1; i>=0; i--)
{
Animation* anim = m_animations.at(i);
if(!anim->m_personnage.getVivant())
{
delete anim;
m_animations.erase(m_animations.begin()+i);
retirerMorts = true;
}
}
}
bool deplacementPerso = Modeles::m_nouvellePhase &&
( (Modeles::m_phase==Modeles::ACTION_PJ) || (Modeles::m_phase==Modeles::ACTION_PNJ) );
if(retirerMorts || deplacementPerso)
{
//changement possible des yOrderAnims
//(on pourrait optimiser mieux, mais pas vraiment la peine)
//std::cout << "reordonnancement des anims des persos" << std::endl;
m_yOrderAnims.clear();
for(Animation* anim : m_animations)
{
Position p = anim->m_personnage.getPosition();
m_yOrderAnims.insert(std::pair<int, Animation*>(
p.getPositionY(),
anim));
}
}
for(Animation* anim : m_animations)
{
anim->update(deltaTemps);
}
}
void PersonnagesView::draw() const
{
//Personnage& joueur = Modeles::m_joueur;
//std::vector<Monstre*>& monstres = Modeles::m_monstres;
std::multimap<int, Animation*>::const_iterator it;
for(it=m_yOrderAnims.begin(); it!=m_yOrderAnims.end(); it++)
{
const Animation* anim = it->second;
anim->draw();
}
}
void PersonnagesView::drawPersonnage(const Personnage& personnage) const
{
}