123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #include "Fenetre.h"
- Fenetre::Fenetre(): m_ecran(0), m_vies(0), typeCo(LOCAL), m_ogre(&m_input, &m_terrain), m_menestrel(&m_input, &m_terrain)
- {
- if(init())
- {
- std::string nomNiveau;
- while((nomNiveau = menu(m_ecran)) != "quitter")
- {
- if(!chargerNiveau(nomNiveau))
- break;
- if(typeCo == LOCAL)
- jeulocal();
- if(typeCo == HOST)
- jeuhost();
- if(typeCo == CLIENT)
- jeuclient();
- if(!m_input.continuer())
- break;
- }
- }
- }
- Fenetre::~Fenetre()
- {
- SDL_FreeSurface(m_ecran);
- SDL_FreeSurface(m_vies);
- SDL_FreeSurface(m_grosBourin);
- SDL_Quit();
- TTF_Quit();
- }
- bool Fenetre::init()
- {
- m_vies = IMG_Load("Skins/vie.png");
- if(m_vies == 0)
- {
- std::cout << "Chargement de l'image vie impossible" << std::endl;
- return false;
- }
- m_grosBourin = IMG_Load("Skins/grosBourin.png");
- if(m_grosBourin == 0)
- {
- std::cout << "Chargement de l'image grosBourin impossible" << std::endl;
- return false;
- }
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1 || TTF_Init() == -1)
- {
- std::cout << "Initialisation de la SDL impossible" << std::endl;
- SDL_Quit();
- TTF_Quit();
- return false;
- }
- SDL_WM_SetCaption("PacMen", 0);
- m_ecran = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
- if(m_ecran == 0)
- {
- std::cout << "Creation de l'ecran impossible" << std::endl;
- SDL_Quit();
- TTF_Quit();
- return false;
- }
- return true;
- }
- void Fenetre::jeulocal()
- {
- int vie = 3;
- Uint32 tempsprecedent = SDL_GetTicks();
- SDL_Rect pos;
- m_input.reset();
- while(m_terrain.itemsRestants()!=0)
- {
- m_input.updateEvenement();
- if(m_input.getTouches(SDLK_ESCAPE) || !m_input.continuer())
- {
- std::cout << "quitter niveau" << std::endl;
- return;
- }
- m_terrain.afficher(m_ecran);
- m_ogre.deplacer();
- m_menestrel.deplacer();
- for(unsigned int i = 0;i<m_fantomes.size();i++)
- m_fantomes[i]->deplacer();
- for(unsigned int i = 0;i<m_fantomes.size();i++)
- {
- if(m_ogre.getPosition() == m_fantomes[i]->getPosition() && m_fantomes[i]->vivant())
- {
- if(m_ogre.getBerzerk())
- {
- m_fantomes[i]->positionner(m_posFantomes);
- m_fantomes[i]->tuer();
- }
- else
- {
- for(unsigned int i = 0;i<m_fantomes.size();i++)
- m_fantomes[i]->positionner(m_posFantomes);
- m_menestrel.positionner(m_posPersos);
- m_ogre.positionner(m_posPersos);
- vie--;
- }
- }
- if(m_menestrel.getPosition() == m_fantomes[i]->getPosition() && m_fantomes[i]->vivant())
- {
- for(unsigned int i = 0;i<m_fantomes.size();i++)
- m_fantomes[i]->positionner(m_posFantomes);
- m_ogre.positionner(m_posPersos);
- m_menestrel.positionner(m_posPersos);
- vie--;
- }
- }
- m_ogre.afficher(m_ecran);
- m_menestrel.afficher(m_ecran);
- for(unsigned int i = 0;i<m_fantomes.size();i++)
- m_fantomes[i]->afficher(m_ecran);
- pos.y = 0;
- for(int i = 0;i<vie;i++)
- {
- pos.x = i*30;
- SDL_BlitSurface(m_vies, 0, m_ecran, &pos);
- }
- if(m_fantomes[0]->getMultiKill(m_fantomes.size()))
- {
- vie++;
- pos.x = 44;
- pos.y = 247;
- SDL_BlitSurface(m_grosBourin, 0, m_ecran, &pos);
- SDL_Flip(m_ecran);
- SDL_Delay(2000);
- }
- if(vie <= 0)
- {
- std::cout << "mort" << std::endl;
- return;
- }
- SDL_Flip(m_ecran);
- while((SDL_GetTicks()-tempsprecedent)<1000/60);
- tempsprecedent = SDL_GetTicks();
- }
- std::cout << "plus de steaks" << std::endl;
- }
- void Fenetre::jeuhost()
- {
- }
- void Fenetre::jeuclient()
- {
- }
- bool Fenetre::chargerNiveau(std::string nomNiveau)
- {
- viderFantomes();
- if(!m_terrain.creer(nomNiveau))
- return false;
- m_posPersos.x = m_terrain.popAllie(X);
- m_posPersos.y = m_terrain.popAllie(Y);
- m_posFantomes.x = m_terrain.popFantom(X);
- m_posFantomes.y = m_terrain.popFantom(Y);
- m_ogre.positionner(m_posPersos);
- m_menestrel.positionner(m_posPersos);
- for(int i = 0;i<m_terrain.getEffectifMobs();i++)
- {
- m_fantomes.push_back(new Fantome(&m_terrain, &m_ogre, &m_menestrel));
- m_fantomes[i]->positionner(m_posFantomes);
- }
- return true;
- }
- void Fenetre::viderFantomes()
- {
- for(unsigned int i = 0;i<m_fantomes.size();i++)
- delete m_fantomes[i];
- m_fantomes.clear();
- }
|