Downloads containing blgsand2night.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Sand CastleFeatured Download Rysice Capture the flag 9 Download file

File preview

const bool MLLESetupSuccessful = MLLE::Setup(); ///@MLLE-Generated
#include "MLLE-Include-1.5.asc" ///@MLLE-Generated
#pragma require "blgsand2night-MLLE-Data-1.j2l" ///@MLLE-Generated
#pragma require "Damn1.j2t" ///@MLLE-Generated
#pragma require "blgsand2night.j2l" ///@MLLE-Generated
array<CustomParticle> particles2(255);
array<Fish@> fishCount;
array<int> crabs(5);
bool crabPacketIsSent = false;
enum packet_type {crabPacket};

// Author Input
int fishLimit = 8; // This is the biggest amount of fish you may possibly see on-screen,edit this however you want (negative values are treated as "infinite").
int colorEndFade = 15; // This is highest amount of how much the textured background will shift it's colors (originalRGB + colorEndFade)
// Author input

void onLevelLoad() {
	jjUseLayer8Speeds = true;
	jjLayers[2].spriteMode = SPRITE::BLEND_NORMAL;
	jjLayers[2].spriteParam = 255;
	jjAnimSets[ANIM::FISH].load();
	jjObjectPresets[OBJECT::CRAB].scriptedCollisions = true;
	jjObjectPresets[OBJECT::CRAB].playerHandling = HANDLING::SPECIAL;
	jjObjectPresets[OBJECT::CRAB].isTarget = false;
	jjObjectPresets[OBJECT::CRAB].isBlastable = false;
	jjObjectPresets[OBJECT::CRAB].triggersTNT = false;
	jjObjectPresets[OBJECT::CRAB].isFreezable = false; 
	jjObjectPresets[OBJECT::CRAB].bulletHandling = HANDLING::IGNOREBULLET;
	jjObjectPresets[OBJECT::CRAB].behavior = Crab();
	flagSprite();
	//coloredBridge();
}

void onLevelReload() {
	crabPacketIsSent = false;
}

void onReceive(jjSTREAM &in packet, int clientID) {
	uint8 type;	
	packet.pop(type);
	if (jjIsServer) {
		switch (type) {
			case crabPacket: {
				array<int> crabColor(5);
				jjSTREAM replyPacket;
				replyPacket.push(uint8(crabPacket));
				for (int i = 0;i < 5;i++) {
					crabColor[i] = jjObjects[crabs[i]].var[0];
					replyPacket.push(crabColor[i]);
				}
				jjSendPacket(replyPacket, clientID);
			}	
			break;
		}
	}  else {
		switch (type) {
			case crabPacket: {
				array<int> crabColor(5);
				for (int i = 0;i < 5;i++) {
					packet.pop(crabColor[i]);
					jjObjects[crabs[i]].var[0] = crabColor[i];
				}
			}
			break;	
		}
	}
 }
 
void flagSprite() {
	jjANIMATION@ flag = jjAnimations[jjObjectPresets[OBJECT::CTFBASE].curAnim];
	jjANIMATION@ apple = jjAnimations[jjAnimSets[ANIM::PICKUPS].firstAnim + 78];
	apple.frameCount = flag.frameCount;
	for (uint i = 0; i < flag.frameCount; ++i) {
		jjANIMFRAME@ frame = jjAnimFrames[flag + i];
		jjANIMFRAME@ frame2 = jjAnimFrames[apple + i];
		frame2.coldSpotX = frame.coldSpotX;
		frame2.coldSpotY = frame.coldSpotY;
		frame2.hotSpotX = frame.hotSpotX;
		frame2.hotSpotY = frame.hotSpotY;
		jjPIXELMAP image(frame);
		for (uint x = 0; x < image.width; ++x)
			for (uint y = 0; y < image.height; ++y)
				if (image[x,y] & ~7 == 24)
					image[x,y] = 160 + ((image[x,y] & 7)*2);
		image.save(frame2);
	}
}

void coloredBridge() {
	jjANIMATION@ bridge = jjAnimations[jjAnimSets[ANIM::BRIDGE].firstAnim + 1];
	for (uint i = 0; i < bridge.frameCount; ++i) {
		jjANIMFRAME@ frame = jjAnimFrames[bridge + i];
		jjPIXELMAP image(frame);
		for (uint x = 0; x < image.width; ++x)
			for (uint y = 0; y < image.height; ++y)
				if (image[x,y] & ~7 == 64)
					image[x,y] = 96 + ((image[x,y] & 7));
		image.save(frame);
	}
}
void onPlayer(jjPLAYER@ play) {
	if (play.yPos >= 0) {
		int skill = jjParameterGet(uint16(play.xPos/32), uint16(play.yPos/32), -4, 2);
		int event = jjEventGet(uint16(play.xPos/32), uint16(play.yPos/32));
		if (skill == 3 && event != 196) {
			if (jjLayers[2].spriteParam > 64) {
				jjLayers[2].spriteParam = jjLayers[2].spriteParam - 10;
			}
		}
		else if (jjLayers[2].spriteParam != 255) {
			jjLayers[2].spriteParam = jjLayers[2].spriteParam + 10;
		}
	}
}

int fishID = 0;
void spawnFish() {
	int fishNR = availableFish();
	if (fishNR != -1) {
		Fish@ fish = fishCount[fishNR];
		bool rightNew = (jjRandom() % 2 == 0? false : true);
		fish.right = rightNew;
		fish.xPos = (rightNew ? 0 : (fish.deadEnd));
		fish.distance = int(jjRandom() % 35);
		fish.xSpeed = 0.1;
		fish.color = int(jjRandom() % 8)*8;
		fish.active = true;
	} else {
		if (fishID < fishLimit || fishLimit < 0) {
			Fish newFish;
			newFish.id = fishID;
			fishCount.insertLast(@newFish);
			fishID++;
		}
	}
}


int originalRed = jjGetFadeColors().red;
int originalGreen = jjGetFadeColors().green;
int originalBlue = jjGetFadeColors().blue;

void animateSun() {
	array<int> RGB = {0,0,0};
	array<int> oRGB = {originalRed,originalGreen,originalBlue};
	for (int i = 0;i < 3;i++) {
		RGB[i] = oRGB[i] + int(abs(jjCos((jjGameTicks) % 1024)*colorEndFade));
		if (RGB[i] < 0) {
			RGB[i] = 0;
		} else
		if (RGB[i] > 255) {
		RGB[i] = 255;
		}
	}
	jjSetFadeColors(RGB[0],RGB[1],RGB[2]);
}
void onMain() {
	if (jjGameTicks % 10 == 0) {
		if (jjRandom() % 100 > 90) {
			spawnFish();
		}
	}
	
	 animateSun();
	
	if (jjGameTicks > 70 && !crabPacketIsSent) {
		int crab = 0;
		for (int i = 0;i < jjObjectCount;i++) {
			jjOBJ@ o = jjObjects[i];
			if (o.eventID == OBJECT::CRAB) {
				crabs[crab] = o.objectID;
				crab++;
			}
		}
		if (!jjIsServer) {
			jjSTREAM packet;
			packet.push(uint8(crabPacket));
			jjSendPacket(packet);
		}
		crabPacketIsSent = true;
	}
	for (int i = 0;i < int(particles2.length - 1);i++) {
		CustomParticle@ particle = particles2[i];
		particle.running();
	}
	if (jjGameTicks % 70 == 0) {		
		int random1 = (jjRandom() % 10); 
		int random2 = (jjRandom() % 6);
		int random3 = (jjRandom() % 12);
		int random4 = (jjRandom() % 15);
		int random5 = (jjRandom() % 4);
		int random9 = (jjRandom() % 8);
		int offset = (jjRandom() % 32);
		array<int> locations1y	= {68,68,68,71,71,72,72,72,72,72};
		array<int> locations3y	= {58,58,58,58,58,58,56,56,56,56,56,56};
		array<int> locations4y	= {56,56,56,56,57,58,58,58,57,57,57,57,57,57,57};
		array<int> locations5x	= {114,115,115,116};
		spawnCustomParticles(30*32 - offset + (random1*32),locations1y[random1]*32,0,0.5,5);
		spawnCustomParticles(61*32 - offset + (random2*32),59*32,0,0.5,5);
		spawnCustomParticles(74*32 - offset + (random3*32),locations3y[random3]*32,0,0.5,5);
		spawnCustomParticles(84*32 - offset + (random4*32),locations4y[random4]*32,0,0.5,5);
		spawnCustomParticles(locations5x[random5]*32 - offset,(57*32) - (random5*32),0,0.5,5);
		spawnCustomParticles(152*32 + (random1*32) - offset,58*32,0,0.5,5);
		spawnCustomParticles(76*32 + ((jjRandom() % 9)*32) - offset,67*32,0,0.5,5);
		spawnCustomParticles(104*32 + ((jjRandom() % 13)*32) - offset,70*32,0,0.5,5);
		spawnCustomParticles(124*32 + ((jjRandom() % 8)*32) - offset,73*32,0,0.5,5);
		spawnCustomParticles(141*32 + (random9*32) - offset,69*32 - 16,0,0.5,5);
	}
}

void onDrawLayer4(jjPLAYER@ player, jjCANVAS@ canvas) {
	canvas.drawResizedSprite(34*32 - 4,57*32 - 5,ANIM::PICKUPS,78,(jjGameTicks % (8*10)/10),5,5,SPRITE::TINTED);
	canvas.drawResizedSprite(63*32 - 4,55*32 - 5,ANIM::PICKUPS,78,(jjGameTicks % (8*10)/10),4,3.8,SPRITE::TINTED);
	canvas.drawResizedSprite(108*32 - 4,38*32 - 5,ANIM::PICKUPS,78,(jjGameTicks % (8*10)/10),6.3,4.5,SPRITE::TINTED);
	canvas.drawResizedSprite(156*32 - 4,52*32 - 5,ANIM::PICKUPS,78,(jjGameTicks % (8*10)/10),5,4,SPRITE::TINTED);
}

void onDrawLayer7(jjPLAYER@ player, jjCANVAS@ canvas) {
	array<Fish> fish(fishCount.length());
	array<int> distances(fishCount.length());
	for (int i = 0;i < int(fishCount.length());i++) {
		fish[i] = fishCount[i];
	}
	fish.sortAsc();
	for (int i = 0;i < int(fishCount.length());i++) {
		if (fish[i].active) {   
			float size = 0.1 + (fish[i].distance*0.01);
			canvas.drawResizedSprite(int(fish[i].xPos),485 + fish[i].distance,ANIM::FISH,1,(jjGameTicks % 60)/10,((size)*(!fish[i].right? -1 : 1)),size,SPRITE::PALSHIFT,-16 + fish[i].color);
			canvas.drawResizedSprite(int(fish[i].xPos),485 + fish[i].distance,ANIM::FISH,1,(jjGameTicks % 60)/10,((size)*(!fish[i].right? -1 : 1)),size,SPRITE::TRANSLUCENTCOLOR,32);
			if (fish[i].distance <= 17) {
				canvas.drawResizedSprite(int(fish[i].xPos),485 + fish[i].distance,ANIM::FISH,1,(jjGameTicks % 60)/10,((size)*(!fish[i].right? -1 : 1)),size,SPRITE::TRANSLUCENTCOLOR,32);
			}
			//canvas.drawString(fish[i].xPos,485 + fish[i].distance,"" + fish[i].id);
		}
		fishCount[i].main();
	}
	//canvas.drawResizedSprite(250,485,ANIM::FISH,1,(jjGameTicks % 60)/10,0.3,0.3,SPRITE::SHADOW);
	//canvas.drawResizedSprite(250,520,ANIM::FISH,1,(jjGameTicks % 60)/10,0.5,0.5,SPRITE::SHADOW);
}


class Crab : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		if (obj.state == STATE::START) {
			if (jjIsServer) {
				obj.var[0] = 8 + ((jjRandom() % 20)*8);
			}
		}
			obj.behave(BEHAVIOR::WALKINGENEMY);
	}
	void onDraw(jjOBJ@ obj) {
		jjDrawResizedSpriteFromCurFrame(obj.xPos,obj.yPos,obj.curFrame,obj.direction,1,SPRITE::SINGLEHUE,obj.var[0]);
	}
}

class CustomParticle {
	int countDown,layer;
	float xPos,yPos,xSpeed,ySpeed;
	bool active;
	void running() {
		if (active) {
			if (countDown > 0) {
				countDown--;
			}
			if (yPos < 0 || xPos < 0) {
				countDown = 0;
				xPos = 32;
				yPos = 32;
			}
			jjDrawRotatedSprite(xPos,yPos,ANIM::AMMO,4,0,255 - countDown,countDown*0.004,countDown*0.004,SPRITE::SINGLEHUE,112,layer);
			xPos += xSpeed;
			yPos += ySpeed;
		}
		if (countDown <= 0) { 
			active = false;
			countDown = 0;
		}
	}
}

class Fish {
	int id,distance,deadEnd,color;
	float xPos,xSpeed;
	bool right,active;
	
	Fish() {
		this.right = (jjRandom() % 2 == 0? true : false);
		this.deadEnd = jjResolutionWidth + 32;
		this.xPos = (right? 0 : (deadEnd));
		this.distance = 1 + int(jjRandom() % 35);
		this.color = int(jjRandom() % 8)*8;
		this.xSpeed = 0.1;
		this.active = true;
	}
	
	void main() {
		if (active) {
			xPos += (xSpeed + (distance*0.01))*(right? 1 : -1);
		}
		if (((xPos > deadEnd && right) || (xPos < 0 && !right)) && active) {
			active = false;
		}
	}
	
	int opCmp(const Fish&in other) const {
        return int(distance - other.distance);
    }
}

void spawnCustomParticles(float xPos,float yPos,float xSpeed,float ySpeed,int layer) {
	CustomParticle@ particle = particles2[availableParticles()];
	particle.xPos = xPos;
	particle.yPos = yPos;
	particle.layer = layer;
	particle.countDown = 255;
	particle.active = true;
	particle.xSpeed = xSpeed;
	particle.ySpeed = ySpeed;
}

int availableParticles() {
	for (int i = 0;i < int(particles2.length - 1);i++) 
		if (particles2[i].active != true) {
			return i;
		}
	return 0;
}

int availableFish() {
	for (int i = 0;i < int(fishCount.length - 1);i++) 
		if (fishCount[i].active != true) {
			return i;
		}
	return -1;
}