summaryrefslogtreecommitdiffstats
path: root/libs/rs/java/Fountain/res/raw/fountain.c
blob: 8b473abb73601cbd3c6d357d4aff714a09b419ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Fountain test script

int main(void* con, int ft, int launchID) {
    int count, touch, x, y, rate, maxLife, lifeShift;
    int life;
    int ct, ct2;
    int newPart;
    int drawCount;
    int dx, dy, idx;
    int posx,posy;
    int c;
    int srcIdx;
    int dstIdx;

    count = loadI32(con, 0, 1);
    touch = loadI32(con, 0, 2);
    x = loadI32(con, 0, 3);
    y = loadI32(con, 0, 4);

    rate = 4;
    maxLife = (count / rate) - 1;
    lifeShift = 0;
    {
        life = maxLife;
        while (life > 255) {
            life = life >> 1;
            lifeShift ++;
        }
    }

    contextBindProgramFragment(con, loadI32(con, 0, 7));
    drawRect(con, 0, 256, 0, 512);
    contextBindProgramFragment(con, loadI32(con, 0, 6));

    if (touch) {
        newPart = loadI32(con, 2, 0);
        for (ct2=0; ct2<rate; ct2++) {
            dx = scriptRand(con, 0x10000) - 0x8000;
            dy = scriptRand(con, 0x10000) - 0x8000;

            idx = newPart * 5 + 1;
            storeI32(con, 2, idx, dx);
            storeI32(con, 2, idx + 1, dy);
            storeI32(con, 2, idx + 2, maxLife);
            storeI32(con, 2, idx + 3, x << 16);
            storeI32(con, 2, idx + 4, y << 16);

            newPart++;
            if (newPart >= count) {
                newPart = 0;
            }
        }
        storeI32(con, 2, 0, newPart);
    }

    drawCount = 0;
    for (ct=0; ct < count; ct++) {
        srcIdx = ct * 5 + 1;

        dx = loadI32(con, 2, srcIdx);
        dy = loadI32(con, 2, srcIdx + 1);
        life = loadI32(con, 2, srcIdx + 2);
        posx = loadI32(con, 2, srcIdx + 3);
        posy = loadI32(con, 2, srcIdx + 4);

        if (life) {
            if (posy < (480 << 16)) {
                dstIdx = drawCount * 9;
                c = 0xffafcf | ((life >> lifeShift) << 24);

                storeU32(con, 1, dstIdx, c);
                storeI32(con, 1, dstIdx + 1, posx);
                storeI32(con, 1, dstIdx + 2, posy);

                storeU32(con, 1, dstIdx + 3, c);
                storeI32(con, 1, dstIdx + 4, posx + 0x10000);
                storeI32(con, 1, dstIdx + 5, posy + dy * 4);

                storeU32(con, 1, dstIdx + 6, c);
                storeI32(con, 1, dstIdx + 7, posx - 0x10000);
                storeI32(con, 1, dstIdx + 8, posy + dy * 4);
                drawCount ++;
            } else {
                if (dy > 0) {
                    dy = (-dy) >> 1;
                }
            }

            posx = posx + dx;
            posy = posy + dy;
            dy = dy + 0x400;
            life --;

            //storeI32(con, 2, srcIdx, dx);
            storeI32(con, 2, srcIdx + 1, dy);
            storeI32(con, 2, srcIdx + 2, life);
            storeI32(con, 2, srcIdx + 3, posx);
            storeI32(con, 2, srcIdx + 4, posy);
        }
    }

    drawTriangleArray(con, loadI32(con, 0, 5), drawCount);
    return 1;
}