Gérer un combat dans un jeu 2d / algorithme primaire d'une ia (en plusieurs maj)

Contenu du snippet

Je reviens après un blanc pour poster quelques fonctions (3) qui m'ont permissent de créer un système de combat "marchant" ^^

Alors c'est fait en langage C (comme tout les trucs que je fais :p ),j'utilise la bibliothèque SDL et un piti peu de logique ^^
C'est un système de combat 2D qui fonctionne mais qui est assez basique (il n'a été créé que pour l'intérêt d'un seul et unique jeu -|- )

En espérant donner un coup de pouce a certains...
PS: les fonctions viendront avec des "MAJ", car j'ai perdu les sources originales :(

Source / Exemple :


int combat(SDL_Surface* ecran)
{
	init();
	/*int degat_rais = Rais.force / 0.9;
int degat_edwin = Edwin.force / 0.2;
int degat_ellana = Ellana.force / 0.2;
int degat_ewilan = Ewilan.intelligence / 0.2;
SDL_Surface *sort = NULL;
SDL_Surface *attack_norm = NULL;
SDL_Surface *background_fight = NULL;
SDL_Surface *life = NULL;4
SDL_Surface *sort = NULL;
SDL_Surface *attack_norm = NULL;
SDL_Surface *background_fight = NULL;
SDL_Surface *life = NULL;
SDL_Surface *Edwin_fight = NULL, *Ewilan_fight = NULL, *Ellana_fight = NULL;

  • /
position.x = 0; position.y = 0; SDL_BlitSurface(background_fight,NULL,ecran,&position); position.x = 30; position.y = 20; SDL_BlitSurface(Edwin_fight,NULL,ecran,&position); position.y = 40; SDL_BlitSurface(Ellana_fight,NULL,ecran,&position); position.x = 10; position.y = 30; SDL_BlitSurface(Ewilan_fight,NULL,ecran,&position); position.x = 250; position.y = 20; SDL_BlitSurface(Rais_fight,NULL,ecran,&position); position.y = 40; SDL_BlitSurface(Rais_fight,NULL,ecran,&position); int tour_edwin = 1,tour_ewilan = 0,tour_ellana = 0,tour_rais = 0; int combat_pas_fini = 1; while(combat_pas_fini && Ewilan.life != 0 && Rais.life != 0) { if(tour_edwin == 1) { while(tour_edwin) { SDL_WaitEvent(&evenement); switch(evenement.type) { case SDL_KEYDOWN: switch(evenement.key.keysym.sym) { case SDLK_a: SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_mob(Edwin); break; } } } tour_edwin = 0; tour_ewilan = 1; } if(tour_ewilan == 1) { while(tour_ewilan) { SDL_WaitEvent(&evenement); switch(evenement.type) { case SDL_KEYDOWN: switch(evenement.key.keysym.sym) { case SDLK_a: SDL_BlitSurface(sort,NULL,ecran,&position); calcul_degats_mob(Ewilan); break; } } } tour_ewilan = 0; tour_ellana = 1; } if(tour_ellana == 1) { while(tour_ellana) { SDL_WaitEvent(&evenement); switch(evenement.type) { case SDL_KEYDOWN: switch(evenement.key.keysym.sym) { case SDLK_a: SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_mob(Ellana); break; } } } tour_ellana = 0; tour_rais = 1; } if(tour_rais == 1) { if(Rais.life == 100) { if(Edwin.life > 90 && Ewilan.life > 90 && Ellana.life > 90) { position.x = 30; position.y = 40; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_edwin = 1; } else if(Edwin.life > 50 && Ewilan.life > 90 && Ellana.life > 90) { position.x = 30; position.y = 40; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_edwin = 1; } else if(Edwin.life < 50 && Ewilan.life > 90&& Ellana.life > 90) { position.x = 10; position.y = 30; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_edwin = 1; } else if(Edwin.life < 50 && Ewilan.life > 50 && Ellana.life > 90) { position.x = 10; position.y = 30; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_edwin = 1; } else if(Edwin.life == 0 && Ewilan.life < 50 && Ellana.life > 90) { position.x = 30; position.y = 40; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_ewilan = 1; } else if(Edwin.life == 0 && Ewilan.life < 50 && Ellana.life > 50) { position.x = 30; position.y = 40; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_ewilan = 1; } else if(Edwin.life == 0 && Ewilan.life == 0 && Ellana.life < 50) { position.x = 30; position.y = 40; SDL_BlitSurface(attack_norm,NULL,ecran,&position); calcul_degats_joueur(Rais); tour_ellana = 1; } else if(Edwin.life == 0 && Ewilan.life == 0 && Ellana.life == 0) { position.x = 0; position.y = 0; SDL_BlitSurface(Game_over,NULL,ecran,&position); combat_pas_fini = 1; } } } if(Rais.life == 0) { return 1; } } dechargement(); return 1; }

Conclusion :


Voilà !
En espérant vous aider ^^

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.