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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <fmod.h>
#include <SDL/SDLP_Anim.h>
int main(int argc, char *argv[])
{
//Variable
int continuer = 1;
//Creation des variables SDL
SDL_Surface *ecran = NULL, *mainPlayer = NULL, *evilPizza = NULL, *score = NULL;
TTF_Font *police = NULL;
SDL_Color blanc = {255,255,255};
SDL_Rect positionMainPlayer, positionevilPizza, positionScore;//Les positions
SDL_Event event;
//Initilistation de la SDL
SDL_Init(SDL_INIT_VIDEO | SDL_DOUBLEBUF | SDL_INIT_AUDIO);
TTF_Init();
//Creation des surfaces
ecran = SDL_SetVideoMode(482, 240, 32, SDL_SWSURFACE);
//Remplissage de l'écran
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 1, 1, 1));
//Chargement des images
mainPlayer = SDL_LoadBMP("Sprites/zozor.bmp");
evilPizza = SDL_LoadBMP("Sprites/Evilpizza.bmp");
police = TTF_OpenFont("TECHNOID.TTF", 21);
score = TTF_RenderText_Solid(police, "0000", blanc);
//Reglage de la transparence
SDL_SetColorKey(mainPlayer, SDL_SRCCOLORKEY, SDL_MapRGB(mainPlayer->format, 0, 255, 255));
SDL_SetColorKey(evilPizza, SDL_SRCCOLORKEY, SDL_MapRGB(evilPizza->format, 0, 255, 255));
//Positionnement initiale du mainPlayer
positionMainPlayer.x = ecran->w / 2 - mainPlayer->w / 2;
positionMainPlayer.y = 200;
//Positionement de la pizza
positionevilPizza.x = 95;
positionevilPizza.y = 40;
//Position du score
positionScore.x = 10;
positionScore.y = 220;
//Boucle de mouvement
SDL_EnableKeyRepeat(5, 5);
SDL_ShowCursor(SDL_DISABLE);
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_RIGHT: // Flèche droite
positionMainPlayer.x++;
break;
case SDLK_LEFT: // Flèche gauche
positionMainPlayer.x--;
break;
case SDLK_ESCAPE: /* Appui sur la touche Echap, on arrête le programme */
continuer = 0;
break;
}
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0)); /* On efface l'écran */
SDL_BlitSurface(mainPlayer, NULL, ecran, &positionMainPlayer);/* On place zozor à sa nouvelle position */
SDL_BlitSurface(evilPizza, NULL, ecran, &positionevilPizza);/*On place la Pizza*/
SDL_BlitSurface(score, NULL, ecran, &positionScore);
SDL_Flip(ecran); /* On met à jour l'affichage */
}
TTF_CloseFont(police);
TTF_Quit();
SDL_FreeSurface(mainPlayer);
SDL_FreeSurface(evilPizza);
SDL_FreeSurface(score);/*On libère de l'espace pour les surfaces*/
SDL_Quit();
} |
Partager