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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int main (int argc , char *argv [])
{
SDL_Surface *fenetre = NULL , *Sephiroth[8] = {} , *Sephiroth_actuel = NULL ;
SDL_Rect position_sephiroth;
SDL_Event event;
int continuer =1 ;
SDL_Init (SDL_INIT_VIDEO);
fenetre = SDL_SetVideoMode(640 , 480 ,32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Sephiroth",NULL);
Sephiroth[0] = SDL_LoadBMP("perso1.bmp");
Sephiroth[1] = SDL_LoadBMP("perso2.bmp");
Sephiroth[2] = SDL_LoadBMP("perso3.bmp");
Sephiroth[3] = SDL_LoadBMP("perso4.bmp");
Sephiroth[4] = SDL_LoadBMP("Attaque1.bmp");
Sephiroth[5] = SDL_LoadBMP("Attaque2.bmp");
Sephiroth[6] = SDL_LoadBMP("Attaque3.bmp");
Sephiroth[7] = SDL_LoadBMP("Attaque4.bmp");
position_sephiroth.x = 0 ;
position_sephiroth.y = 0;
Sephiroth_actuel= SDL_LoadBMP("perso1.bmp");
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_EnableKeyRepeat(10, 10);
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT :
continuer =0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_UP:
position_sephiroth.y -= 5;
break;
case SDLK_DOWN:
position_sephiroth.y += 5;
break;
case SDLK_LEFT:
position_sephiroth.x -= 25;
break;
case SDLK_RIGHT:
Sephiroth_actuel = Sephiroth[1];
position_sephiroth.x += 25;
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(85);
Sephiroth_actuel = Sephiroth[2];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(85);
Sephiroth_actuel = Sephiroth[3];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(85);
Sephiroth_actuel = Sephiroth[0];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
break;
case SDLK_SPACE:
Sephiroth_actuel = Sephiroth[4];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(200);
SDL_FreeSurface(Sephiroth_actuel);
Sephiroth_actuel = Sephiroth[5];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(100);
SDL_FreeSurface(Sephiroth_actuel);
Sephiroth_actuel = Sephiroth[6];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(100);
SDL_FreeSurface(Sephiroth_actuel);
Sephiroth_actuel = Sephiroth[7];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_Delay(100);
SDL_FreeSurface(Sephiroth_actuel);
Sephiroth_actuel = Sephiroth[0];
SDL_SetColorKey(Sephiroth_actuel,SDL_SRCCOLORKEY,SDL_MapRGB(Sephiroth_actuel->format,255,255,255));
SDL_BlitSurface(Sephiroth_actuel,NULL,fenetre,&position_sephiroth);
SDL_Flip(fenetre);
SDL_FreeSurface(Sephiroth_actuel);
break ;
}
break;
}
SDL_FillRect(fenetre, NULL, SDL_MapRGB(fenetre->format, 0, 0, 0));
SDL_BlitSurface(Sephiroth_actuel, NULL, fenetre, &position_sephiroth);
SDL_Flip(fenetre);
}
SDL_FreeSurface(Sephiroth_actuel);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager