View Single Post
Seren Seren's Avatar

JCF Member

Joined: Feb 2010

Posts: 864

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Jul 17, 2014, 11:07 AM
Seren is offline
Reply With Quote
Here's the kind of code I meant:
Code:
interface Iparticle {
	void draw(jjCANVAS@) const;
	bool process();
}
class Tsnowflake : Iparticle {
	private float x, y, xSpeed, ySpeed;
	private uint8 frame;
	private int deathCounter, noClipCounter, speedModifier;
	Tsnowflake(float xPos, float yPos) {
		x = xPos;
		y = yPos;
		uint random = jjRandom();
		xSpeed = -0.5f - (random & 4095) / 16384.f;
		ySpeed = ((random >>= 12) & 8191) / 4096.f;
		frame = (random >>= 13) & 7;
		deathCounter = 0;
		noClipCounter = 35;
		speedModifier = ((random >> 3) & 15) << 6;
	}
	void draw(jjCANVAS@ canvas) const override {
		canvas.drawSprite(int(x), int(y), ANIM::SNOW, 0, frame, 0, SPRITE::PALSHIFT, 16);
	}
	bool process() override {
		if (deathCounter == 0) {
			uint random = jjRandom();
			x += xSpeed += (int(random & 1023) - 511) / 65536.f + jjSin(jjGameTicks + speedModifier) / 128.f;
			y += ySpeed += ((random >> 16) & 1023) / 65536.f;
			if (noClipCounter > 0)
				noClipCounter--;
			else if (jjMaskedPixel(int(x), int(y)))
				deathCounter = 1;
		} else {
			if (++deathCounter & 7 == 0 && frame < 7)
				frame++;
			if (deathCounter > 70)
				return false;
		}
		for (int i = 0; i < jjLocalPlayerCount; i++) {
			const jjPLAYER@ player = jjLocalPlayers[i];
			if (x + 32 < player.cameraX || y + 32 < player.cameraY || x - 32 >= player.cameraX + jjSubscreenWidth || y - 32 >= player.cameraY + jjSubscreenHeight)
				continue;
			return true;
		}
		return false;
	}
}
array<Iparticle@> particles;
void addSnow() {
	for (int i = 0; i < jjLocalPlayerCount; i++) {
		const jjPLAYER@ player = jjLocalPlayers[i];
		uint random = jjRandom();
		float x = player.cameraX - 32 + player.xSpeed + ((random & 0xFFFF) * (jjResolutionWidth + 64) >> 16);
		float y = player.cameraY - 32 + (((random >> 16) & 0xFFFF) * jjResolutionHeight >> 16);
		particles.insertLast(Tsnowflake(x, y));
	}
}
void drawParticleSet(const array<Iparticle@> &in particleSet, jjCANVAS@ canvas) {
	for (uint i = 0; i < particleSet.length(); i++) {
		particleSet[i].draw(canvas);
	}
}
void processParticleSet(array<Iparticle@>& particleSet) {
	for (uint i = 0; i < particleSet.length();) {
		if (particleSet[i].process())
			i++;
		else
			particleSet.removeAt(i);
	}
}
void onDrawLayer4(jjPLAYER@, jjCANVAS@ canvas) {
	drawParticleSet(particles, canvas);
}
void onLevelLoad() {
	jjObjects[0].determineCurAnim(ANIM::SNOW, 0, false);
}
void onMain() {
	addSnow();
	processParticleSet(particles);
}
The number in red should be modified to the palshift parameter value you want to use. Notice this code doesn't require a snow event in the level.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.