Downloads containing PipeDreamExample.j2as

Downloads
Name Author Game Mode Rating
JJ2+ Only: Pipe DreamFeatured Download Obi1mcd Tileset 8.8 Download file

File preview

//Yeah I'm just going to apologise in advance for the likely scenario of this not being ideal angelscript
//Deadlines and such.

jjPAL initialPalette;

float liquidPoolGlowProgress = 0;
float rocksGlowProgress = 0;
float crystalGlowProgress = 0;
float cloudGlowProgress = 0;
 
int liquidPoolRippleProgress = 0;
int crystalRippleProgress = 0;
int cloudRippleProgress = 0;
 
bool liquidGlowing = true;
bool rocksGlowing = true;
bool crystalGlowing = true;
bool cloudGlowing = true;

void onLevelLoad() {
	
	//Store the initial palette for the stage
	//Could use jjBackupPalette for this one but if you change the palette beforehand then you'd want this I assume
	initialPalette = jjPalette;
	
	//Set the water gradient to the default values
	jjSetWaterGradient();
	
	jjSetWaterLevel(2464, true);
	
	jjWaterLayer = 3;
	
}

void onMain() {
	
	//Every other tick cycle the liquid section of the palette
	//There is probably a far better way to do timing but I sort of ran out of time before the contest deadline.
	if (jjGameTicks % 2 == 1) {
		
		cycleLiquid();
		
	}
	
	if (jjGameTicks % 8 == 1) {
	
		liquidPoolGlow();
	}
	
	if (jjGameTicks % 4 == 1) {
	
        crystalGlow();
	}
	
	//Rock glowing disabled because it looks bad
	/*
	if (jjGameTicks % 2 == 1) {
	
        rocksGlow();
	}
	*/
	
	if (jjGameTicks % 4 == 1) {
	
        liquidPoolRipple();
	}
 
	if (jjGameTicks % 4 == 1) {
	
        crystalRipple();
	}
 
	if (jjGameTicks % 4 == 1) {
	
        cloudsGlow();
	}
	
	//Trigger crates tied to water level
	if (jjTriggers[1] && jjWaterLevel > 1952) {
		jjSetWaterLevel(1952, false);
	}
	
	if (jjTriggers[2] && jjWaterLevel > 960) {
	jjSetWaterLevel(960, false);
	}
 
}

void cycleLiquid() {
	
	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	//The liquid colours range from 208-223. See PipeDreamREADME.txt for all the palette stuff
	
	//Grab the last 15 colours from the main palette and shift them one spot to the left in the new one
	newPal.copyFrom(208, 15, 209, jjPalette, 1.0);
	
	//Then grab the first colour from the old palette and put it in the last spot
	newPal.copyFrom(223, 1, 208, jjPalette, 1.0);
	
	newPal.apply();
	
}

void liquidPoolGlow() {

	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	//Random number; very arbitrary, used for opacity, should be less than 1. Higher it is the faster the glow is
	float random = ((jjRandom()%3) + 1)/ 20.0;
	
	//If we're going from default colours to bright
	if (liquidGlowing) {
		
		//Apply the brightened colour at a random rate
		newPal.gradient(245, 135, 245, 77, 13, 77, 128, 8, random);

		liquidPoolGlowProgress += random;

		if (liquidPoolGlowProgress >= 1) {
		
			liquidGlowing = false;
			liquidPoolGlowProgress = 0;
		}
		
		newPal.apply();
	}
	else {
 
		//Copy the default colours for the set back at a random opacity
		newPal.copyFrom(128, 8, 128, initialPalette, random);

		liquidPoolGlowProgress += random;

		if (liquidPoolGlowProgress >= 1) {
		
			liquidGlowing = true;
			liquidPoolGlowProgress = 0;
		}
		
		newPal.apply();
	}
}

void crystalGlow() {
	
	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	//Random number; very arbitrary, used for opacity, should be less than 1. Higher it is the faster the glow is
	float random = ((jjRandom()%3) + 1)/ 20.0;
	
	//If we're going from default colours to bright
	if (crystalGlowing) {
		
		//Apply the brightened colour at a random rate
		newPal.gradient(0, 255, 19, 0, 130, 19, 104, 8, random);

		crystalGlowProgress += random;

		if (crystalGlowProgress >= 1) {
		
			crystalGlowing = false;
			crystalGlowProgress = 0;
		}
		
		newPal.apply();
	}
	else {
 
		//Copy the default colours for the set back at a random opacity
		newPal.copyFrom(104, 8, 104, initialPalette, random);

		crystalGlowProgress += random;

		if (crystalGlowProgress >= 1) {
		
			crystalGlowing = true;
			crystalGlowProgress = 0;
		}
		
		newPal.apply();
	}
}

void rocksGlow() {
	
	//If you uncomment this the rocks will glow, but it looks kind of terrible to have absolutely everything glowing
	/*
	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	//Random number; very arbitrary, used for opacity, should be less than 1. Higher it is the faster the glow is
	float random = ((jjRandom()%3) + 1)/ 20.0;
	
	//If we're going from default colours to bright
	if (rocksGlowing) {
		
		//Apply the brightened colour at a random rate
		newPal.gradient(52, 202, 45, 86, 38, 86, 136, 8, random);

		rocksGlowProgress += random;

		if (rocksGlowProgress >= 1) {
		
			rocksGlowing = false;
			rocksGlowProgress = 0;
		}
		
		newPal.apply();
	}
	else {
 
		//Copy the default colours for the set back at a random opacity
		newPal.copyFrom(136, 8, 136, initialPalette, random);

		rocksGlowProgress += random;

		if (rocksGlowProgress >= 1) {
		
			rocksGlowing = true;
			rocksGlowProgress = 0;
		}
		
		newPal.apply();
	}
	*/
}

void cloudsGlow() {
	
	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	//Random number; very arbitrary, used for opacity, should be less than 1. Higher it is the faster the glow is
	float random = ((jjRandom()%3) + 1)/ 30.0;
	
	//If we're going from default colours to bright
	if (cloudGlowing) {
		
		//Apply the brightened colour at a random rate
		newPal.gradient(238, 70, 238, 30, 4, 30, 176, 32, random);

		cloudGlowProgress += random;

		if (cloudGlowProgress >= 1) {
		
			cloudGlowing = false;
			cloudGlowProgress = 0;
		}
		
		newPal.apply();
	}
	else {
 
		//Copy the default colours for the set back at a random opacity
		newPal.copyFrom(176, 32, 176, initialPalette, random);

		cloudGlowProgress += random;

		if (cloudGlowProgress >= 1) {
		
			cloudGlowing = true;
			cloudGlowProgress = 0;
		}
		
		newPal.apply();
	}
}

void liquidPoolRipple() {
	
	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	if (liquidPoolRippleProgress == 0) {
	
		//Random number, chance of a ripple effect starting per tick
		int random = (jjRandom()%100);
		
		if (random == 1) {
		
			newPal.copyFrom(128, 6, 128, initialPalette, 1.0);

			newPal.fill(255, 255, 255, 128 + liquidPoolRippleProgress, 1, 0.25);
			
			liquidPoolRippleProgress++;
			
			newPal.apply();
		}
	}
	else {
	
		newPal.copyFrom(128, 6, 128, initialPalette, 1.0);

		newPal.fill(255, 255, 255, 128 + liquidPoolRippleProgress, 1, 0.25);
		
		liquidPoolRippleProgress++;
		
		if (liquidPoolRippleProgress >= 6) {
		
			liquidPoolRippleProgress = 0;
			
			newPal.copyFrom(128, 6, 128, initialPalette, 1.0);
		
		}
		
		newPal.apply();
		
	}
}

void crystalRipple() {
	//Make a temporary palette
	jjPAL newPal = jjPalette;
	
	if (crystalRippleProgress == 0) {
	
		//Random number, chance of a ripple effect starting per tick
		int random = (jjRandom()%50);
		
		if (random == 1) {
		
			newPal.copyFrom(105, 6, 105, initialPalette, 1.0);

			newPal.fill(255, 255, 255, 105 + crystalRippleProgress, 1, 0.25);
			
			crystalRippleProgress++;
			
			newPal.apply();
		}
	}
	else {
	
		newPal.copyFrom(105, 6, 105, initialPalette, 1.0);

		newPal.fill(255, 255, 255, 105 + crystalRippleProgress, 1, 0.25);
		
		crystalRippleProgress++;
		
		if (crystalRippleProgress >= 6) {
		
			crystalRippleProgress = 0;
			
			newPal.copyFrom(105, 6, 105, initialPalette, 1.0);
		
		}
		
		newPal.apply();
		
	}
}