Advertisement
ananasa

main.c

Apr 4th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include  <stdlib.h>
  3. #include  <SDL/SDL.h>
  4. #include <SDL/SDL_image.h>
  5. #include "boundingbox.h"
  6.  
  7. int main()
  8. {
  9.     SDL_Surface *screen ;
  10.     Objet Obj, Obj1 ;
  11.     SDL_Event event ;
  12.     int test =0 , x ;
  13.  
  14.  if  ( SDL_Init ( SDL_INIT_VIDEO )  == -1 )  {
  15.          printf ( "Can not init SDL \n " );
  16.      }
  17.  
  18.      screen  =  SDL_SetVideoMode ( 1280 ,  720 ,  32 ,  SDL_HWSURFACE  |  SDL_DOUBLEBUF );
  19.          if  ( screen  ==  NULL )  {
  20.       printf ( "Can not set video mode: \n ");
  21.          
  22.      }
  23.      SDL_FillRect ( screen ,  NULL ,  SDL_MapRGB ( screen -> format,  0,  255 , 255));
  24.  
  25. //initialiser et afficher image
  26.     initialiserObjet ( &Obj ,"first.png" ,  0 ,  0 ) ;
  27.     affichageObjet (Obj ,screen) ;
  28.     initialiserObjet ( &Obj1 ,"second.png" ,  500 ,  200 ) ;
  29.     affichageObjet (Obj1 ,screen) ;
  30.  
  31.    SDL_EnableKeyRepeat(10,10) ;
  32.     while  ( test==0 )  {
  33.          while  (SDL_PollEvent ( &event ))  {
  34.              switch  ( event.type )  {
  35.              case  SDL_QUIT :
  36.                  test  =  1 ;
  37.                  break ;  
  38.  
  39.                 case SDL_KEYDOWN:
  40.  
  41.         switch(event.key.keysym.sym)
  42.         {
  43.  
  44.                 case SDLK_ESCAPE :
  45.     test=1 ;
  46.  
  47.                 case SDLK_LEFT :
  48.  
  49. Obj.position.x-=10 ;
  50. SDL_FillRect ( screen ,  NULL ,  SDL_MapRGB ( screen -> format,  0,  255 , 255));
  51.     affichageObjet (Obj ,screen) ;
  52.     affichageObjet (Obj1 ,screen) ;
  53.  
  54. break ;
  55.  
  56.                 case SDLK_SPACE :
  57.  
  58. Obj.position.x+=10 ;
  59. SDL_FillRect ( screen ,  NULL ,  SDL_MapRGB ( screen -> format,  0,  255 , 255));
  60.     affichageObjet (Obj ,screen) ;
  61.     affichageObjet (Obj1 ,screen) ;
  62. break ;
  63.  
  64.                 case SDLK_UP :
  65.  
  66. Obj.position.y-=10 ;
  67. SDL_FillRect ( screen ,  NULL ,  SDL_MapRGB ( screen -> format,  0,  255 , 255));
  68.     affichageObjet (Obj ,screen) ;
  69.     affichageObjet (Obj1 ,screen) ;
  70. break ;
  71.  
  72.                 case SDLK_DOWN :
  73.  
  74. Obj.position.y+=10 ;
  75. SDL_FillRect ( screen ,  NULL ,  SDL_MapRGB ( screen -> format,  0,  255 , 255));
  76.     affichageObjet (Obj ,screen) ;
  77.     affichageObjet (Obj1 ,screen) ;
  78. break ;
  79.              }
  80.  
  81.     x=collisionBoundingbox (Obj.position,Obj1.position) ;
  82.  
  83. if(x==1)
  84. {
  85.     SDL_FillRect ( screen ,  NULL ,  SDL_MapRGB ( screen -> format,  0,  0 , 0));
  86.     SDL_Flip(screen) ;
  87. }
  88. break ;
  89.  
  90.          }
  91.      }
  92. }
  93. return 0 ;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement