SHARE
TWEET

KDS' Triple Layer Tile Implementation for Pokeemerald

Lunos May 18th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void DrawMetatile(s32 metatileLayerType, u16 *metatiles, u16 offset)
  2. {
  3.     switch (metatileLayerType)
  4.     {
  5.     case 3: // TRIPLE_LAYER
  6.         // Draw metatile's bottom layer to the bottom background layer.
  7.         gBGTilemapBuffers3[offset] = metatiles[0];
  8.         gBGTilemapBuffers3[offset + 1] = metatiles[1];
  9.         gBGTilemapBuffers3[offset + 0x20] = metatiles[2];
  10.         gBGTilemapBuffers3[offset + 0x21] = metatiles[3];
  11.  
  12.         // Draw metatile's top layer to the middle background layer..
  13.         gBGTilemapBuffers1[offset] = metatiles[4];;
  14.         gBGTilemapBuffers1[offset + 1] = metatiles[5];
  15.         gBGTilemapBuffers1[offset + 0x20] = metatiles[6];
  16.         gBGTilemapBuffers1[offset + 0x21] = metatiles[7];
  17.  
  18.         // Draw metatile's extra layer to the top background layer.
  19.         gBGTilemapBuffers2[offset] = metatiles[8];
  20.         gBGTilemapBuffers2[offset + 1] = metatiles[9];
  21.         gBGTilemapBuffers2[offset + 0x20] = metatiles[10];
  22.         gBGTilemapBuffers2[offset + 0x21] = metatiles[11];
  23.         break;        
  24.     case 2: // LAYER_TYPE_
  25.         // Draw metatile's bottom layer to the bottom background layer.
  26.         gBGTilemapBuffers3[offset] = metatiles[0];
  27.         gBGTilemapBuffers3[offset + 1] = metatiles[1];
  28.         gBGTilemapBuffers3[offset + 0x20] = metatiles[2];
  29.         gBGTilemapBuffers3[offset + 0x21] = metatiles[3];
  30.  
  31.         // Draw transparent tiles to the middle background layer.
  32.         gBGTilemapBuffers1[offset] = 0;
  33.         gBGTilemapBuffers1[offset + 1] = 0;
  34.         gBGTilemapBuffers1[offset + 0x20] = 0;
  35.         gBGTilemapBuffers1[offset + 0x21] = 0;
  36.  
  37.         // Draw metatile's top layer to the top background layer.
  38.         gBGTilemapBuffers2[offset] = metatiles[4];
  39.         gBGTilemapBuffers2[offset + 1] = metatiles[5];
  40.         gBGTilemapBuffers2[offset + 0x20] = metatiles[6];
  41.         gBGTilemapBuffers2[offset + 0x21] = metatiles[7];
  42.         break;
  43.     case 1:  // LAYER_TYPE_COVERED_BY_OBJECTS
  44.         // Draw metatile's bottom layer to the bottom background layer.
  45.         gBGTilemapBuffers3[offset] = metatiles[0];
  46.         gBGTilemapBuffers3[offset + 1] = metatiles[1];
  47.         gBGTilemapBuffers3[offset + 0x20] = metatiles[2];
  48.         gBGTilemapBuffers3[offset + 0x21] = metatiles[3];
  49.  
  50.         // Draw metatile's top layer to the middle background layer.
  51.         gBGTilemapBuffers1[offset] = metatiles[4];
  52.         gBGTilemapBuffers1[offset + 1] = metatiles[5];
  53.         gBGTilemapBuffers1[offset + 0x20] = metatiles[6];
  54.         gBGTilemapBuffers1[offset + 0x21] = metatiles[7];
  55.  
  56.         // Draw transparent tiles to the top background layer.
  57.         gBGTilemapBuffers2[offset] = 0;
  58.         gBGTilemapBuffers2[offset + 1] = 0;
  59.         gBGTilemapBuffers2[offset + 0x20] = 0;
  60.         gBGTilemapBuffers2[offset + 0x21] = 0;
  61.         break;
  62.     case 0: // LAYER_TYPE_NORMAL
  63.         // Draw garbage to the bottom background layer.
  64.         gBGTilemapBuffers3[offset] = 0x3014;
  65.         gBGTilemapBuffers3[offset + 1] = 0x3014;
  66.         gBGTilemapBuffers3[offset + 0x20] = 0x3014;
  67.         gBGTilemapBuffers3[offset + 0x21] = 0x3014;
  68.  
  69.         // Draw metatile's bottom layer to the middle background layer.
  70.         gBGTilemapBuffers1[offset] = metatiles[0];
  71.         gBGTilemapBuffers1[offset + 1] = metatiles[1];
  72.         gBGTilemapBuffers1[offset + 0x20] = metatiles[2];
  73.         gBGTilemapBuffers1[offset + 0x21] = metatiles[3];
  74.  
  75.         // Draw metatile's top layer to the top background layer, which covers event object sprites.
  76.         gBGTilemapBuffers2[offset] = metatiles[4];
  77.         gBGTilemapBuffers2[offset + 1] = metatiles[5];
  78.         gBGTilemapBuffers2[offset + 0x20] = metatiles[6];
  79.         gBGTilemapBuffers2[offset + 0x21] = metatiles[7];
  80.         break;
  81.     }
  82.     schedule_bg_copy_tilemap_to_vram(1);
  83.     schedule_bg_copy_tilemap_to_vram(2);
  84.     schedule_bg_copy_tilemap_to_vram(3);
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top