Copy to Clipboard Test

Painting Pushblock Code

const int SFX_PAINT_PUSHBLOCK_MOVE = 50; //Sound to play when moving a block.

const int SFX_PAINT_PUSHBLOCK_STUCK = 16;//Sound to play when pushblock gets stuck.



//Painting puchblock.

//Like Tall puchblock, but leaves undercombos specific to FFC. Multiple painting pushblocks can leave dufferent undercombos.



//Set up 2 consecutive combos with the same tile, non-solid then fully solid.

//Effect Width and Height used. If TileHeight is greater than EffectHeight / 16, then the script calls PaintPush Renderer, so FFC sprite rendering is aligned to bottom edge of FFC`s hitbox.

//Place FFC on 1st combo from step 1

//Flag all target combos, including combo under FFC, with the same flag ID.

//D0 - bracelet level requirement.

//D1 - allowed push directions. Add together - 1-up, 2-down, 4-left, 8-right. 0 for all directions.

//D2 - add together: 1 - gets stuck after 1 push, 2 - gets stuck when landing on trigger, 4 - icy block, continue moving in direction until hitting obstacle, 8 - ignore triggers, 16 - iceblock paints continiously, 32 - animation on push (uses next combo in list)



//PaintPushRender

//Renderer for PaintPush blocks

//Place, gridsnap, and align on bottom with large pushblock.

//D0 - ID of pushblock FFC



ffc script LargePaintPushBlock{

	void run (int weight, int dirs, int flags){

		int origdata= this->Data;

		int cmb=origdata;

		int str[] = "PaintPushRender";

		int scr = Game->GetFFCScript(str);

		if (this->TileHeight>(this->EffectHeight/16)){

			int args[2] = {FFCNum(this),0};

			ffc r = RunFFCScriptOrQuit(scr, args);

			r->Data = cmb;

			r->X = this->X;

			r->TileWidth = this->TileWidth;

			r->TileHeight=this->TileHeight;

			r->CSet = this->CSet;

			r->Y = this->Y + this->EffectHeight - this->TileHeight*16;

			this->Data = FFCS_INVISIBLE_COMBO;

		}		

		int pos = ComboAt (this->X+1, this->Y+1);

		if (dirs==0) dirs=15;

		int ucmb = Screen->ComboD[pos];

		int ucset = Screen->ComboC[pos];

		int uflag = Screen->ComboF[pos];

		PaintPushReplaceCombosUnderFFC(this, ucmb+1, ucset);

		int pushcounter = 0;

		this->InitD[7] = -1;

		int movecounter = 0;

		for (int i=0;i<176;i++){

			if (ComboFI(i, CF_BLOCKTRIGGER))Screen->ComboF[i] = CF_BLOCKTRIGGER;

		}

		while(true){

			if (this->InitD[7]<0){

				if (PaintPushBlockIsPushed(this,Link->Dir, 6))pushcounter++;

				else pushcounter = 0;

				if (pushcounter>=8){

					if (PaintPushBlockCanBePushed(this, Link->Dir, weight, dirs) && !EnemiesAlive()){

						this->InitD[7] = Link->Dir;

						Game->PlaySound(SFX_PAINT_PUSHBLOCK_MOVE);

						movecounter = 16;

						if((flags&4)>0)movecounter = 8;

						PaintPushReplaceCombosUnderFFC(this, ucmb, ucset);

					}

					else pushcounter = 0;

				}

			}

			else{

				NoAction();

				movecounter--;

				if (this->InitD[7]==DIR_UP){

					this->Y--;

					if((flags&4)>0)this->Y--;

				}

				if (this->InitD[7]==DIR_DOWN){

					if((flags&4)>0)this->Y++;

					this->Y++;

				}

				if (this->InitD[7]==DIR_LEFT){

					this->X--;

					if((flags&4)>0)this->X--;

				}

				if (this->InitD[7]==DIR_RIGHT){

					this->X++;

					if((flags&4)>0)this->X++;

				}

				if (movecounter==0){

					if ((flags&4)>0 && PaintPushBlockCanBePushed(this, this->InitD[7], 0, dirs)){

						if ((flags&16)>0)PaintPushReplaceCombosUnderFFC(this, ucmb, ucset);

						movecounter=8;

					}

					else{

						pos = ComboAt (this->X+1, this->Y+1);

						if ((flags&1)>0){

							Game->PlaySound(SFX_PAINT_PUSHBLOCK_STUCK);

							dirs=0;

						}

						PaintPushReplaceCombosUnderFFC(this, ucmb+1, ucset);

						this->InitD[7]=-1;

						if ((flags&8)==0)PaintPushTriggerUpdate(this,ucmb,uflag, ucset);

						if (Screen->ComboF[pos]!=uflag){

							for(int i=1;i<=32;i++){

								//Game->PlaySound(16);

								ffc n = Screen->LoadFFC(i);

								if (n->Script!=this->Script)continue;

								n->InitD[6] = 2;

							}

						}

						if ((flags&2)>0 && this->InitD[6]>0){

							Game->PlaySound(SFX_PAINT_PUSHBLOCK_STUCK);

							dirs=0;

						}

					}

				}

			}

			if (this->InitD[6]==2)PaintPushTriggerUpdate(this,ucmb,uflag, ucset);

			if (this->Data!=FFCS_INVISIBLE_COMBO && (flags&32)>0){

				if (this->InitD[7]>=0)this->Data=origdata+1;

				else this->Data=origdata;

			}

			//debugValue(FFCNum(this),this->InitD[6]);

			Waitframe();

		}

	}

}



//returns true, if Link tries to push this block

bool PaintPushBlockIsPushed(ffc this, int dir, int margin){

	if((Link->X == this->X - 16 && (CenterLinkY() < this->Y+this->EffectHeight - 8+margin && CenterLinkY() > this->Y - margin) && Link->InputRight && dir == DIR_RIGHT) || // Right

	(Link->X == this->X + this->EffectWidth && (CenterLinkY() < this->Y+this->EffectHeight - 8+margin && CenterLinkY() > this->Y - margin) && Link->InputLeft && dir == DIR_LEFT) || // Left

	(Link->Y == this->Y - 16 && (Link->X < (this->X + this->EffectWidth-16+margin) && Link->X > this->X - margin) && Link->InputDown && dir == DIR_DOWN) || // Down

	(Link->Y == this->Y + this->EffectHeight-8 && (Link->X < (this->X + this->EffectWidth-16+margin) && Link->X > this->X - margin) && Link->InputUp && dir == DIR_UP)) { // Up

		return true;

	}

	return false;

}



//Returns true, if block can be pushed in the given direction

bool PaintPushBlockCanBePushed(ffc this, int dir, int weight, int dirs){

	if (dir==DIR_UP){

		if ((dirs&1)==0) return false;

	}

	if (dir==DIR_DOWN){

		if ((dirs&2)==0) return false;

	}

	if (dir==DIR_LEFT){

		if ((dirs&4)==0) return false;

	}

	if (dir==DIR_RIGHT){

		if ((dirs&8)==0) return false;

	}

	int br = GetHighestLevelItemOwned(IC_BRACELET);

	int power = 0;

	if (br>=0){

		itemdata it = Game->LoadItemData(br);

		power = it->Power;

	}

	if (power<weight) return false;

	int x1 = 0;

	int y1 = 0;

	int x2 = 0;

	int y2 = 0;

	if (dir==DIR_UP){

		x1 = this->X+1;

		y1 = this->Y-15;

		x2 = this->X+this->EffectWidth-2;

		y2 = this->Y-1;

	}

	if (dir==DIR_DOWN){

		x1 = this->X+1;

		y1 = this->Y+ this->EffectHeight+1;

		x2 = this->X+this->EffectWidth-2;

		y2 = y1+14;

	}

	if (dir==DIR_LEFT){

		x1 = this->X-14;

		y1 = this->Y+1;

		x2 = this->X-1;

		y2 = y1+this->EffectHeight-3;

	}

	if (dir==DIR_RIGHT){

		x1 = this->X+this->EffectWidth+1;

		y1 = this->Y+1;

		x2 = x1+14;

		y2 = y1+this->EffectHeight-3;

	}

	for (int i=0;i<176;i++){

		int cx1 = ComboX(i);

		int cy1 = ComboY(i);

		int cx2 = cx1+15;

		int cy2 = cy1+15;

		if (!RectCollision(x1,y1,x2,y2,cx1,cy1,cx2,cy2))continue;

		if (ComboFI(i, CF_NOBLOCKS)) return false;

		if (Screen->ComboS[i]>0)return false;

		int comboS=0;

		if(Screen->LayerMap(1)>0) comboS |= GetLayerComboS(1, i);

		if(Screen->LayerMap(2)>0) comboS |= GetLayerComboS(2, i);

		if(comboS>0)return false;

	}

	return true;

}



//Replaces combos under FFC.

void PaintPushReplaceCombosUnderFFC(ffc this, int ucmb, int ucset){

	int x1 = this->X+1;

	int y1 = this->Y+1;

	int x2 = x1+this->EffectWidth-2;

	int y2 = y1+this->EffectHeight-2;

	for (int i=0;i<176;i++){

		int cx1 = ComboX(i);

		int cy1 = ComboY(i);

		int cx2 = cx1+15;

		int cy2 = cy1+15;

		if (!RectCollision(x1,y1,x2,y2,cx1,cy1,cx2,cy2))continue;

		Screen->ComboD[i] = ucmb;

		Screen->ComboC[i] = ucset;

	}

}



//Checks, if all pushblocks are on triggers and triggers secrets, if it`s true;

void PaintPushTriggerUpdate(ffc f,int ucmb, int uflag, int ucset){

	f->InitD[6]=1;

	for (int i=0;i<176;i++){

		if (!ComboFI(i,uflag)) continue;

		if (Screen->ComboD[i]!=ucmb && Screen->ComboD[i]!=ucmb+1){

			f->InitD[6]=0;

			break;

		}

		if (Screen->ComboC[i]!=ucset){

			f->InitD[6]=0;

			break;

		}

	}

	for(int i=1;i<=33;i++){

		if (Screen->State[ST_SECRET]) break;

		if (i==33){

			Game->PlaySound(SFX_SECRET);

			Screen->TriggerSecrets();

			Screen->State[ST_SECRET]=true;

			break;

		}

		ffc n = Screen->LoadFFC(i);

		if (n->Script!=f->Script)continue;

		if ((n->InitD[2]&8)>0) continue;

		if (n->InitD[6] !=1) break;

	}

}



//Renderer for PaintPush blocks

//D0 - ID of pushblock FFC

ffc script PaintPushRender{

	void run (int ID){

		int origdata = this->Data;

		ffc f = Screen->LoadFFC(ID);

		while(true){

			if (Link->Y>=f->Y)this->Flags[FFCF_OVERLAY] =false;

			else this->Flags[FFCF_OVERLAY] =true;

			this->X = f->X;

			this->Y = f->Y + f->EffectHeight - f->TileHeight*16;

			if (((f->InitD[2])&32)>0 && f->InitD[7]>=0)this->Data = origdata+1;

			else this->Data = origdata;

			Waitframe();

		}

	}

}