protected void FillOtherLiquid(LevelTile_Dig self, LevelTile_Dig otherTile, LevelTilemap level) { int value = Mathf.Clamp(flowAmount, 0, liquidAmount); otherTile.AddWater(level, value); self.RemoveWater(level, value); }
float CalcuateLight(LevelTile_Dig lightSource) { var x = Mathf.Abs(this.x - lightSource.pos.x); var y = Mathf.Abs(this.y - lightSource.pos.y); var dis = Mathf.Sqrt(x * x + y * y); var c = Mathf.Clamp01((1 + dis) / (lightSource.data as LevelTileData_Dig).emitLightRange); return((1 - c) * (lightSource.data as LevelTileData_Dig).emitLight); }
void FlowDown(int x, int y, LevelTilemap level, LevelTile_Dig tile) { if (CanFlowToPos(x, y, level) == false) { return; } if (liquidAmount <= 0) { return; } FillOtherLiquid(tile, level.GetTile <LevelTile_Dig>(x, y), level); }
public override void DestroyTile(BaseLevelTile tile) { base.DestroyTile(tile); LevelTile_Dig tileAbove = GetTile <LevelTile_Dig>(tile.pos.x, tile.pos.y + 1); if (tileAbove.inSunLight == true) { LightOnPos(tile.pos.x, tile.pos.y, true); } else { ShadowOnPos(tile.pos.x, tile.pos.y); } }
float GetAbsorption(LevelTile_Dig tile) { if (tile.IsEmpty()) { return(0); } var data = tile.data as LevelTileData_Dig; if (data != null) { return(data.isTranslucent? 0 : 1); } else { return(1); } }
bool DelayErase(LevelTilemap level, LevelTile_Dig tile) { if (liquidAmount > 0) { erase = false; delayedErase = delayedEraseMax; } if (erase == false) { return(false); } delayedErase -= inViewdeltaTime; if (delayedErase >= 0) { return(false); } return(true); }
void Flow(int dirX, LevelTilemap level, LevelTile_Dig tile) { int targetX = tile.pos.x + dirX; int targetY = tile.pos.y; if (CanFlowToPos(targetX, targetY, level) == false) { return; } if (liquidAmount <= stickAmount) { return; } FillOtherLiquid(tile, level.GetTile <LevelTile_Dig>(targetX, targetY), level); //if (liquidAmount <= 0) // StartErase(); }
public void ShadowOnPos(int x, int posY) { LevelTile_Dig tile = GetTile <LevelTile_Dig>(x, posY); var pos = Vector3Int.zero; var data = tile.data as LevelTileData_Dig; //if (data != null) // return; bool lastHit = false; float value = 1; if (tile.IsEmpty()) { value = 0; } int penetration = 5; for (int y = posY; y > 0; y--) { if (penetration <= 0) { break; } tile = GetTile <LevelTile_Dig>(x, posY); if (tile == null) { break; } value -= GetAbsorption(tile); tile.inSunLight = false; SetLight(tile, value); if (tile.IsEmpty() == false) { penetration--; lastHit = true; } } }
public void LightOnPos(int x, int posY, bool sunLight = false) { LevelTile_Dig tile = GetTile <LevelTile_Dig>(x, posY + 1); if (sunLight == true && tile.inSunLight == false) { return; } var pos = Vector3Int.zero; bool lastHit = false; float value = 1; int penetration = 5; for (int y = posY; y > 0; y--) { if (penetration <= 0) { break; } tile = GetTile <LevelTile_Dig>(x, y); if (tile == null) { break; } value -= GetAbsorption(tile); if (value == 1) { tile.inSunLight = true; } SetLight(tile, value); if (tile.IsEmpty() == false) { penetration--; lastHit = true; } } }
public void SetLight(LevelTile_Dig leveltile, float sunLight) { leveltile.sunLight = sunLight; leveltile.viewNeedUpdate = true; int x = leveltile.x; int y = leveltile.y; if (IsPosOutOfBound(x - 1, y) == false) { GetITile(x - 1, y).viewNeedUpdate = true; } if (IsPosOutOfBound(x + 1, y) == false) { GetITile(x + 1, y).viewNeedUpdate = true; } if (IsPosOutOfBound(x, y - 1) == false) { GetITile(x, y - 1).viewNeedUpdate = true; } if (IsPosOutOfBound(x, y + 1) == false) { GetITile(x, y + 1).viewNeedUpdate = true; } }
bool NeighbourHasLessWater(LevelTile_Dig neighbour) { return(liquidAmount - neighbour.liquidAmount > flowAmount); }