92 lines
3.4 KiB
C#
92 lines
3.4 KiB
C#
using UnityEngine;
|
||
|
||
public static class FieldCleaner
|
||
{
|
||
const int FIELD_HEIGHT = 6;
|
||
const int FIELD_WIDTH = 7;
|
||
const string SORTLAYER_BACKGROUND = "Background";
|
||
|
||
const float EXPLOSION_FORCE = 30;
|
||
static readonly Vector3 EXPLOSION_ORIGIN = new Vector3(0, -2, -5);
|
||
const float EXPLOSION_RADIUS = 50;
|
||
|
||
const float TIME_TO_DESTROY = 5;
|
||
|
||
static Transform[,] field;
|
||
|
||
static bool toMenu;
|
||
static CellState firstPlayer;
|
||
|
||
|
||
|
||
//передаем переходим мы в меню или нет. Если нет, то переход отсюда в новый раунд
|
||
//Надо еще сделать в конструкторе чтобы nextState указывать а то ж непонятно вообще
|
||
public static void Clear(bool to_menu, CellState _firstPlayer)
|
||
{
|
||
toMenu = to_menu;
|
||
firstPlayer = _firstPlayer;
|
||
|
||
field = GameManager.instance.chipTransforms;
|
||
|
||
SoundManager.instance.playExplosion();
|
||
|
||
//блок непоняток
|
||
if (GameManager.instance.currentChip != null)
|
||
{
|
||
Object.Destroy(GameManager.instance.currentChip);
|
||
}
|
||
GameManager.fieldModel.makeEmptyField(width: GameManager.instance.Cols, height: GameManager.instance.Rows);
|
||
GameManager.instance.chipTransforms = new Transform[GameManager.instance.Rows, GameManager.instance.Cols];
|
||
|
||
|
||
Explode();
|
||
|
||
//переход
|
||
if (toMenu)
|
||
GameManager.instance.stateMachine.ChangeState(new MenuState(fromGameplay: true));
|
||
else
|
||
{
|
||
//Фишка ходит первой если ее не побеждали сегодня еще
|
||
|
||
bool goingToLastBot = DifficultyManager.Instance.currentOpponent == GameManager.instance.botsAmount - 1;
|
||
|
||
if (goingToLastBot)
|
||
{
|
||
//bool bossUpgraded = GameManager.instance.BossUpgraded;
|
||
bool bossFirst = SettingsManager.GetString("BaseBotDifficulty", "Фиксированная") != "Обычная";
|
||
CellState firstRoundPlayer = bossFirst ? CellState.Player2 : CellState.Player1;
|
||
GameManager.instance.stateMachine.ChangeState(new StartRoundState(firstPlayer: firstRoundPlayer));
|
||
return;
|
||
}
|
||
|
||
|
||
GameManager.instance.stateMachine.ChangeState(new StartRoundState(firstPlayer: firstPlayer));
|
||
}
|
||
|
||
|
||
}
|
||
|
||
private static void Explode()
|
||
{
|
||
for (int i = 0; i < GameManager.instance.Rows; i++)
|
||
{
|
||
for (int j = 0; j < GameManager.instance.Cols; j++)
|
||
{
|
||
Transform chipTransform = field[i, j];
|
||
if (chipTransform != null)
|
||
{
|
||
Rigidbody rb = chipTransform.GetComponent<Rigidbody>();
|
||
rb.isKinematic = false;
|
||
rb.AddExplosionForce(EXPLOSION_FORCE, EXPLOSION_ORIGIN, EXPLOSION_RADIUS, upwardsModifier: 1, ForceMode.Impulse);
|
||
|
||
chipTransform.GetComponent<TrailRenderer>().sortingLayerName = SORTLAYER_BACKGROUND;
|
||
chipTransform.GetChild(0).GetComponent<SpriteRenderer>().sortingLayerName = SORTLAYER_BACKGROUND;
|
||
Object.Destroy(chipTransform.gameObject, TIME_TO_DESTROY+Random.Range(-1f,1f));//чтобы уничтожались не одновременно
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|