Downloads containing SmokeBossUtilsV1.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Holiday Hare 24Featured Download PurpleJazz Single player 10 Download file

File preview

class RandomArray
{
    array<int> @_arr;
    int _n;
    int _currN;

    RandomArray(int n)
    {
        _n = n;
        _currN = n - 1;
        array<int> arrayAssign(n);

        @_arr = @arrayAssign;

        Reset();
    }

private
    void Reset()
    {
        for (int i = 0; i < _n; i++)
        {
            _arr[i] = i;
        }
    }

    int GetNumber()
    {

        if (_currN == -1)
        {
            _currN = _n - 1;
            Reset();
        }

        uint randNum = jjRandom();
        // Careful with modulo operator mixing signed and unsigned, compiler doesn't seem to give warning
        uint randIdx = randNum % uint(_currN + 1);

        int outNum = _arr[randIdx];

        int tmp = _arr[_currN];
        _arr[_currN] = _arr[randIdx];
        _arr[randIdx] = tmp;

        _currN--;

        return outNum;
    }
}

class SyncTimer
{
    int _t;
    int _off;
    int _dur;
    int _outReady;
    bool isReady(bool active)
    {
        if (!active || _t == -1)
            return false;
        _t++;
        if (_t >= _off && _t - _off < _dur)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    SyncTimer(int dur, bool started = false, int off = 0, int outReady = -1)
    {
        _t = started ? 0 : -1;
        _off = off;
        _dur = dur;
        _outReady = outReady;
    }

    void reset()
    {
        _t = 0;
    }

    int GetNextState()
    {
        return _outReady;
    }

    bool JustFinished()
    {
        return _t - _off == _dur;
    }
}

bool
GoTo(float objx1, float objy1, float &out objx, float &out objy,
     float Startx, float Starty, float Endx, float Endy, float Speed,
     float Behind)
{
    float angle = atan2((Endx - Startx), (Endy - Starty));
    objx1 += sin(angle) * Speed;
    objy1 += cos(angle) * Speed;
    objx = objx1;
    objy = objy1;
    if (((Endx + Behind * sin(angle) - objx1) *
             (Endx + Behind * sin(angle) - objx1) +
         (Endy + Behind * cos(angle) - objy1) *
             (Endy + Behind * cos(angle) - objy1)) <
        (Speed * 1.1 + 3) * (Speed * 1.1 + 3))
        return true; // arrived to destination
    else
        return false; // not arrived to destination
}

bool GoArc(float objx1, float objy1, float & out objx, float & out objy, float Startx, float Starty, float Endx, float Endy, float Speed, float Behind) {
	float Vectx1 = Endx - Startx;
	float Vecty1 = Endy - Starty;
	float Unitx1 = Vectx1 / sqrt(Vectx1 * Vectx1 + Vecty1 * Vecty1);
	float Unity1 = Vecty1 / sqrt(Vectx1 * Vectx1 + Vecty1 * Vecty1);
	float Vectx = (Endx )  - objx1;
	float Vecty = (Endy) - objy1;
	float Unitx = -Vecty / sqrt(Vectx * Vectx + Vecty * Vecty);
	float Unity = Vectx / sqrt(Vectx * Vectx + Vecty * Vecty);
	objx1 += Unitx * Speed;
	objy1 += Unity * Speed;
	objx = objx1;
	objy = objy1;
	if ((Endx + Behind * Unitx1 - objx1) * (Endx + Behind * Unitx1 - objx1) + (Endy + Behind * Unity1 - objy1) * (Endy + Behind * Unity1 - objy1) < (Speed * 3) * (Speed * 3))
		return true;
	else return false;
}