Downloads containing BLGruins1.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Project RejectFeatured Download Rysice Single player 8.9 Download file

File preview

const bool MLLESetupSuccessful = MLLE::Setup(); ///@MLLE-Generated
#include "MLLE-Include-1.5.asc" ///@MLLE-Generated
#pragma require "blgruins1-MLLE-Data-1.j2l" ///@MLLE-Generated
#pragma require "blgruins1.j2l" ///@MLLE-Generated



#include "blgruins.asc"
#pragma require "blgruins.asc"
#pragma require "Earthquake.wav" //earthquake sound from https://www.freesoundeffects.com/
#pragma require "alarm1.wav"
#pragma require "alarm2.wav"
#pragma require "alarm3.wav"
bool BCAvailable = true;
bool settableAreaLoaded = false;
array<jjOBJ@> Explosions(10);
array<AutomatedDoors> Doors(10);
jjOBJ@ ExplosionTrail;
array<SOUND::Sample> explosionSounds = {SOUND::COMMON_BENZIN1,SOUND::COMMON_DAMPED1,SOUND::COMMON_EXPL_TNT,SOUND::ROCK_ROCK1,SOUND::AMMO_LAZRAYS};
array<SOUND::Sample> alarmSounds = {SOUND::INTRO_BLOW,SOUND::INTRO_BOEM1,SOUND::INTRO_BOEM2};

void onLevelLoad() {
	jjSampleLoad(SOUND::INTRO_BLOW,"alarm1.wav");
	jjSampleLoad(SOUND::INTRO_BOEM1,"alarm2.wav");
	jjSampleLoad(SOUND::INTRO_BOEM2,"alarm3.wav");
	blgruins::init();
	jjUseLayer8Speeds = true;
	jjTexturedBGFadePositionY = 0.5;
	jjGenerateSettableTileArea(4,0,0,jjLayerWidth[4],jjLayerHeight[4]);
	settableAreaLoaded = true;
	Doors[0].locked = true;
}

void onLevelReload() {
	blgruins::reInit();
	jjMusicLoad("", true);
	BCAvailable = true;
	flashBang = 0;
	if (BCAvailable == true) {
	blgruins::cutscene.activated = true;
	blgruins::cutscene.borders = true;
	blgruins::cutscene.freezePlayer = true;
	blgruins::cutscene.endTimeStamp = 70*20;
	blgruins::cutscene.ID = 0;
	BCAvailable = false;
	Doors[0].locked = true;
	Doors[0].openCounter = 0;
	}
}

void onLevelBegin() {
	blgruins::postInit();
	if (BCAvailable == true) {
	blgruins::cutscene.activated = true;
	blgruins::cutscene.borders = true;
	blgruins::cutscene.freezePlayer = true;
	blgruins::cutscene.endTimeStamp = 70*20;
	blgruins::cutscene.ID = 0;
	BCAvailable = false;
	}
}

bool onDrawScore(jjPLAYER@ player, jjCANVAS@ canvas) {
	blgruins::HUD(player,canvas);
	return false;
}

void onMain() {
	blgruins::blgMain();
	cutscenes();
	if (settableAreaLoaded) {
	for (int i = 0;i < 9;i++) {
		AutomatedDoors@ door = Doors[i];
		door.runnning();
		door.ID = i;
	}
	}
	door0();
	door1();
}

void door0() {
	AutomatedDoors@ door = Doors[0];
	door.xTile = 57;
	door.yTile = 26;
	door.tileID1 = 8 + (38*10);
	door.tileID2 = 9 + (38*10);
	door.loaded = true;
}
void door1() {
	AutomatedDoors@ door = Doors[1];
	door.xTile = 66;
	door.yTile = 26;
	door.tileID1 = 8 + (38*10);
	door.tileID2 = 9 + (38*10);
	door.loaded = true;
}
void onPlayerInput(jjPLAYER@ play) {
	blgruins::playerInput(play);
}

void onPlayer(jjPLAYER@ play) {
	blgruins::player(play);
}

void onFunction0() {
	if (BCAvailable == true) {
	blgruins::cutscene.activated = true;
	blgruins::cutscene.borders = true;
	blgruins::cutscene.freezePlayer = true;
	blgruins::cutscene.endTimeStamp = 70*20;
	blgruins::cutscene.ID = 0;
	BCAvailable = false;
	}
}

void onFunction1() {
	Doors[0].locked = false;
}
int flashBang = 0;
void cutscenes() {
	if (blgruins::cutscene.ID == 0) {
		int cameraXOffset = 800 -jjSubscreenWidth;
		int cameraYOffset = 600 -jjSubscreenHeight;
		if (checkTimeStampPrecise(70*3)) { //it begins
			jjMusicLoad("Earthquake.wav",false);
		}
		if (checkTimeStamp(70*1,70*16 + 10,70 + 30)) { 
		 jjSamplePriority(alarmSounds[jjRandom() % 3]);
		}
		if (checkTimeStamp(70*1,70*16 + 10,70 + 30,32)) {
			jjDrawRectangle(48*32,56*32, 26*32,20*32 , 27, SPRITE::TRANSLUCENT,0,1);
		}
		if (checkTimeStamp(70*12 + 10,70*19)) {
			jjDrawRectangle(48*32,56*32, 26*32,20*32 ,15, SPRITE::BLEND_NORMAL,(flashBang) ,1);
			if (flashBang < 255) {
			flashBang += 1;
			}
		}
		if (checkTimeStamp(70*3,70*16 + 10,30)) {
			 addExplosions((57*32) + (jjRandom() % 200),64*32 +  + (jjRandom() % 200),0,3,false);
			 jjAddParticleTileExplosion(59 + (jjRandom() % 3), 63 + (jjRandom() % 4), 51*10,false);
		}
		if (checkTimeStamp(70*3,70*16 + 10,15)) {
			 addExplosions((57*32) + (jjRandom() % 210),63*32 + (jjRandom() % 180),1,3,false);
			 addExplosions((57*32) + (jjRandom() % 210),63*32 + (jjRandom() % 180),2,3,false);
		}
		if (checkTimeStamp(70*3,70*16 + 10,40)) {
			 addExplosionTrail(59*32 + (jjRandom() % 32) ,63*32 + (jjRandom() % 180),0);
			 addExplosionTrail(62*32 - (jjRandom() % 32) ,63*32 + (jjRandom() % 180),1);
		}
		if (checkTimeStamp(70*16 + 10,70*16 + 12)) {
			blgruins::cutscene.freezePlayer = false;
			jjMusicLoad("Final_Boss.mp3", false);
		}
		if (checkTimeStampPrecise(70*16 + 10)) {
		}
		for (int i = 0;i <= jjLocalPlayerCount;i++) {
		jjPLAYER@ play = jjLocalPlayers[i];
			if (checkTimeStamp(0,2)) {
				play.cameraFreeze(49*32 - 16 + cameraXOffset/2,57*32 + cameraYOffset/2,false,true);
			}
			if (checkTimeStamp(70*3,70*15 + 60)) {
			play.cameraFreeze(49*32 - 16 + cameraXOffset/2,57*32 + ((jjSin((jjGameTicks*100) % 1023))*8) + cameraYOffset/2,false,true);
			}
			if (checkTimeStamp(70*16,70*16 + 10)) {
			playxPos[play.playerID]	= 36*32;
			playyPos[play.playerID] = 27*32 + 10;
			}
			if (checkTimeStamp(70*16 + 10,70*16 + 12)) {
			play.cameraFreeze(33*32 - 16 + cameraXOffset/2,15*32 + 2 + cameraYOffset/2,false,true);
			}
			if (checkTimeStampPrecise(70*16)) {
			 jjSample(play.xPos, play.yPos,SOUND::DEVILDEVAN_LAUGH,63,5500);
			}
			if (checkTimeStamp(70*19,70*20)) {
				flashBang = 0;
				play.cameraUnfreeze(false);	
			}
		}
	}	
}

bool checkTimeStamp(int start,int end) {
	if (blgruins::cutscene.timeStamp > start && blgruins::cutscene.timeStamp < end) {
		return true;
	}
	return false;
}

bool checkTimeStampPrecise(int timeStamp) {
	if (blgruins::cutscene.timeStamp == timeStamp) {
		return true;
	}
	return false;
}

bool checkTimeStamp(int start,int end,int offset) {
	if (blgruins::cutscene.timeStamp > start && blgruins::cutscene.timeStamp < end && (blgruins::cutscene.timeStamp % offset == 0)) {
		return true;
	}
	return false;
}

bool checkTimeStamp(int start,int end,int offset,int interval) {
	if (blgruins::cutscene.timeStamp > start && blgruins::cutscene.timeStamp < end && (blgruins::cutscene.timeStamp % offset >= 0 && blgruins::cutscene.timeStamp % offset < interval )) {
		return true;
	}
	return false;
}

void addExplosions(int x,int y,int ID,int size,bool silent) {
	 @Explosions[ID] = jjObjects[jjAddObject(OBJECT::SEEKERBULLET, 32, 32,0, CREATOR::LEVEL)];
	 Explosions[ID].xPos = x;
	 Explosions[ID].yPos = y;
	 Explosions[ID].behavior = function(obj) { obj.behavior = CutsceneExplosion1();};
	 Explosions[ID].var[4] = 2 + int(jjRandom() % size);
	 if (!silent) {
	 jjSample(p.xPos, p.yPos,explosionSounds[jjRandom() % 5] ,32,8000 + (jjRandom() % 7000));
	 }
}

void addExplosionTrail(int x,int y,int direction) {
	 @ExplosionTrail = jjObjects[jjAddObject(OBJECT::BLASTERBULLET, 32, 32,direction, CREATOR::LEVEL,BEHAVIOR::BULLET)];
	 ExplosionTrail.xPos = x;
	 ExplosionTrail.yPos = y;
	 ExplosionTrail.behavior = function(obj) { obj.behavior = CutsceneExplosionTrail();};
	 ExplosionTrail.direction = direction;
	 ExplosionTrail.counterEnd = 120;
	 ExplosionTrail.xSpeed = 0;
	 ExplosionTrail.ySpeed = -5;
	 ExplosionTrail.xAcc = 0.08;
	 ExplosionTrail.yAcc = 0.25;
	 jjSample(p.xPos, p.yPos,SOUND::ORANGE_BOEML);
}

class CutsceneExplosion1 : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		obj.behave(BEHAVIOR::SEEKERBULLET,false);
		obj.counterEnd = 0;
		if (obj.state == STATE::START) {
		obj.scriptedCollisions = true;
		obj.state = STATE::EXPLODE;
		obj.var[4] = 1 + int(jjRandom() % 5);
		}
		if (obj.state == STATE::FLY) {
		obj.var[4] = 1 + int(jjRandom() % 5);
		obj.scriptedCollisions = true;
		obj.state = STATE::EXPLODE;
		}
	}
	bool onObjectHit(jjOBJ@ obj, jjOBJ@, jjPLAYER@ player, int) {
	return false;
	}
	void onDraw(jjOBJ@ obj) {
		if (obj.state == STATE::EXPLODE) {
			jjDrawResizedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, (obj.var[4] * 0.5),(obj.var[4] * 0.5), SPRITE::NORMAL,0);
		}
	}
}

class CutsceneExplosionTrail : jjBEHAVIORINTERFACE {
	void onBehave(jjOBJ@ obj) {
		if (obj.state == STATE::START) {
		obj.xSpeed = 0;
		obj.ySpeed = 0;
		obj.state = STATE::FLY;
		}
		if (obj.state == STATE::FLY) {
		obj.xSpeed += obj.xAcc;
		obj.ySpeed += obj.yAcc;
		if ((++obj.counter == obj.counterEnd)) {
			if (blgruins::cutscene.timeStamp > blgruins::cutscene.endTimeStamp) {
				obj.state = STATE::EXPLODE;
				}
			} else {
				obj.xPos += (obj.direction < 1? -obj.xSpeed : obj.xSpeed);
				obj.yPos += obj.ySpeed;
				//obj.draw();
				if (obj.counter % 5 == 0) {
			addExplosions(obj.xPos,obj.yPos,3,1,true);
			}
				}
		} else if (obj.state == STATE::DEACTIVATE) {
			obj.delete();
		} else if (obj.state == STATE::EXPLODE) {
			obj.behavior = BEHAVIOR::EXPLOSION2;
			obj.frameID = 0; //display the full .killAnim animation
		}
	}
	bool onObjectHit(jjOBJ@ obj, jjOBJ@, jjPLAYER@ player, int) {
	return false;
	}
	void onDraw(jjOBJ@ obj) {
		//jjDrawString(obj.xPos,obj.yPos,"" + obj.xSpeed);
		//	jjDrawResizedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, 1,1, SPRITE::NORMAL,0);
	}
}

class AutomatedDoors {
	int xTile,yTile,ID,tileID1,tileID2,openStyle,openCounter;
	bool activated,locked,loaded;
	void runnning() {
		if (loaded) {
		jjDrawTile(xTile*32,(yTile*32) - openCounter,tileID1,TILE::ALLQUADRANTS,4);
		jjDrawTile(xTile*32,(yTile*32) + 32 - openCounter,tileID2,TILE::ALLQUADRANTS,4);
		if (!activated) {
			jjTileSet(4,xTile,yTile,1);
			jjTileSet(4,xTile,yTile + 1,1);
			
		}
		if (!locked) {
		if (detectPlayers()) {
			if (openCounter < 64) {
				openCounter += 1;
			}
			} else {
			if (openCounter > 0) {
					openCounter -= 1;
			}
			}
		}
		if (openCounter > 32) {
		activated = true;
		} else activated = false;
		if (activated) {
			jjTileSet(4,xTile,yTile,0);
			jjTileSet(4,xTile,yTile + 1,0);
		}
		}
	}
	bool detectPlayers() {
	int players = 0;
		for (int i = 0;i < 32;i++) {
				jjPLAYER@ play = jjPlayers[i];
				if (int(play.xPos / 32) < xTile + 2 && int(play.xPos / 32) > xTile - 2  && int(play.yPos / 32) < yTile + 3 && int(play.yPos / 32) > yTile - 2)
				players++;
	}
	return (players >= 1? true : false);
	}
}