Advertisement
Guest User

Cylindrical scroller effect - SGDK

a guest
Dec 16th, 2012
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.86 KB | None | 0 0
  1. #include "effect_cylinder.h"
  2.  
  3. void EFFECT_cylinder(int sens, int speed, int length)
  4. {
  5.     u16 j = 0;
  6.     u16* scrollTable;
  7.     u16 curY;
  8.     int curX;
  9.     u16 ttt=0;
  10.     int vscroll;
  11.     u16 scr = 0;
  12.  
  13.     void initTable()
  14.     {
  15.         scrollTable = (u16*)MEM_alloc(21*42*sizeof(u16));
  16.         vscroll=0x840;
  17.         int k, h;
  18.         int center = 12;
  19.         for (k=0 ; k<42 ; ++k)
  20.         {
  21.             int count = (k*k)*0.02f;
  22.             for (h=0 ; h<21 ; ++h)
  23.             {
  24.                 int xv;
  25.                 if (k<center) xv = (h-10)*(h-10)*((center-k)*(center-k))*0.004;
  26.                 else xv = -(h-10)*(h-10)*((k-center)*(k-center))*0.004;
  27.                 scrollTable[k*21+h] = 0x840-count+xv;
  28.             }
  29.         }
  30.     }
  31.  
  32.     int posY = 0;
  33.     u16* scrollData = NULL;
  34.  
  35.     void vblank()
  36.     {
  37.         ++ttt;
  38.         curY = 0;
  39.         posY += sens*speed;
  40.        
  41.         scrollData = scrollTable;
  42.     }
  43.  
  44.     void hblank()
  45.     {
  46.         vu16 *pw = (u16 *) GFX_DATA_PORT;
  47.         vu32 *pl = (u32 *) GFX_CTRL_PORT;
  48.         int val = -posY-ttt/4;
  49.        
  50.         int x;
  51.         for (x=0 ; x<21 ; ++x)
  52.         {
  53.             u16 addr = (x&0x1F)*4;
  54.             *pl = GFX_WRITE_VSRAM_ADDR(addr);
  55.             *pw = val+scrollData[x];
  56.             *pl = GFX_WRITE_VSRAM_ADDR(addr+2);
  57.             *pw = val/2+scrollData[x];
  58.         }
  59.        
  60.         scrollData += 21;
  61.         curY++;
  62.     }
  63.  
  64.     GSKE_setScrollMode(GSKE_HSCROLL_Plane, GSKE_VSCROLL_Column);
  65.    
  66.     initTable();
  67.    
  68.     u32 start = SND_getTime_PCM();
  69.    
  70.     int xs=0, ys=0;
  71.    
  72.     u16 w = cylinder[0];
  73.     u16 h = cylinder[1];
  74.     VDP_setPalette(PAL2, &cylinder[2]);
  75.     VDP_loadBMPTileData((u32*) &cylinder[18], 1, w / 8, h / 8, w/8 );
  76.     for (ys=0 ; ys<VDP_getPlanHeight()/(h/8); ++ys)
  77.     for (xs=0 ; xs<VDP_getPlanWidth()/(w/8); ++xs)
  78.         VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL2, 0, 0, 0, 1), xs*(w/8), ys*(h/8), w/8, h/8);
  79.    
  80.     w = cylinder_back[0];
  81.     h = cylinder_back[1];
  82.     VDP_setPalette(PAL1, &cylinder_back[2]);
  83.     VDP_loadBMPTileData((u32*) &cylinder_back[18], 257, w / 8, h / 8, w/8 );
  84.     for (ys=0 ; ys<VDP_getPlanHeight()/(h/8); ++ys)
  85.     for (xs=0 ; xs<VDP_getPlanWidth()/(w/8); ++xs)
  86.         VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, 257), xs*(w/8), ys*(h/8), w/8, h/8);
  87.        
  88.     SYS_setVIntCallback(vblank);
  89.     SYS_setHIntCallback(hblank);
  90.     VDP_setHIntCounter(1);
  91.     VDP_setHInterrupt(1);
  92.    
  93.     curY = 0;
  94.    
  95.     u32 t=0;
  96.     do
  97.     {
  98.         u32 ct = SND_getTime_PCM();
  99.         if (ct>start) t = ct-start;
  100.        
  101.         VDP_setHorizontalScroll(APLAN, 0, sinFix16(t*speed/20)*2);
  102.         VDP_setHorizontalScroll(BPLAN, 0, sinFix16(t*speed/20)*2);
  103.     }
  104.     while(t<length);
  105.    
  106.     SYS_setVIntCallback(0);
  107.     SYS_setHIntCallback(0);
  108.     MEM_free(scrollTable);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement