示例#1
0
    /// <summary>
    /// Distrugge il building.
    /// </summary>
    public void destroyMe()
    {
        if (isAlive)
        {
            isAlive = false;
            if (OnDestroy != null)
            {
                OnDestroy(this);
            }
            CellDoomstock cell = GameManager.I.gridController.Cells[(int)Data.GetGridPosition().x, (int)Data.GetGridPosition().y];
            cell.SetStatus(CellDoomstock.CellStatus.Debris, cell.building);
            if (Data.ID != "Casa")
            {
                Data.RemoveAllPopulationFromBuilding();
            }
            TimeEventManager.OnEvent -= OnUnitEvent;
            SetBuildingStatus(BuildingState.Destroyed);

            List <Transform> myobject = gameObject.GetComponentsInChildren <Transform>().ToList();
            myobject.Remove(transform);
            if (Data.ID == "Meraviglia")
            {
                GameManager.I.OnMeravigliaDestroyed();
            }
            foreach (Transform go in myobject)
            {
                go.gameObject.SetActive(false);
            }
            CurrentMesh.mesh = Macerie;
            gameObject.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
            transform.eulerAngles           = new Vector3(90, 20, 0);
        }
    }
示例#2
0
    public void SetupPlayers()
    {
        CellDoomstock hole = gridController.GetCellPositionByStatus(CellDoomstock.CellStatus.Hole);

        if (Players[0] != null)
        {
            Players[0].SetupInput(
                new PlayerInputData()
            {
                Up                = KeyCode.W,
                Left              = KeyCode.A,
                Down              = KeyCode.S,
                Right             = KeyCode.D,
                Confirm           = KeyCode.Z,
                AddPopulationUnit = KeyCode.X,
                GoBack            = KeyCode.E,
                PlayerPower       = KeyCode.Q,
                RemovePopulation  = KeyCode.C,
                Pause             = KeyCode.Escape,
                EndGame           = KeyCode.F1
            });

            Players[0].SetUpPosition((int)hole.GridPosition.x - 1, (int)hole.GridPosition.y - 1, CellSize);
        }

        if (Players[1] != null)
        {
            Players[1].SetupInput(
                new PlayerInputData()
            {
                Up                = KeyCode.I,
                Left              = KeyCode.J,
                Down              = KeyCode.K,
                Right             = KeyCode.L,
                Confirm           = KeyCode.N,
                AddPopulationUnit = KeyCode.U,
                GoBack            = KeyCode.O,
                PlayerPower       = KeyCode.P,
                RemovePopulation  = KeyCode.M,
                Pause             = KeyCode.F5,
                EndGame           = KeyCode.F2
            });

            Players[1].SetUpPosition((int)hole.GridPosition.x - 1, (int)hole.GridPosition.y + 1, CellSize);
        }

        if (Players[2] != null)
        {
            Players[2].SetupInput(
                new PlayerInputData()
            {
                Up                = KeyCode.UpArrow,
                Left              = KeyCode.LeftArrow,
                Down              = KeyCode.DownArrow,
                Right             = KeyCode.RightArrow,
                Confirm           = KeyCode.Home,
                AddPopulationUnit = KeyCode.PageUp,
                GoBack            = KeyCode.PageDown,
                PlayerPower       = KeyCode.Insert,
                RemovePopulation  = KeyCode.Keypad0,
                Pause             = KeyCode.Keypad0,
                EndGame           = KeyCode.F3
            });

            Players[2].SetUpPosition((int)hole.GridPosition.x + 1, (int)hole.GridPosition.y + 1, CellSize);
        }
        hole.SetStatus(CellDoomstock.CellStatus.Empty);
        #region Quarto player commento
        //if (Players[3] != null) {
        //    Players[3].SetupInput(
        //    new PlayerInputData() {
        //        Up = KeyCode.Keypad8,
        //        Left = KeyCode.Keypad4,
        //        Down = KeyCode.Keypad5,
        //        Right = KeyCode.Keypad6,
        //        Confirm = KeyCode.KeypadMultiply,
        //        PopulationMenu = KeyCode.KeypadPlus,
        //        GoBack = KeyCode.KeypadMinus,

        //    });

        //    Players[3].SetUpPosition((int)hole.GridPosition.x + 1, (int)hole.GridPosition.y - 1, CellSize);
        //}
        #endregion
    }
示例#3
0
    public void DoMoveStep(INode _step)
    {
        if (lastPos != null)
        {
            if (lastPos.Type != CellDoomstock.CellType.Forest)
            {
                if (lastPos.Status == CellDoomstock.CellStatus.Enemy)
                {
                    lastPos.SetStatus(CellDoomstock.CellStatus.Empty);
                    lastPos.EnemiesInCell.Remove(this);
                }
            }


            lastPos = CurrentPosition;
        }
        transform.DOLookAt(_step.GetWorldPosition(), MovementSpeed, AxisConstraint.Y);

        if (CurrentPath != null)
        {
            transform.DOMove((new Vector3(_step.GetWorldPosition().x, _step.GetWorldPosition().y - 0.8f, _step.GetWorldPosition().z + 0.4f)), MovementSpeed).OnComplete(() =>
            {
                CurrentNodeIndex++;
                int lastNode    = pathFindingSettings.MoveToLastButOne ? CurrentPath.Count - 2 : CurrentPath.Count - 1;
                CurrentPosition = _step as CellDoomstock;
                lastPos         = CurrentPosition;

                if (CurrentPosition.Type != CellDoomstock.CellType.Forest)
                {
                    if (CurrentPosition.Status != CellDoomstock.CellStatus.Debris)
                    {
                        if (CurrentPosition.Status != CellDoomstock.CellStatus.Filled)
                        {
                            CurrentPosition.SetStatus(CellDoomstock.CellStatus.Enemy);
                            CurrentPosition.EnemiesInCell.Add(this);
                        }
                    }
                }


                if (CurrentNodeIndex > lastNode)
                {
                    // ha raggiunto l'obbiettivo, attacca
                    if (Attack(CurrentTarget))
                    {
                        if (CurrentTarget.BuildingLife <= 0)
                        {
                            currentState = enemyState.Searching;
                            resetTarget();
                        }
                    }
                    //else
                    //    currentState = enemyState.Attack;
                }
                else
                {
                    AttackNextStep();
                    if (currentState == enemyState.MovingToTarget)
                    {
                        // prossimo step di movimento
                        this.DoMoveToCurrentPathStep();
                    }
                }
                if (OnStep != null)
                {
                    OnStep(this);
                }
            });
        }
    }