#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;ideplacer(); for(unsigned int i = 0;igetPosition() && m_fantomes[i]->vivant()) { if(m_ogre.getBerzerk()) { m_fantomes[i]->positionner(m_posFantomes); m_fantomes[i]->tuer(); } else { for(unsigned int i = 0;ipositionner(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;ipositionner(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;iafficher(m_ecran); pos.y = 0; for(int i = 0;igetMultiKill(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;ipositionner(m_posFantomes); } return true; } void Fenetre::viderFantomes() { for(unsigned int i = 0;i