Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.40 KB | None | 0 0
  1. void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, bool chop)
  2. {
  3.     if(defaultsheet == 0) defaultsheet = IMGObjectSheet;
  4.     //sprites can be offset by a random amount, both animationwise, and just variationwise.
  5.     //the base offset is set here.
  6.     int rando = randomCube[x%RANDOM_CUBE][y%RANDOM_CUBE][z%RANDOM_CUBE];
  7.     //and the random offset of the animation frame is set here, provided the sprite iis set to use random animation frames.
  8.     int offsetAnimFrame = ((randomanimation?rando:0) + currentAnimationFrame) % MAX_ANIMFRAME;
  9.     //the following stuff is only bothered with if the animation frames say it should be drawn. this can be over-ridden
  10.     // by setting animate to 0
  11.     if ((animframes & (1 << offsetAnimFrame)) || !animate)
  12.     {
  13.         //if set by the xml file, a random offset between 0 and 'variations' is added to the sprite.
  14.         int randoffset = 0;
  15.         if(variations)
  16.             randoffset = rando%variations;
  17.  
  18.         if(!b)
  19.             return;
  20.         //if the xml says that this is a blood sprite, and offset is set here for proper pooling. this over-rides the random offset.
  21.         if(bloodsprite)
  22.             randoffset = getBloodOffset(b);
  23.         if((water_direction < 0) || (water_direction == get_relative_water_direction(b)))
  24.         {
  25.             if(( //these are all border conditions. this first section is a list of positive conditions. if at least one of the border conditions is met, the tile can be shown.
  26.                 (openborders & b->openborders) ||
  27.                 (upstairborders & b->upstairborders) ||
  28.                 (downstairborders & b->downstairborders) ||
  29.                 (rampborders & b->rampborders) ||
  30.                 (wallborders & b->wallborders) ||
  31.                 (floorborders & b->floorborders) ||
  32.                 (lightborders & b->lightborders)
  33.                 ) && !( //This second block consists of negative conditions. if /any/ of these border conditions are met, the tile will not be drawn
  34.                 (notopenborders & b->openborders) ||
  35.                 (notupstairborders & b->upstairborders) ||
  36.                 (notdownstairborders & b->downstairborders) ||
  37.                 (notrampborders & b->rampborders) ||
  38.                 (notwallborders & b->wallborders) ||
  39.                 (notfloorborders & b->floorborders) ||
  40.                 (darkborders & b->lightborders)
  41.                 ))
  42.             {
  43.                 if(
  44.                     (snowmin <= b->snowlevel &&
  45.                     (snowmax == -1 || snowmax >= b->snowlevel)) &&
  46.                     (bloodmin <= b->bloodlevel && (bloodmax == -1 || bloodmax >= b->bloodlevel)) &&
  47.                     (mudmin <= b->mudlevel && (mudmax == -1 || mudmax >= b->mudlevel)) &&
  48.                     (grassmin <= b->grasslevel && (grassmax == -1 || grassmax >= b->grasslevel)) &&
  49.                     ((light==LIGHTANY) || ((light==LIGHTYES) && b->designation.bits.skyview) || ((light==LIGHTNO) && !(b->designation.bits.skyview)))  &&//only bother with this tile if it's in the light, or not.
  50.                     ((grasstype == -1) || (grasstype == b->grassmat))
  51.                     )
  52.                 {
  53.                     int32_t drawx = x;
  54.                     int32_t drawy = y;
  55.                     int32_t drawz = z; //- ownerSegment->sizez + 1;
  56.  
  57.  
  58.                     correctBlockForSegmetOffset( drawx, drawy, drawz);
  59.                 correctBlockForRotation( drawx, drawy, drawz, b->ownerSegment->rotation);
  60.                     int32_t viewx = drawx;
  61.                     int32_t viewy = drawy;
  62.                     int32_t viewz = drawz;
  63.                     pointToScreen((int*)&drawx, (int*)&drawy, drawz);
  64.                     drawx -= TILEWIDTH>>1;
  65.  
  66.                     int sheetx, sheety;
  67.                     if(tilelayout == BLOCKTILE)
  68.                     {
  69.                         sheetx = ((sheetindex+tileoffset+randoffset) % SHEET_OBJECTSWIDE) * spritewidth;
  70.                         sheety = ((sheetindex+tileoffset+randoffset) / SHEET_OBJECTSWIDE) * spriteheight;
  71.                     }
  72.                     else if(tilelayout == RAMPBOTTOMTILE)
  73.                     {
  74.                         sheetx = sheetx = SPRITEWIDTH * b->ramp.index;
  75.                         sheety = sheety = ((TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset))+(TILEHEIGHT + FLOORHEIGHT);
  76.                     }
  77.                     else if(tilelayout == RAMPTOPTILE)
  78.                     {
  79.                         sheetx = sheetx = SPRITEWIDTH * b->ramp.index;
  80.                         sheety = sheety = (TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset);
  81.                     }
  82.                     else
  83.                     {
  84.                         sheetx = ((sheetindex+tileoffset+randoffset) % SHEET_OBJECTSWIDE) * spritewidth;
  85.                         sheety = ((sheetindex+tileoffset+randoffset) / SHEET_OBJECTSWIDE) * spriteheight;
  86.                     }
  87.                     if(chop && ( halftile == HALFTILECHOP))
  88.                     {
  89.                         if(fileindex < 0)
  90.                             al_draw_tinted_bitmap_region(defaultsheet, get_color(b), sheetx, sheety+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
  91.                         else
  92.                             al_draw_tinted_bitmap_region(getImgFile(fileindex), get_color(b), sheetx, (sheety)+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT, 0);
  93.                         //draw cut-off floor thing
  94.                         al_draw_bitmap_region(IMGObjectSheet,
  95.                             TILEWIDTH * SPRITEFLOOR_CUTOFF, 0,
  96.                             SPRITEWIDTH, SPRITEWIDTH,
  97.                             drawx+offset_x, drawy+offset_y-((SPRITEHEIGHT-WALL_CUTOFF_HEIGHT)/2), 0);
  98.                     }
  99.                     else if ((chop && (halftile == HALFTILEYES)) || (!chop && (halftile == HALFTILENO)) || (!chop && (halftile == HALFTILECHOP)) || (halftile == HALFTILEBOTH))
  100.                     {
  101.                         if((isoutline == OUTLINENONE) || ((isoutline == OUTLINERIGHT) && (b->depthBorderNorth)) || ((isoutline == OUTLINELEFT) && (b->depthBorderWest)) || ((isoutline == OUTLINEBOTTOM) && (b->depthBorderDown)))
  102.                         {
  103.                             if(fileindex < 0)
  104.                                 al_draw_tinted_bitmap_region(defaultsheet, get_color(b), sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
  105.                             else
  106.                                 al_draw_tinted_bitmap_region(getImgFile(fileindex), get_color(b), sheetx, sheety, spritewidth, spriteheight, drawx + offset_x + offset_user_x, drawy + offset_user_y + (offset_y - WALLHEIGHT), 0);
  107.                         }
  108.                         if(needoutline)
  109.                         {
  110.                             //drawy -= (WALLHEIGHT);
  111.                             //Northern border
  112.                             if(b->depthBorderNorth)
  113.                                 DrawSpriteFromSheet(281, IMGObjectSheet, al_map_rgb(255,255,255), drawx + offset_x, drawy + offset_y );
  114.  
  115.                             //Western border
  116.                             if(b->depthBorderWest)
  117.                                 DrawSpriteFromSheet(280, IMGObjectSheet, al_map_rgb(255,255,255), drawx + offset_x, drawy + offset_y );
  118.  
  119.                             //drawy += (WALLHEIGHT);
  120.                         }
  121.                     }
  122.                     //draw_textf_border(font, al_map_rgb(255,255,255), drawx, drawy, 0, "%d,%d", fileindex, sheetindex);
  123.                 }
  124.             }
  125.         }
  126.     }
  127.     if(!subsprites.empty())
  128.     {
  129.         for(int i = 0; i < subsprites.size(); i++)
  130.         {
  131.             subsprites.at(i).draw_world_offset(x, y, z, b, tileoffset, chop);
  132.         }
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement