Copy to Clipboard Test

FF Falling Rocks Code

//FF_falling_rock
//Annoying falling rocks and boulders in Death Mountain of Old Hyrule. Bounce downwards left and right. Respawns when off bottom of the screen.

ffc script FallingBoulder{
	void run(int enemyID){
		npc ghost = Ghost_InitAutoGhost(this, enemyID);
		
		int HF = ghost->Homing;
		int HR = ghost->Haltrate;
		int RR = ghost->Rate;
		int HNG = ghost->Hunger;
		int SPD = ghost->Step;
		int WPND = ghost->WeaponDamage;
		
		int sizex = Ghost_GetAttribute(ghost, 0, 1);//Tile Width
		int sizey = Ghost_GetAttribute(ghost, 1, 1);//Tile Height	
		int angle = Ghost_GetAttribute(ghost, 2, 30);//Falling angle of rock.
		int rand = Ghost_GetAttribute(ghost, 3, 0);//If>0 - Random angle each bounce, otherwise alternate left and right. If Homing Factor is >176 - try to chase Link.
		int sound = Ghost_GetAttribute(ghost, 4, 0);//Sound to play on each bounce.
		int quake = Ghost_GetAttribute(ghost, 5, 0);//Quake power on each bounce.
		int delay = Ghost_GetAttribute(ghost, 6, 0);//Delay before starting falling after respawn.
		int bouncevz = Ghost_GetAttribute(ghost, 7, 160);//Bounce Z-height.
		int randdelay = Ghost_GetAttribute(ghost, 8, 0);//Delay randomization, maximum disperse.
		int visibledelay = Ghost_GetAttribute(ghost, 9, 0);//>0 - Render rock at wait time.
		
		ghost->Extend=3;
		Ghost_SetSize(this, ghost, sizex, sizey);
		if (sizex>2 || sizey>2)Ghost_SetHitOffsets(ghost, 8, 8, 8, 8);
		
		Ghost_SetFlag(GHF_NORMAL);
		Ghost_UnsetFlag(GHF_KNOCKBACK);
		Ghost_SetFlag(GHF_IGNORE_ALL_TERRAIN);
		Ghost_SetFlag(GHF_MOVE_OFFSCREEN);
		
		int OrigTile = ghost->OriginalTile;
		int statecounter = delay+Rand(randdelay);
		int haltcounter = -1;
		int origx= Ghost_X;
		bouncevz/=100;
		int dir = 2+Rand(2);
		Ghost_Y=0;
		int curangle = angle;
		if (visibledelay==0){
			ghost->DrawXOffset = 1000;
			ghost->CollDetection=false;
		}
		
		int defs[18];
		Ghost_StoreDefenses(ghost,defs);
		
		while(true){
			if (statecounter>0){
				statecounter--;
				if (statecounter==0){
					if (HF>176){
						if (Link->X>Ghost_X)curangle = -angle;
						else curangle = angle-180;
					}
					else if (rand>0){
						if (ChooseB())curangle = -angle;
						else curangle = angle-180;
					}
					else if (angle>-90)curangle = angle-180;
					else curangle = -angle;
					Ghost_Jump = bouncevz;
					Ghost_Vx = SPD/100*Cos(curangle);
					Ghost_Vy = -SPD/100*Sin(curangle);
					ghost->DrawXOffset = 0;
					ghost->CollDetection=true;
					
				}
			}
			else{
				if (CenterX(ghost)<16 && Ghost_Vx<0)Ghost_Vx*=-1;
				if (CenterX(ghost)>240 && Ghost_Vx>0)Ghost_Vx*=-1;
				if (Ghost_Jump<=0 && Ghost_Z<=0){
					if (HF>176){
						if (Link->X>Ghost_X)curangle = -angle;
						else curangle = angle-180;
					}
					else if (rand>0){
						if (ChooseB())curangle = -angle;
						else curangle = angle-180;
					}
					else if (angle>-90)curangle = angle-180;
					else curangle = -angle;
					Ghost_Jump = bouncevz;
					Ghost_Vx = SPD/100*Cos(curangle);
					Ghost_Vy = -SPD/100*Sin(curangle);
					Game->PlaySound(sound);
					Screen->Quake+=quake;
				}
				if (Ghost_Y>176){
					Ghost_Vx=0;
					Ghost_Vy=0;
					Ghost_Jump=0;
					Ghost_Z=0;
					Ghost_Y=0;
					statecounter = delay+Rand(randdelay);
					if (visibledelay==0){
						ghost->DrawXOffset = 1000;
						ghost->CollDetection=false;
					}
				}
			}
			Ghost_Waitframe(this, ghost);
		}
	}
}