Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct{
- unsigned int *Ids;
- unsigned int Count;
- unsigned int OldData; /*[0] store the ids pointers used before, [1] store their screen pos rendered before*/
- unsigned int NewData;
- /*Way of counting the Data:
- Old/New Data -> 16 Bits
- [5] bits of sum from all horizontal coords
- [5] bits of sum from all vertical coords
- [6] bits of sum from all sprite pointers
- */
- }SpritesTilesRender;
- SpritesTilesRender SpriteTiles[25][80];/*8KB of initial data ,will expand from size when needed*/
- /**
- Tmp: two lines of 4 pixels.
- SpriteTile: The pointer containing which sprites are to be rendered in this tile.
- tileX: Horizontal pos from the tile.
- tileY: Vertical pos from the tile.
- **/
- unsigned char RenderSpritesTile(unsigned char *Tmp,SpritesTilesRender *SpriteTile, int tileX,int tileY){
- unsigned int PixelsNotRendered = 8;
- int scrX[2],scrY[2];/*Screen Index*/
- int _SprX,_SprY; /*SpriteIndex*/
- int Id;
- int i,j,k;
- if(SpriteTile->Count){
- unsigned char Tmp2[8] = {0,0,0,0,0,0,0,0};
- Id - SpriteTile->Count -1; /*We go from the top to below to avoid overdrawn*/
- while(Id > -1 && PixelsNotRendered > 0){
- ScrX[0] = SpritesPosX[Id];
- ScrX[1] = ScrX[0] + 4;
- /*Sprite X and Y are always going to be valid, so no need for ifs and else*/
- _SprX = ScrX[0] - (tileX << 2);
- ScrY[0] = SpritesPosY[Id];
- ScrY[1] = ScrY[0] + 2;
- _SprY = ScrY[0] - (tileY << 3);
- /*Limit the end of the sprite in case it ends before the Tile End*/
- if(ScrX[1] < ScrX[0] + Sprites[Id].Size.X){
- ScrX[1] = ScrX[0] + Sprites[Id].Size.X;
- }
- if(ScrY[1] < ScrY[0] + Sprites[Id].Size.Y){
- ScrX[1] = ScrY[0] + Sprites[Id].Size.Y;
- }
- j= (_SprY<<2)/*Set the j offset by the amount of initial lines not to be rendered*/
- + _SprX;/*Set the horizontal Offset;*/
- k = _SprX;
- i = ScrX[0];/*Backup from ScrX*/
- while(ScrY[0] != ScrY[1]){
- while(ScrX[0] != ScrX[1]){
- /*Avoid OverDrawn*/
- if(Tmp2[j] == 0){
- /*Avoid Tranparent Pixels*/
- if(Sprites[Id].Data[_SprY][_SprX] !=0){
- PixelsNotRendered--;
- Tmp2[j] = Sprites[Id].Data[_SprY][_SprX];
- }
- }
- _SprX++;
- ScrX++;
- j++;
- }
- ScrX[0] = o;
- _SprX = k;
- _SprY++;
- ScrY[0]++;
- j = j + k; /*Sets the horizontal offset*/
- }
- Id--;
- }
- i=0;
- /*And lastly we transfer the sprite tile for the char tile*/
- while(i< 8){
- if(Tmp2[i]!= 0){
- Tmp[i] = Tmp2[i];
- }
- i++;
- }
- return 1;
- }
- return 0;
- }
- void ADD Sprite(){
- NewPointers =
- (((NewPointers >10) /*Filter the pointers*/
- + ActualPointer /*Add the actual pointer*/)
- << 10 /*Move back the original pointer area*/);
- /*-----STEP 2, ADD THE HORIZONTAL COORD----*/
- |
- (
- (
- (
- ((NewPointers >5) /*Move the Horizontal stuff to the left*/
- & 31 /*Filter the First 5 bits*/
- )
- + ActualX /*Adds the actual pos X*/
- ) << 5 /*Moves back where it belongs to*/
- ) & 992/*Remove some garbage made after the 10 bits zone*/
- )
- |
- /*-----STEP 3, ADD THE VERTICAL COORD---*/
- (
- (
- (NewPointers & 31) /*Filter the first 5 bits*/
- + ActualY /*Adds the actual pos Y*/
- ) & 31 /*Filters back the original vertical zone.*/
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement