Downloads containing PGM.j2as

Downloads
Name Author Game Mode Rating
JJ2+ Only: Player Guided MissileFeatured Download Foly Custom / Concept 8.5 Download file

File preview

/***************************************************/
/**	Made by Foly 						 		  **/
/**	Feel free to use/copy any part of this script **/
/***************************************************/

/***Constants***/
int RocketTime = 1400;
float RotateSpeed = 6;
float RocketXYSpeed = 3;
float RocketDiaSpeed = RocketXYSpeed/1.41;

/***Variables***/
jjOBJ@ sRocket;
bool RocketLaunch = false;
float xPosOld, Angle;

/***Script only functions***/
void ChangeRD(float tAngle) {
	//Determine if the rocket is going left or right
	if (tAngle > 0)
		sRocket.direction = 1;
	else
		sRocket.direction = -1;

	//Set the animation and velocity of the rocket
	tAngle = abs(tAngle);
	if ((tAngle >= 0) && (tAngle < 22.5)) {
		sRocket.determineCurAnim(ANIM::AMMO , 38, true);
		sRocket.xSpeed = 0;
		sRocket.ySpeed = -RocketXYSpeed;
	}
	else if ((tAngle >= 22.5) && (tAngle < 67.5)) {
		sRocket.determineCurAnim(ANIM::AMMO , 39, true);
		sRocket.xSpeed = RocketDiaSpeed*sRocket.direction;
		sRocket.ySpeed = -RocketDiaSpeed;
	}
	else if ((tAngle >= 67.5) && (tAngle < 112.5)) {
		sRocket.determineCurAnim(ANIM::AMMO , 37, true);
		sRocket.xSpeed = RocketXYSpeed*sRocket.direction;
		sRocket.ySpeed = 0;
	}
	else if ((tAngle >= 112.5) && (tAngle < 157.5)) {
		sRocket.determineCurAnim(ANIM::AMMO , 36, true);
		sRocket.xSpeed = RocketDiaSpeed*sRocket.direction;
		sRocket.ySpeed = RocketDiaSpeed;
	}
	else if ((tAngle >= 157.5) && (tAngle < 180)) {
		sRocket.determineCurAnim(ANIM::AMMO , 35, true);
		sRocket.xSpeed = 0;
		sRocket.ySpeed = RocketXYSpeed;
	}
}

//Returns everything to normal after the rocket explodes
void DestroyRocket() {
	RocketLaunch = false;
	p.ammo[4] = 1;
	p.cameraUnfreeze();
	p.noFire = false;
	p.jumpStrength = -10;
	p.timerStop();
	sRocket.state = STATE::EXPLODE;
}

//Determines the absolute value
int abs(int x) {
	if (x < 0)
		x = -x;
	return x;
}


/***onFunctions***/
void onFunction1() {
	jjOBJ@ Light;
	int LL = 0;
	for (int i = 1; i < jjObjectCount; i++) {
		@Light = jjObjects[i];
		if (Light.isActive && (Light.eventID == OBJECT::DESTRUCTSCENERY) && (Light.state == STATE::DONE)) {
			LL++;
			if (LL == 6) {
				jjAlert("You have lit all the lights, you've earned a candy! :)");
				jjAddObject(OBJECT::CANDY, 32*31, 32*34);
				break;
			}
		}
	}
	if (LL < 6)
		jjAlert("You have lit |" + formatInt(LL, "1") + "||||||| of the| 6 |||||||light(s). ");
	
}

/***Gameplay functions***/

void onMain() {
	/*Rocket movement*/
	if ((RocketLaunch) && (sRocket.isActive)) {
		//Keep the camera frozen to the rocket
		p.cameraFreeze(sRocket.xPos, sRocket.yPos, true, true);
		
		//Disable the rockets own death counter
		sRocket.counter = 1;
		
		//If the player goes left or right the angle changes -5 or 5 degrees respectively
		if (p.xPos > xPosOld) {
			ChangeRD(Angle);
			Angle = Angle + RotateSpeed;
		}
		if (p.xPos < xPosOld) {
			ChangeRD(Angle);
			Angle = Angle - RotateSpeed;
		}

		//Angle can only be between -180 and 180
		if (Angle > 180)
			Angle = -180;
		if (Angle < -180)
			Angle = 180;
			
		//Dont change the player position and have smooth angle turning
		p.xPos = xPosOld;
		p.xSpeed = 0;
		p.xAcc = 0;
		
		//Stop all the fun if the rocket hits the wall :(
		if (sRocket.state == STATE::EXPLODE)
			DestroyRocket();
	}

	/*Start rocket launch*/
	if ((p.ammo[4] == 0) && (!RocketLaunch)) {
		RocketLaunch = true;
		
		//Dont allow the player to shoot while the rocket is active
		p.noFire = true;
		
		//Find the rocket id, when it's found break the loop so sRocket will point to the rocket object
		for (int i = 1; i < jjObjectCount; i++) {
			@sRocket = jjObjects[i];
			if (sRocket.isActive && (sRocket.eventID == OBJECT::SEEKERBULLET) && (!(sRocket.state == STATE::EXPLODE)) && 
				(sRocket.creatorType == CREATOR::PLAYER) && ((sRocket.creator - 32768) == p.playerID)) {
				break;
			}
		}
		
		//Starts the timer obviously
		p.timerStart(RocketTime, false);

		//Remember the x position of the player from where he/she fired the rocket
		xPosOld = p.xPos;
		p.jumpStrength = 0;
		
		//Determine the starting direction and set starting angle
		switch (sRocket.direction) {
			case 0: Angle = 0; break;
			case -1: Angle = -90; break;
			default: Angle = 90; break;
		}

		ChangeRD(Angle);

		//Destroy the rocket if it's not made by a player (this will destroy 1 seeker ammo at the start which is used to load the animation)
		if (sRocket.creatorType != CREATOR::PLAYER)
			DestroyRocket();
	}
}

void onPlayerTimerEnd() {
	//Destroys the rocket when the timer ends
	DestroyRocket();
	p.timerPersists = false;
}