Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.22 KB | None | 0 0
  1. typedef struct{
  2.     unsigned int *Ids;
  3.     unsigned int Count;
  4.     unsigned int OldData; /*[0] store the ids pointers used before, [1] store their screen pos rendered before*/
  5.     unsigned int NewData;
  6.     /*Way of counting the Data:
  7.         Old/New Data -> 16 Bits
  8.         [5] bits of sum from all horizontal coords
  9.         [5] bits of sum from all vertical coords
  10.         [6] bits of sum from all sprite pointers
  11.     */
  12. }SpritesTilesRender;
  13.  
  14. SpritesTilesRender SpriteTiles[25][80];/*8KB of initial data ,will expand from size when needed*/
  15.  
  16. /**
  17.     Tmp: two lines of 4 pixels.
  18.     SpriteTile: The pointer containing which sprites are to be rendered in this tile.
  19.     tileX: Horizontal pos from the tile.
  20.     tileY: Vertical pos from the tile. 
  21. **/
  22.  
  23. unsigned char RenderSpritesTile(unsigned char *Tmp,SpritesTilesRender *SpriteTile, int tileX,int tileY){
  24.     unsigned int PixelsNotRendered = 8;
  25.     int scrX[2],scrY[2];/*Screen Index*/
  26.     int _SprX,_SprY; /*SpriteIndex*/
  27.     int Id;
  28.     int i,j,k;
  29.     if(SpriteTile->Count){
  30.         unsigned char Tmp2[8] = {0,0,0,0,0,0,0,0};
  31.         Id - SpriteTile->Count -1; /*We go from the top to below to avoid overdrawn*/
  32.         while(Id > -1 && PixelsNotRendered > 0){
  33.             ScrX[0] = SpritesPosX[Id];
  34.             ScrX[1] = ScrX[0] + 4;
  35.             /*Sprite X and Y are always going to be valid, so no need for ifs and else*/
  36.             _SprX = ScrX[0] - (tileX << 2);
  37.             ScrY[0] = SpritesPosY[Id];
  38.             ScrY[1] = ScrY[0] + 2;
  39.             _SprY = ScrY[0] - (tileY << 3);
  40.             /*Limit the end of the sprite in case it ends before the Tile End*/
  41.             if(ScrX[1] < ScrX[0] + Sprites[Id].Size.X){
  42.                 ScrX[1] = ScrX[0] + Sprites[Id].Size.X;
  43.             }
  44.             if(ScrY[1] < ScrY[0] + Sprites[Id].Size.Y){
  45.                 ScrX[1] = ScrY[0] + Sprites[Id].Size.Y;
  46.             }
  47.             j= (_SprY<<2)/*Set the j offset by the amount of initial lines not to be rendered*/
  48.                 + _SprX;/*Set the horizontal Offset;*/
  49.             k = _SprX;
  50.             i = ScrX[0];/*Backup from ScrX*/
  51.             while(ScrY[0] != ScrY[1]){
  52.                 while(ScrX[0] != ScrX[1]){
  53.                     /*Avoid OverDrawn*/
  54.                     if(Tmp2[j] == 0){
  55.                         /*Avoid Tranparent Pixels*/
  56.                         if(Sprites[Id].Data[_SprY][_SprX] !=0){
  57.                             PixelsNotRendered--;
  58.                             Tmp2[j] = Sprites[Id].Data[_SprY][_SprX];
  59.                         }                          
  60.                     }  
  61.                     _SprX++;
  62.                     ScrX++;
  63.                     j++;
  64.                 }
  65.                 ScrX[0] = o;
  66.                 _SprX = k;
  67.                 _SprY++;
  68.                 ScrY[0]++;
  69.                 j = j + k; /*Sets the horizontal offset*/
  70.             }
  71.             Id--;
  72.         }
  73.         i=0;
  74.         /*And lastly we transfer the sprite tile for the char tile*/
  75.         while(i< 8){
  76.             if(Tmp2[i]!= 0){
  77.                 Tmp[i] = Tmp2[i];
  78.             }
  79.             i++;
  80.         }
  81.         return 1;
  82.     }
  83.     return 0;
  84. }
  85.  
  86. void ADD Sprite(){
  87.     NewPointers =
  88.         (((NewPointers >10) /*Filter the pointers*/
  89.                 + ActualPointer /*Add the actual pointer*/)
  90.             << 10 /*Move back the original pointer area*/);
  91.         /*-----STEP 2, ADD THE HORIZONTAL COORD----*/
  92.         |
  93.         (
  94.             (
  95.                 (
  96.                     ((NewPointers >5) /*Move the Horizontal stuff to the left*/
  97.                         & 31 /*Filter the First 5 bits*/
  98.                     )
  99.                     +   ActualX /*Adds the actual pos X*/
  100.                 ) << 5 /*Moves back where it belongs to*/
  101.             ) & 992/*Remove some garbage made after the 10 bits zone*/
  102.         )
  103.         |
  104.         /*-----STEP 3, ADD THE VERTICAL COORD---*/
  105.         (
  106.             (
  107.                 (NewPointers & 31) /*Filter the first 5 bits*/
  108.                 + ActualY /*Adds the actual pos Y*/
  109.             )   & 31 /*Filters back the original vertical zone.*/
  110.        
  111.         )
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement