Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. int main(int argc, char *argv[])
  2. {
  3. SDL_Init(SDL_INIT_VIDEO); // Initialisation de la SDL
  4.  
  5. SDL_Surface *ecran = NULL, *dauphin = NULL, *background = NULL;
  6. SDL_Rect position_dauphin, position_background;
  7. position_dauphin.x = 50;
  8. position_dauphin.y = 150;
  9. position_background;
  10. position_background.x = 0;
  11. position_background.y = 0;
  12. SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 30, 145, 183));
  13.  
  14. SDL_WM_SetCaption("Blue Ocean ~prototype~", NULL);
  15.  
  16. ecran = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); // On tente d'ouvrir une fenêtre
  17. if (ecran == NULL) // Si l'ouverture a échoué, on écrit l'erreur et on arrête
  18. {
  19. fprintf(stderr, "Impossible de charger le mode vidéo : %s\n", SDL_GetError());
  20. exit(EXIT_FAILURE);
  21. }
  22.  
  23. background = IMG_Load("background.png");
  24. //SDL_SetColorKey(zozor, SDL_SRCCOLORKEY, SDL_MapRGB(dauphin->format, 255, 0, 0));
  25. // Utilisez SDL_SRCCOLORKEY pour activer la transparence, 0 pour la désactiver.
  26. SDL_BlitSurface(background, NULL, ecran, &position_background);
  27.  
  28. dauphin = IMG_Load("dauphin.png");
  29. SDL_SetAlpha(dauphin, SDL_SRCALPHA, 200);
  30. SDL_BlitSurface(dauphin, NULL, ecran, &position_dauphin);
  31.  
  32. SDL_Flip(ecran); /* Mise à jour de l'écran */
  33.  
  34. int program_is_running = 1;
  35. SDL_Event event;
  36. while (program_is_running)
  37. {
  38. SDL_PollEvent(&event);
  39. switch(event.type) // Test du type d'évènement
  40. {
  41. case SDL_QUIT: // Si c'est un évènement de type "Quitter"
  42. program_is_running = 0;
  43. break;
  44.  
  45. case SDL_KEYDOWN:
  46. switch (event.key.keysym.sym)
  47. {
  48. case SDLK_ESCAPE:
  49. program_is_running = 0;
  50. break;
  51. case SDLK_SPACE:
  52. break;
  53. }
  54. }
  55. }
  56.  
  57. SDL_FreeSurface(dauphin); /* On libère la surface */
  58. SDL_FreeSurface(background);
  59. SDL_Quit(); // Arrêt de la SDL
  60.  
  61. return EXIT_SUCCESS; // Fermeture du programme
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement