Example #1
0
/**
 * \fn void actio(t_perso *perso)
 * \param perso Personnage du tableau de perso 
 * \brief Effectue une action pour un personnage 
 *
 */
void actio(t_perso *perso){
	if(perso->i_HP > 0){

		int PA_actuel = perso->i_PA, PM_actuel = perso->i_PM; /*Permet de ne pas modifier les statistiques du personnage*/
		do{
			afficher_map();
			affichage_perso(*perso);
			printf("%i PA, %i PM\n", PA_actuel, PM_actuel);
			printf("1 - Deplacement\n");
			printf("2 - Attaque\n");
			printf("3 - Passer\n");
			printf("4 - Sauvegarder\n");
			printf("5 - Menu Principal\n");
			scanf("%i", &action);
			switch(action){
				case 1:	deplacement(&PM_actuel);
					break;
				case 2: attaque(&PA_actuel);
					break;
				case 3: printf("Passage de tour\n");
					break;
				case 4: save();
					break;
				case 5: break;
			}
			perso_vivant();
		}while(action != 3 && action != 5 && !victoire());
	}
}
Example #2
0
void Unite::boucle(const Event& e)
{
	if(m_cible.isElem())
	{
		if(rangeOk())
		{	
			s_gestionnaire->moveElem(getId(), m_pos+((m_cible.getElem()->getPos()-m_pos)*0.1f*m_tmpAttaque));
		}
		
		if(rangeOk() && m_tmpAttaque <= 0)
		{
			attaque();
			m_tmpAttaque=1.0f;
		}
		else if(!rangeOk())
		{
			m_tmpPos += m_vitesse*s_gestionnaire->getElapsedTime();
			
			if(m_tmpPos >= 1.0f)
			{
				m_pos = m_cibleTmp.getPos();
				
				m_cibleTmp = Cible(s_gestionnaire->step(m_pos, m_cible.getElem()->getPos()));
				m_tmpPos = 0.0f;
			}
			
			s_gestionnaire->moveElem(getId(), m_pos+((m_cibleTmp.getPos()-m_pos)*m_tmpPos));
		}
	}
	else
	{
		m_tmpPos += m_vitesse*s_gestionnaire->getElapsedTime();
		
			
		if(m_tmpPos >= 1.0f)
		{
			m_pos = m_cibleTmp.getPos();
			
			m_cibleTmp = Cible(s_gestionnaire->step(m_pos, m_cible.getPos()));
			m_tmpPos = 0.0f;
		}
		
		s_gestionnaire->moveElem(getId(), m_pos+((m_cibleTmp.getPos()-m_pos)*m_tmpPos));
	}
	
	m_tmpAttaque -= s_gestionnaire->getElapsedTime();
	
	if(m_tmpAttaque <= 0.0f)
	{
		m_tmpAttaque = 0.0f;
	}
}
Example #3
0
void Projectile::draw(SDL_Surface* gpScreen) {
    if (id == 3 && (gpJeu->getJoueur()->getTypeAnim()==TOUCHE 
    || gpJeu->getJoueur()->getTypeAnim()==CHUTE)) vie = 0;
    if (id > 0 && vie) {
    
        int phg[2];
        phg[0] = gpJeu->getPhg(0);
        phg[1] = gpJeu->getPhg(1);
    
        // déplacement
        if (vie && !gpJeu->getStop() && vitesse) {
            for (int i=0; i<vitesse; i++) {
                if (etape == 1) {
                    switch (direction) {
                        case N : move(0,-1); break;
                        case S : move(0,1); break;
                        case O : move(-1,0); break;
                        case E : move(1,0); break;
                    }
                }else {
                    switch (direction) {
                        case S : move(0,-1); break;
                        case N : move(0,1); break;
                        case E : move(-1,0); break;
                        case O : move(1,0); break;
                    }
                }
                if (vie <= 0) break;
                if (hauteur==0 || (id>=21 && id<=26)) attaque();
            }
        }
    
        //dessin
        if (vie) {
            
            if ((hauteur==0 || (id>=21 && id<=26)) && !vitesse) attaque();
            
            SDL_Rect src;
            SDL_Rect dst;
    
            src.h = h;src.w = w;
            dst.x = x-phg[0];dst.y = y-phg[1];
            src.x=w*direction;src.y=h*anim;
        
            if ((id == 1 || id == 2) && anim > 3) src.y=h*(anim-2);
            if (id == 4) {
                src.y=8; if (anim < 22) src.x=0; else src.x=(anim-21)*16;
                if (id == 4 && anim == 30) src.y=0;
            }
            if (id == 5) src.x+=51;
            if (id == 6) src.x=34;
            if (id == 7) {src.y=0; if (anim<4) src.x=w*(anim%2); else src.x=32;}
            
            if (id == 8) {
                src.y = 0; dst.y = y - phg[1];
                src.x = 0; dst.x = x - phg[0]-anim*4-8;
                SDL_BlitSurface(image, &src, gpScreen, &dst);
                src.x = 16; dst.x = x - phg[0]+anim*4+8;
            }
            
            if (id >=9 && id <=12) {
                src.x=w*anim; src.y=h*(id-9);
            }
            
            if (id ==15 || id == 16) {src.x=w*anim; src.y=0;}
            
            if (id >=21 && id <=26) {
                if (!anim) { src.x=112; src.y=(id-21)*16;}
                if (anim==1) { src.x=64; src.y=74;}
                if (anim==2) { src.x=56; src.y=90;}
                if (anim>2) { src.x=80; src.y=74;}
            }
            
            SDL_BlitSurface(image, &src, gpScreen, &dst);
            
            if (id == 3) dessinChaine(gpScreen);
            if (id == 6) dessinTrainee(gpScreen);
        
            //anim
            if(SDL_GetTicks() > lastAnimTime + vanim && !gpJeu->getStop()) {
                lastAnimTime = SDL_GetTicks();
                anim++;
                if (anim > max) {
                    anim = 0;
                    if ((id == 1 || id == 2 || id == 4 || id >= 7/* || id == 8*/) && max > 0) vie = 0;
                    if (id == 7 && gpJeu->getJoueur()->getTypeAnim()==LANTERNE) 
                        gpJeu->getJoueur()->setTypeAnim(AUCUNE);
                }
                if (id == 4 && anim == 30) {
                    w=32; h=32; zx=0; zy=0; zw=32; zh=32; x-=8; y-=8;
                    gpJeu->getAudio()->playSound(16);
                }
                if (id >= 21 && id <=26 && anim == 2) {
                    w=24; h=24; zx=0; zy=0; zw=24; zh=24; x-=4; y-=4;
                }
                if (id >= 21 && id <=26 && anim == 3) {
                    w=32; h=32; zx=0; zy=0; zw=32; zh=32; x-=4; y-=4;
                }
            }
        }
    }
    
    if (suivant != NULL) if (((Projectile*)suivant)->vie == 0){
		if(((Projectile*)suivant)->image) SDL_FreeSurface(((Projectile*)suivant)->image);
		((Projectile*)suivant)->image = 0;
		enleve(suivant);
	}
    if (suivant != NULL) ((Projectile*)suivant)->draw(gpScreen);
}
Example #4
0
void Projectile::draw(SDL_Surface* gpScreen) {
    if (id == 3 && (gpJeu->getJoueur()->getTypeAnim()==TOUCHE 
    || gpJeu->getJoueur()->getTypeAnim()==CHUTE)) vie = 0;
    if (id > 0 && vie) {
    
        int phg[2];
        phg[0] = gpJeu->getPhg(0);
        phg[1] = gpJeu->getPhg(1);
    
        // déplacement
        if (vie && !gpJeu->getStop() && vitesse) {
            for (int i=0; i<vitesse; i++) {
                if (etape == 1) {
                    switch (direction) {
                        case N : move(0,-1); break;
                        case S : move(0,1); break;
                        case O : move(-1,0); break;
                        case E : move(1,0); break;
                    }
                }else {
                    switch (direction) {
                        case S : move(0,-1); break;
                        case N : move(0,1); break;
                        case E : move(-1,0); break;
                        case O : move(1,0); break;
                    }
                }
                if (vie <= 0) break;
                if (hauteur==0 || (id>=21 && id<=27)) attaque();
            }
        }
    
        //dessin
        if (vie) {
            
            if ((hauteur==0 || ((id>=21 && id<=29) || id==130)) && !vitesse) attaque();
            
            SDL_Rect src;
            SDL_Rect dst;
    
            src.h = h;src.w = w;
            dst.x = x-phg[0];dst.y = y-phg[1];
            src.x=w*direction;src.y=h*anim;
        
            if ((id == 1 || id == 2) && anim > 3) src.y=h*(anim-2);
            if (id == 4 || id == 140) {
                if (id == 140) anim=30;
                src.y=8; if (anim < 22) src.x=0; else src.x=(anim-21)*16;
                if (anim == 30) src.y=0;
                if (id == 140) anim=0;
            }
            if (id == 5) src.x+=51;
            if (id == 6) src.x=34;
            if (id == 7) {src.y=0; if (anim<4) src.x=w*(anim%2); else src.x=32;}
            
            if (id == 8) {
                src.y = 0; dst.y = y - phg[1];
                src.x = 0; dst.x = x - phg[0]-anim*4-8;
                SDL_BlitSurface(image, &src, gpScreen, &dst);
                src.x = 16; dst.x = x - phg[0]+anim*4+8;
            }
            
            if (id >=9 && id <=12) {
                src.x=w*anim; src.y=h*(id-9);
            }
            
            if (id==19 && !gpJeu->getJoueur()->getGel() && max<2) {anim=1; max=2;}
            
            if (id ==15 || id == 16 || id == 17 || id == 19 || id == 20 
            || id == 40 || id == 41) {src.x=w*anim; src.y=0;}
            
            if (id == 41 && max == 1) src.x+=96;
            
            if ((id >=21 && id <=29) || id==130) {
                if (!anim) {
                    src.x=112; src.y=(id-21)*16; 
                    if (id==29)src.y-=16;
                    if (id==130) {src.x=96; src.y=112;}
                }
                if (anim==1) { src.x=64; src.y=74;}
                if (anim==2) { src.x=56; src.y=90;}
                if (anim>2) { src.x=80; src.y=74;}
            }
            
            if (id == 42) {src.x=0; src.y=0; src.w=24; src.h=26;}
            
            SDL_BlitSurface(image, &src, gpScreen, &dst);
            
            if (id == 3) dessinChaine(gpScreen);
            if (id == 6) dessinTrainee(gpScreen);
        
            //anim
            if(SDL_GetTicks() > lastAnimTime + vanim && !gpJeu->getStop()) {
                lastAnimTime = SDL_GetTicks();
                anim++;
                if (anim > max) {
                    anim = 0;
                    if ((id == 1 || id == 2 || id == 4 || (id >= 7 && id <40) 
                    || id == 19 || id == 130 || id == 140) && (max > 0 || id == 140)) {
                        vie = 0;
                        //anim Ganondorf se relève
                        if (id == 15 && gpJeu->getZone() == 57 && gpJeu->getJoueur()->getEnnemi(50) 
                        && gpJeu->getMonde()->regionValue(0)==160*16 
                        && gpJeu->getMonde()->regionValue(1)==15*16
                        && y < 20*16) {
                            Ennemi* enn = gpJeu->getEnnemi()->getSuivant();
                            while (enn != NULL) {
                                if (enn->getEnnId() == 89) enn->releve();
                                enn = enn->getSuivant();
                            }
                            gpJeu->ecrit(1098);
                        }
                    }
                    if (id == 7 && gpJeu->getJoueur()->getTypeAnim()==LANTERNE) 
                        gpJeu->getJoueur()->setTypeAnim(AUCUNE);
                    if (id == 41) {max=1; vanim=480;}
                }
                if (id == 4 && anim == 30) {
                    w=32; h=32; zx=0; zy=0; zw=32; zh=32; x-=8; y-=8;
                    gpJeu->getAudio()->playSound(16);
                }
                if (((id >= 21 && id <=29) || id==130) && anim == 2) {
                    w=24; h=24; zx=0; zy=0; zw=24; zh=24; x-=4; y-=4;
                }
                if (((id >= 21 && id <=29) || id==130) && anim == 3) {
                    w=32; h=32; zx=0; zy=0; zw=32; zh=32; x-=4; y-=4;
                }
            }
        }
    }
    
    
    
    if (suivant != NULL) if (((Projectile*)suivant)->vie == 0) enleve(suivant);
    if (suivant != NULL) ((Projectile*)suivant)->draw(gpScreen);
}