20231001 - Wen Hop - Spiral Particle System

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

It's been a "hot second" since I did anything with Wen Hop. Today I felt a little "recovered" and had a play with the code.
Previously, the particle system had a whole bunch of variables - x and y position, x and y speed, and this was fine for straight-line movement. But I had this idea of "spiral" movement, and that old system really didn't work well with that. So I changed it to use a vector (angle), and a distance. The x,y pixel position is calculated from those, so now it's easy to rotate and move particles around an origin. The effect isn't quite what I hoped for, but it does work, so that's what this video is showing.  The spiral of particles as you do various things.


Please do not upload/republish this binary on other sites/forums.

Andrew Davie

The code is surprisingly simple...

const int xsin[] = {
    0, 97, 181, 236, 256, 236, 181, 97, 0, -97, -181, -236, -256, -236, -181, -97,
};

const int xcos[] = {
    256, 236, 181, 97, 0, -97, -181, -236, -256, -236, -181, -97, 0, 97, 181, 236,
};

void drawParticles() {

    for (int i = 0; i < PARTICLE_COUNT; i++) {
        if (particleAge[i]) {

            --particleAge[i];

            int xOffset = (xsin[(particleDirection[i] >> 4) & 0xF] * particleDistance[i]) >> 16;
            int yOffset = (xcos[(particleDirection[i] >> 4) & 0xF] * particleDistance[i] * 3) >> 16;

            int y = (particleY[i] >> 8) + yOffset;
            int x = (particleX[i] >> 8) + xOffset;

            if (!drawBit(x, y))
                particleAge[i] = 0;

            particleDirection[i] += 8;
            particleDistance[i] += particleSpeedX[i];
        }
    }
}