IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Jeu Ping Pong


Sujet :

C

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2015
    Messages : 1
    Par défaut Jeu Ping Pong
    Bonjour, je souhaite créer un jeu ping pong en c. J'ai déjà commencé mais je veux qu'il soit plus performant. Je veux créer une fonction qui gère les scorse et d'autres idées que vous pouvez me proposer. Vous trouverez le code que j'ai déjà programmé. Faites vos critiques et vos propositions.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    #include "graphics.h"
     
    struct BRIQUE
    {
    	COULEUR coul;
    	POINT PBG,PHD;
    	int etat;
    };
    typedef struct BRIQUE BRI;
    BRI BR[6][18];
     
    void initialise_brique()
    {
    	int l,c,L=35;
    	COULEUR color;
    	for(l=0;l<6;l++)
    	{
    		int ytmp = 300+l*L;
     
    		for(c=0;c<18;c++)
    		{
    			BR[l][c].PBG.y = ytmp;
    			BR[l][c].PBG.x = c*75;
    			BR[l][c].PHD.y = ytmp+L;
    			BR[l][c].PHD.x = c*75+75;
    			do
    			{ color = couleur_RGB(alea_int(250),alea_int(250),alea_int(250));
    			}while(color == bleu);
    			BR[l][c].coul = color;
     
    			draw_fill_rectangle(BR[l][c].PBG,BR[l][c].PHD,BR[l][c].coul);
     
    		}
    	}
    }
    struct RAQ
    {
    	POINT P1,P2;
    };
    typedef struct RAQ RAQ;
    struct ball
    {
    	POINT centre,bd,bg,bh,bb;
    	int rn,dx,dy;
    };
    typedef struct ball BL;
    POINT efface_affiche(int r,int dx,int dy,POINT ancien)
     {
    		POINT nouveau;
    	  draw_fill_circle(ancien,r,bleu);
    	   nouveau.x = ancien.x + dx;
    	  nouveau.y = ancien.y + dy;
    	 draw_fill_circle(nouveau,r,rouge);
    	  return nouveau;
     }
     
    void initialise_ball(BL *bal)
    {
    	bal->centre.x = 450;bal->centre.y = 300;
    	bal->rn=5;bal->dx=1;bal->dy=1;
    }
    void deplace_bal(BL *bal)
    {
    		bal->bd.y = bal->bg.y = bal->centre.y;
    		bal->bg.x = bal->centre.x - bal->rn;
    		bal->bd.x = bal->centre.x + bal->rn;
    		bal->bh.x = bal->bb.x = bal->centre.x;
    		bal->bh.y = bal->centre.y + bal->rn;
    		bal->bb.y = bal->centre.y - bal->rn;
    		POINT ancien = bal->centre;
    	  if((bal->bh.y>=HEIGHT && bal->dy>0) || (bal->bb.y<=0 && bal->dy<0))
    		 {
    		   bal->dy=-bal->dy;
    		 }
    	  if((bal->bd.x>=WIDTH && bal->dx>0) || (bal->bg.x<=0 && bal->dx<0))
    		{
    		  bal->dx=-bal->dx;
    		}
    	  bal->centre = efface_affiche(bal->rn,bal->dx,bal->dy,ancien);
    }
    /*void efface_RAQ(RAQ RK)
    {
    	draw_fill_rectangle(RK.P1,RK.P2,bleu);
    }
    void affiche_RAQ(RAQ RK)
    {
    	draw_fill_rectangle(RK.P1,RK.P2,rouge);
    }*/
    void deplace_Raq(RAQ *R,int dx)
    {
    	if(R->P2.x>900 && dx>0)
    	{
    	R->P1.x = 800;R->P1.y = 30;
    	R->P2.x = 900;R->P2.y = 45;
    	draw_fill_rectangle(R->P1,R->P2,rouge);
    	}
    	else if(R->P1.x<0 && dx<0)
    	{
    	R->P1.x = 0;R->P1.y = 30;
    	R->P2.x = 100;R->P2.y = 45;
    	draw_fill_rectangle(R->P1,R->P2,rouge);}
    	draw_fill_rectangle(R->P1,R->P2,bleu);
    	R->P1.x+=dx;
    	R->P2.x+=dx;
    	draw_fill_rectangle(R->P1,R->P2,rouge);
    	}
     
    //&& bal->bd.x <=RK->P2.x &&  bal->bg.x >= RK->P1.x
    void choc_Raq_ball(RAQ *RK, BL *bal)
    {
     
    	if(bal->bb.y <= (RK->P2.y+1) && bal->bb.y > RK->P1.y && bal->dy<0 && bal->bb.x <=RK->P2.x &&  bal->bb.x >= RK->P1.x)
    		bal->dy = -bal->dy;
     
    	if(bal->bh.y >= (RK->P1.y-1) && bal->bb.y < RK->P2.y && bal->dy>0 && bal->bh.x <=RK->P2.x &&  bal->bh.x >= RK->P1.x)
    		bal->dy = -bal->dy;
     
    	if(bal->bd.x >= RK->P1.x && bal->bd.x < RK->P1.x+10 && bal->dx>0 && bal->bd.y <= RK->P2.y &&  bal->bd.y >= RK->P1.y)
    		bal->dx = -bal->dx;
     
    	if(bal->bg.x <= RK->P2.x && bal->bg.x > RK->P2.x-10 && bal->dx<0 && bal->bg.y <= RK->P2.y &&  bal->bg.y >= RK->P1.y)
    		bal->dx = -bal->dx;
    }
    void choc_ball_brique(BL *bal)
    {
    	int l,c;
    	for(l=0;l<6;l++)
    	{
    		for(c=0;c<18;c++)
    		{
    			/*if(bal->bh.y>=BR[l][c].PBG.y && bal->dy > 0 && bal->bh.x>=BR[l][c].PBG.x && bal->bh.x<=BR[l][c].PHD.x && BR[l][c].coul != bleu)
    			{
     
    					draw_fill_rectangle(BR[l][c].PBG,BR[l][c].PHD,bleu);
    					bal->dy = -bal->dy;
    					BR[l][c].coul = bleu;
     
    			}*/
    			if(bal->bh.y>=BR[l][c].PBG.y && bal->bb.y < BR[l][c].PBG.y && bal->dy > 0 && bal->bh.x>=BR[l][c].PBG.x && bal->bh.x<=BR[l][c].PHD.x && BR[l][c].coul != bleu)
    			{
     
    					draw_fill_rectangle(BR[l][c].PBG,BR[l][c].PHD,bleu);
    					bal->dy = -bal->dy;
    					BR[l][c].coul = bleu;
     
    			}
    		if(bal->bb.y<=BR[l][c].PHD.y && bal->bb.y > BR[l][c].PBG.y && bal->dy<0 && bal->bb.x>=BR[l][c].PBG.x && bal->bb.x<=BR[l][c].PHD.x && BR[l][c].coul != bleu)
    					{draw_fill_rectangle(BR[l][c].PBG,BR[l][c].PHD,bleu);
    					bal->dy = -bal->dy;
    					BR[l][c].coul = bleu;}
    		/*else if(bal->bd.x >= BR[l][c].PBG.x && bal->bd.x < BR[l][c].PBG.x + 10 && bal->bd.y <= BR[l][c].PHD.y &&  bal->bd.y >= BR[l][c].PBG.y && BR[l][c].coul != bleu)
    					{draw_fill_rectangle(BR[l][c].PBG,BR[l][c].PHD,bleu);
    					bal->dx = -bal->dx;
    					BR[l][c].coul = bleu;}
    		else if(bal->bg.x <= BR[l][c].PHD.x && bal->bg.x < BR[l][c].PHD.x - 10 && bal->bd.y <= BR[l][c].PHD.y &&  bal->bd.y >= BR[l][c].PBG.y && BR[l][c].coul != bleu)
    					{draw_fill_rectangle(BR[l][c].PBG,BR[l][c].PHD,bleu);
    					bal->dx = -bal->dx;
    					BR[l][c].coul = bleu;}*/
     
    		}
    	}
    }
    int main()
    {
    	init_graphics(900,600);
    	fill_screen(bleu);
    	POINT P;
    	affiche_auto_off();
    	RAQ RK;
    	BL bal;
    	initialise_ball(&bal);
    	RK.P1.x = 400;RK.P1.y = 30;
    	RK.P2.x = 500;RK.P2.y = 45;
    	draw_fill_rectangle(RK.P1,RK.P2,rouge);
    	initialise_brique();
    while(1)
    {
    	choc_Raq_ball(&RK,&bal);
    	choc_ball_brique(&bal);
        deplace_bal(&bal);
        choc_Raq_ball(&RK,&bal);
    	P = get_arrow();
    	if(P.x!=0)
    	{
    	deplace_Raq(&RK,P.x*2);
    	}
    	affiche_all();
    }
    	wait_escape();
    	exit(0);
    }
    Fichiers attachés Fichiers attachés

  2. #2
    Expert éminent

    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    5 202
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 5 202
    Par défaut
    Je ne peux pas télécharger ici, poste ton code lui-même, via la balise [code] (le bouton #)

  3. #3
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    27 105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 27 105
    Billets dans le blog
    146
    Par défaut
    Bonjour,

    Je conseille d'ajouter des assert() pour vérifier les pointeurs passés à des fonctions : http://alexandre-laurent.developpez....-applications/
    Le nom des variables et structures n'est pas explicite. Pas de commentaires, non plus.

    Je me demande comment vous sortez du while(1).

    Pour le reste, rien à dire, le code n'est pas vraiment compréhensible.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

Discussions similaires

  1. flv embed mode ping pong
    Par superleon dans le forum ActionScript 3
    Réponses: 6
    Dernier message: 16/12/2008, 12h39
  2. [IRC] Ping / Pong
    Par Invité4 dans le forum IRC / mIRC
    Réponses: 7
    Dernier message: 28/04/2008, 19h07
  3. Ping pong vers un site
    Par dd_garion dans le forum Débuter
    Réponses: 2
    Dernier message: 26/02/2008, 10h47
  4. Problème pour un jeu de pong
    Par Galip dans le forum C++Builder
    Réponses: 4
    Dernier message: 05/04/2007, 08h28
  5. [TP] Problème dans un jeu de ping pong
    Par kellog02 dans le forum Turbo Pascal
    Réponses: 1
    Dernier message: 05/11/2005, 11h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo