int i = 0;
SDL_SURFACE* images[7];
...
// خزن الفريمات من 1 الى 7 في المصفوفة images
...
case sdlk_right:
positionP.x += 10;
persoactuel = images[i++];
if(i == 7)
i = 0;
break;
case sdlk_left:
...
int shooting = 0;
SDL_RECT projectilePos;
...
case SDLK_SPACE:
shooting = 1;
projectilePos.x = player.x;
projectilePos.y = player.y;
...
//في حال عدم تجاوز موقع الرصاصة موقع الهدف أو خروجها عن حدود الشاشة
projectilePos.x+= speed_and_direction;
#include
#include
int main(int argc, char *argv[])
{
SDL_Surface *screen = NULL, *image[4] = {NULL} , *actuel = NULL;
SDL_Rect pos;
SDL_Event event;
int i=0;
int run = 1;
SDL_Surface* projectile = NULL;
int shooting = 0;
SDL_RECT projectilePos;
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(400, 400, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("mourad projet", NULL);
image[0] = SDL_LoadBMP("1.bmp");
image[1] = SDL_LoadBMP("2.bmp");
image[2] = SDL_LoadBMP("3.bmp");
image[3] = SDL_LoadBMP("4.bmp");
projectile = SDL_LoadBMP("projectile.bmp");
pos.x = 1;
pos.y = 1;
SDL_EnableKeyRepeat(100,100);
while(run)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
run = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:
pos.x+=10;
actuel = image[i++];
if(i == 3)
i=0;
break;
break;
case SDLK_SPACE:
if(shooting)
break;
shooting = 1;
projectilePos.x = pos.x;
projectilePos.y = pos.y;
}
break;
}
// في حال عدم تجاوز موقع الرصاصة عن حدود الشاشة
if(projectilePos.x < 400) {
projectilePos.x+=15;
}
else {
shooting = 0;
}
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,50,50,50));
SDL_BlitSurface(actuel,NULL,screen,&pos);
if(shooting)
SDL_BlitSurface(projectile, NULL, screen, projectilePos);
SDL_Flip(screen);
}
SDL_FreeSurface(actuel);
SDL_Quit();
return EXIT_SUCCESS;
}