Advertisement
ananasa

entite.c

Apr 4th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6.  
  7. #include <SDL/SDL.h>
  8. #include <SDL/SDL_image.h>
  9. #include <SDL/SDL_ttf.h>
  10. #include <SDL/SDL_mixer.h>
  11. #include <time.h>
  12. #include"entite.h"
  13.  
  14.     void initialiser_entite(ent *E)
  15. {
  16.  
  17.     E->spriteleft = IMG_Load("left.png"); //grande image de l'entité (plusieurs case A GAUCHE)
  18.     E->spriteright = IMG_Load("right.png");//grande image de l'entité (plusieurs case A DROITE)
  19.     E->dst.x = 0;
  20.     E->dst.y = 0;
  21.  
  22.  
  23.     E->position_entite.x=0;
  24.     E->position_entite.y=0;
  25.     E->position_map.x=0;
  26.     E->position_map.y=0;
  27.     E->frame.x=0;
  28.     E->frame.y=0;
  29.     E->frame.w = SPRITE_W;
  30.     E->frame.h = SPRITE_H;
  31.     E->dst.x=0;
  32.     E->dst.y=0;
  33.  
  34.     E->image_entite=NULL;
  35.  
  36.  
  37.     E->pos_alea_max_x=0;
  38.     E->pos_alea_min_x=0;
  39.  
  40.     E->pos_alea_max_y=0;
  41.     E->pos_alea_min_y=0;
  42.  
  43.     E-> pos_max_x=0;
  44.     E-> pos_min_x=0;
  45.  
  46.     E-> pos_min_y=0;
  47.     E->pos_max_y=0;
  48. }
  49.  
  50.  
  51.     void animation_entite(ent E)
  52. {
  53.     SDL_Surface* screen = NULL;
  54.  
  55.     SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
  56.     screen = SDL_SetVideoMode(W_Screen, H_Screen, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_HWPALETTE | SDL_RESIZABLE );//SDL_HWPALETTE:Mise a jour de la surface
  57.  
  58.    
  59.     SDL_Surface* backg = NULL;
  60.     backg = IMG_Load("background.jpg");
  61.     SDL_BlitSurface(backg, NULL, screen, NULL);
  62.     SDL_WM_SetCaption("animation entite", NULL);
  63.     SDL_Flip(screen);
  64.  
  65.     initialiser_entite(&E);
  66.  
  67. //Hide Cursor
  68.     SDL_ShowCursor(SDL_DISABLE);
  69.     int continuer = 1;
  70.     while(continuer)
  71.     {
  72.         SDL_Event event;
  73.         SDL_PollEvent(&event);
  74.                
  75.  
  76.         int i;
  77.                 int j;
  78.  
  79.     for(j=0;j<1;j++)
  80.         {
  81.         for(i = 0; i<MAX_FRAMES; i++)
  82.         {          
  83.             E.frame.x = i*(Sint16)SPRITE_W;
  84.             E.frame.y = j*(Sint16)SPRITE_H;//0;
  85.             E.frame.w = SPRITE_W;
  86.             E.frame.h = SPRITE_H;
  87.             SDL_BlitSurface(backg, NULL, screen, NULL);
  88.             SDL_BlitSurface(E.spriteright, &E.frame, screen, &E.dst);          
  89.             SDL_Flip(screen);
  90.             SDL_Delay(700);          
  91.         }
  92. }
  93.     for(j=0;j<1;j++)
  94. {       for(i = (MAX_FRAMES - 1); i>=0; i--)
  95.         {
  96.             E.frame.x = i*(Sint16)SPRITE_W;
  97.             E.frame.y = j*(Sint16)SPRITE_H;
  98.             E.frame.w = SPRITE_W;
  99.             E.frame.h = SPRITE_H;
  100.             SDL_BlitSurface(backg, NULL, screen, NULL);
  101.             SDL_BlitSurface(E.spriteleft, &E.frame, screen, &E.dst);
  102.             SDL_Flip(screen);
  103.             SDL_Delay(700);
  104.         }
  105.  
  106. }
  107.         switch(event.type)
  108.  
  109.         {   case SDL_QUIT:
  110.                                continuer = 0;
  111.                                break;
  112.             case SDL_KEYDOWN:
  113.                 if(event.key.keysym.sym == SDLK_ESCAPE)
  114.                 {
  115.                     continuer = 0;
  116.                 }
  117.         }
  118.  
  119.     }
  120.     SDL_Quit();
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement