Home | History | Annotate | Download | only in raw
      1 // Fountain test script
      2 
      3 #pragma version(1)
      4 #pragma stateVertex(orthoWindow)
      5 #pragma stateRaster(flat)
      6 #pragma stateFragment(PgmFragBackground)
      7 #pragma stateStore(MyBlend)
      8 
      9 
     10 int main(void* con, int ft, int launchID) {
     11     int count, touch, x, y, rate, maxLife, lifeShift;
     12     int life;
     13     int ct, ct2;
     14     int newPart;
     15     int drawCount;
     16     int dx, dy, idx;
     17     int posx,posy;
     18     int c;
     19     int srcIdx;
     20     int dstIdx;
     21 
     22     count = loadI32(con, 0, 1);
     23     touch = loadI32(con, 0, 2);
     24     x = loadI32(con, 0, 3);
     25     y = loadI32(con, 0, 4);
     26 
     27     rate = 4;
     28     maxLife = (count / rate) - 1;
     29     lifeShift = 0;
     30     {
     31         life = maxLife;
     32         while (life > 255) {
     33             life = life >> 1;
     34             lifeShift ++;
     35         }
     36     }
     37 
     38     drawRect(con, 0, 256, 0, 512);
     39     contextBindProgramFragment(con, NAMED_PgmFragParts);
     40 
     41     if (touch) {
     42         newPart = loadI32(con, 2, 0);
     43         for (ct2=0; ct2<rate; ct2++) {
     44             dx = scriptRand(con, 0x10000) - 0x8000;
     45             dy = scriptRand(con, 0x10000) - 0x8000;
     46 
     47             idx = newPart * 5 + 1;
     48             storeI32(con, 2, idx, dx);
     49             storeI32(con, 2, idx + 1, dy);
     50             storeI32(con, 2, idx + 2, maxLife);
     51             storeI32(con, 2, idx + 3, x << 16);
     52             storeI32(con, 2, idx + 4, y << 16);
     53 
     54             newPart++;
     55             if (newPart >= count) {
     56                 newPart = 0;
     57             }
     58         }
     59         storeI32(con, 2, 0, newPart);
     60     }
     61 
     62     drawCount = 0;
     63     for (ct=0; ct < count; ct++) {
     64         srcIdx = ct * 5 + 1;
     65 
     66         dx = loadI32(con, 2, srcIdx);
     67         dy = loadI32(con, 2, srcIdx + 1);
     68         life = loadI32(con, 2, srcIdx + 2);
     69         posx = loadI32(con, 2, srcIdx + 3);
     70         posy = loadI32(con, 2, srcIdx + 4);
     71 
     72         if (life) {
     73             if (posy < (480 << 16)) {
     74                 dstIdx = drawCount * 9;
     75                 c = 0xffafcf | ((life >> lifeShift) << 24);
     76 
     77                 storeU32(con, 1, dstIdx, c);
     78                 storeI32(con, 1, dstIdx + 1, posx);
     79                 storeI32(con, 1, dstIdx + 2, posy);
     80 
     81                 storeU32(con, 1, dstIdx + 3, c);
     82                 storeI32(con, 1, dstIdx + 4, posx + 0x10000);
     83                 storeI32(con, 1, dstIdx + 5, posy + dy * 4);
     84 
     85                 storeU32(con, 1, dstIdx + 6, c);
     86                 storeI32(con, 1, dstIdx + 7, posx - 0x10000);
     87                 storeI32(con, 1, dstIdx + 8, posy + dy * 4);
     88                 drawCount ++;
     89             } else {
     90                 if (dy > 0) {
     91                     dy = (-dy) >> 1;
     92                 }
     93             }
     94 
     95             posx = posx + dx;
     96             posy = posy + dy;
     97             dy = dy + 0x400;
     98             life --;
     99 
    100             //storeI32(con, 2, srcIdx, dx);
    101             storeI32(con, 2, srcIdx + 1, dy);
    102             storeI32(con, 2, srcIdx + 2, life);
    103             storeI32(con, 2, srcIdx + 3, posx);
    104             storeI32(con, 2, srcIdx + 4, posy);
    105         }
    106     }
    107 
    108     drawTriangleArray(con, NAMED_PartBuffer, drawCount);
    109     return 1;
    110 }
    111