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
| int game(ecran)
{
SDL_Surface *perso2 = NULL;
SDL_Rect pos2;
SDL_Surface *perso = NULL;
SDL_Rect pos;
int i, j;
int continuer = 1;
SDL_Event event;
SDL_Rect position, position2;
perso = IMG_Load("mur.jpg");
perso2 = IMG_Load("robot.gif");
err = IMG_Load("err2.jpg");
pos.x = 0;
pos.y = 0;
pos2.x = 300;
pos2.y = 300;
SDL_BlitSurface(perso, NULL, ecran, &pos);
SDL_BlitSurface(perso2, NULL, ecran, &pos2);
SDL_EnableKeyRepeat(100, 100);
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:
pos2.y++;
break;
case SDLK_DOWN:
pos2.y--;
break;
case SDLK_RIGHT:
pos2.x++;
break;
case SDLK_LEFT:
pos2.x--;
break;
case SDLK_KP8:
pos.y--;
break;
case SDLK_KP2:
pos.y++;
break;
case SDLK_KP6:
pos.x++;
break;
case SDLK_KP4:
pos.x--;
break;
}
}
position.x = pos.x * BLOC;
position.y = pos.y * BLOC;
position2.x = pos2.x * BLOC;
position2.y = pos2.y * BLOC;
SDL_BlitSurface(perso2, NULL, ecran, &position2);
SDL_BlitSurface(perso, NULL, ecran, &position);
SDL_Flip(ecran);
}
SDL_EnableKeyRepeat (0, 0);
} |
Partager