Esempio n. 1
0
 public int AddManaForBump(SSlot slot, SPipe pipe, int mana, int color)
 {
     for (int i = 0; i < _buttons.Count; ++i)
     {
         int addedMana = _buttons[i].AddMana(mana, color);
         if (addedMana > 0)
         {
             mana -= addedMana;
             Vector3    startPos = transform.parent.transform.InverseTransformPoint(slot.transform.position);
             Vector3    endPos   = transform.parent.transform.parent.InverseTransformPoint(_buttons[i].transform.position);
             GameObject effect   = GameObject.Instantiate(CollectManaEffect, Vector3.zero, Quaternion.identity) as GameObject;
             effect.transform.SetParent(transform.parent.transform, false);
             effect.transform.localPosition = startPos;
             List <Vector3>   path        = GameManager.Instance.GameData.XMLSplineData[String.Format("chip_get_{0}", UnityEngine.Random.Range(1, 4))];
             MoveSplineAction splineMover = new MoveSplineAction(effect, path, startPos, endPos, Consts.ADD_POINTS_EFFECT_TIME);
             _worker.AddParalelAction(splineMover);
             GameObject.Destroy(effect, Consts.ADD_MANA_EFFECT_TIME + 0.1f);
         }
         if (mana <= 0)
         {
             break;
         }
     }
     return(mana);
 }
Esempio n. 2
0
//    public void ApplyPipe(SPipe apipe)
//    {
//        Pipe = apipe;
//        Pipe.SetXY(X, Y, false);
//    }

    public SPipe TakePipe()
    {
        SPipe res = Pipe;

        Pipe = null;
        return(res);
    }
Esempio n. 3
0
    public override bool IsCanApply()
    {
        GameBoard    board = GameManager.Instance.Game;
        List <SSlot> slots = new List <SSlot>();

        for (int i = 0; i < GameBoard.WIDTH; ++i)
        {
            for (int j = 0; j < GameBoard.HEIGHT; ++j)
            {
                SSlot slot = board.Slots[i, j];
                SPipe pipe = slot.Pipe;
                if (pipe != null)
                {
                    slots.Add(slot);
                }
            }
        }
        return(slots.Count > 0);
    }
Esempio n. 4
0
    public bool CheckSlot(SSlot slot)
    {
        if (!slot || !slot.Pipe || slot.Pipe.PipeType != EPipeType.Colored)
        {
            return(false);
        }
        int pipeColor = slot.Pipe.AColor;

        if (pipeColor < Slots.Count)
        {
            if (Slots[pipeColor].CheckAim(slot.Pipe.Param))
            {
                _creaturesManager.CustomizeCreature(pipeColor, Slots[pipeColor].GetLevel());
                SPipe pipe = slot.TakePipe();
                FlyingEffect(pipe);
                return(true);
            }
        }
        return(false);
    }
Esempio n. 5
0
 public void SetPipe(SPipe apipe, bool setPositionToo = true)
 {
     Pipe = apipe;
     Pipe.SetXY(X, Y, setPositionToo);
 }
Esempio n. 6
0
    public override void ApplyPowerup()
    {
        GameBoard board = GameManager.Instance.Game;

        board.SetGameState(EGameState.PlayerUsedPowerup, "PowerUp_Reshuffle");
        List <SSlot> slots = new List <SSlot>();

        for (int i = 0; i < GameBoard.WIDTH; ++i)
        {
            for (int j = 0; j < GameBoard.HEIGHT; ++j)
            {
                SSlot slot = board.Slots[i, j];
                SPipe pipe = slot.Pipe;
                if (pipe != null)
                {
                    slots.Add(slot);
                }
            }
        }
        if (slots.Count > 0)
        {
            //int boosterPower = GameManager.Instance.Player.BoosterLevel * Consts.PU__POWER_PER_LEVEL_RESHUFFLE;
            //boosterPower = Mathf.Min(slots.Count, boosterPower);
            int boosterPower = slots.Count;
            // take pipes from slots
            slots = Helpers.ShuffleList(slots);
            List <SPipe> pipes = new List <SPipe>();
            for (int i = 0; i < boosterPower; ++i)
            {
                pipes.Add(slots[i].TakePipe());
            }
            // find free slots
            List <SSlot> freeSlots = board.GetEmptySSlots();
            // randomly move pipes to slots
            float maxTime = 0;
            for (int i = 0; i < boosterPower; ++i)
            {
                // add to new slot
                SPipe pipe  = pipes[i];
                int   randI = UnityEngine.Random.Range(0, freeSlots.Count);
                SSlot slot  = freeSlots[randI];

                if (slot.X == pipe.X && slot.Y == pipe.Y && freeSlots.Count > 1)
                {
                    // we must change slot
                    --i;
                    continue;
                }

                freeSlots.RemoveAt(randI);
                // find distance
                float dx       = pipe.X - slot.X;
                float dy       = pipe.Y - slot.Y;
                float distance = Mathf.Sqrt(dx * dx + dy * dy);
                // find move time, check max time
                float moveTime = distance * Consts.PU__RESHUFFLE_TIME_PER_SLOT;
                if (moveTime > maxTime)
                {
                    maxTime = moveTime;
                }
                //
                slot.SetPipe(pipe, false);
                // move upper
                Vector3 oldPos = pipe.transform.position;
                oldPos.z = GameBoard.PipeZ - 1.0f;
                pipe.transform.position = oldPos;
                // fly to new slot
                GameObject pipeObj = pipe.gameObject;
                LeanTween.cancel(pipeObj);
                Vector3 newPos = slot.transform.position;
                newPos.z = GameBoard.PipeZ;
                LeanTween.move(pipeObj, newPos, moveTime)
                //.setDelay(i * 0.01f)
                .setEase(LeanTweenType.easeInOutSine);
            }
            MusicManager.playSound("reshuffle");
            pipes.Clear();
            freeSlots.Clear();
            ////
            //EventData eventData = new EventData("OnPowerUpUsedEvent");
            //eventData.Data["type"] = GameData.PowerUpType.Reshuffle;
            //GameManager.Instance.EventManager.CallOnPowerUpUsedEvent(eventData);
            ////
            LeanTween.delayedCall(maxTime, () =>
            {
                if (!board.CheckIfOutOfMoves())
                {
                    board.SetGameState(EGameState.PlayersTurn, "Reshuffle powerup completed");
                }
            });
            //Invoke("CheckIfOutOfMoves", maxTime);
        }
        else
        {
            //TODO wrong sound, nothing happens
            board.SetGameState(EGameState.PlayersTurn, "Reshuffle wrong");
        }
    }
Esempio n. 7
0
    private float CreateAttack(GameBoard board, SSlot slot, int pipeColor, int attackPower)
    {
        EnemySlot enemySlot = board.AEnemies.Slots[slot.X]; // find enemies slot in front of slot
        Enemy     enemy     = enemySlot.GetEnemy();

        if (!enemy)
        {
            board.BreakePipeInSlot(slot, (slot.Pipe as Pipe_Colored).GetExplodeEffectPrefab());
            OnEndAttack();
            return(0);
        }
        SPipe pipe = slot.TakePipe();

        //Time.timeScale = 0.1f;
        Vector3 fromPos = pipe.transform.position;
        Vector3 toPos   = enemySlot.transform.position;

        float distance = Mathf.Abs(fromPos.y - toPos.y);
        float speed    = 0.05f; // per unit
        float flyTime  = distance * speed;

        Vector3[] pathPoints = new Vector3[5];
        // from
        Vector3 p1 = fromPos;

        p1.z                    = -11;
        pathPoints[1]           = p1;
        pipe.transform.position = p1;
        // to
        Vector3 p3 = toPos;

        p3.z          = -11;
        pathPoints[3] = p3;
        // first liverage
        Vector3 p0 = p1;

        p0.x         += UnityEngine.Random.Range(-4.0f, 4.0f);
        p0.y         += UnityEngine.Random.Range(-2.0f, -4.0f);
        pathPoints[0] = p0;
        // second liverage
        Vector3 p4 = p3;

        p4.x         += UnityEngine.Random.Range(-4.0f, 4.0f);
        p4.y         += UnityEngine.Random.Range(2.0f, 4.0f);
        pathPoints[4] = p4;
        // middle point
        Vector3 p2 = (p1 + p3) / 2.0f;

        p2.x         += UnityEngine.Random.Range(-3.0f, 3.0f);
        pathPoints[2] = p2;
        //
        LTSpline spline = new LTSpline(pathPoints);
        //
        //GameObject trailEffect = GameObject.Instantiate(FlyEffectPrefab, Vector3.zero, Quaternion.identity) as GameObject;
        //trailEffect.transform.SetParent(pipe.transform, false);
        //trailEffect.transform.localPosition = Vector3.zero;
        ////trailEffect.transform.position = fromPos;
        ////trailEffect.transform.localScale = new Vector3(0, 0, 1);
        ////LeanTween.scale(trailEffect, Vector3.one, Consts.FINAL_ATTACK_TIME / 2.0f)
        ////    .setEase(LeanTweenType.easeInOutSine)
        ////    .setLoopPingPong(1)
        Vector3 startAngle = pipe.transform.eulerAngles;

        LeanTween.value(pipe.gameObject, 0.0f, 1.0f, flyTime)
        .setOnUpdate((float norm) =>
        {
            Vector3 pos             = spline.point(norm);
            pipe.transform.position = pos;
        })
        .setOnComplete(() =>
        {
            ApplyAttack(board, enemy, pipeColor, attackPower);
            //Destroy(trailEffect, Consts.ADD_POINTS_EFFECT_TIME + 0.2f);
            pipe.transform.localScale = Vector3.one;
            pipe.transform.localScale = Vector3.zero;
            pipe.gameObject.SetActive(false);
            //pipe.PlayHideAnimation();
        })
        .setEaseInOutSine();
        LeanTween.rotateX(pipe.gameObject, startAngle.x + 40, (flyTime - 0.05f) / 2.0f)
        .setLoopPingPong(1)
        .setEase(LeanTweenType.easeInOutSine);
        LeanTween.rotateY(pipe.gameObject, startAngle.y + 40, (flyTime - 0.05f) / 2.0f)
        .setLoopPingPong(1)
        .setEase(LeanTweenType.easeInOutSine);
        float scale = 0.85f;

        LeanTween.scale(pipe.gameObject, new Vector3(scale, scale, scale), flyTime - 0.1f);
        return(flyTime);
    }
Esempio n. 8
0
    protected void FlyingEffect(SPipe pipe)
    {
        //Time.timeScale = 0.1f;
        int pipeColor = pipe.AColor;
        //pipe.PlayHideAnimation();
        Vector3 fromPos = pipe.transform.position;
        Vector3 toPos   = Slots[pipeColor].transform.position;

        Vector3[] pathPoints = new Vector3[5];
        // from
        Vector3 p1 = fromPos;

        p1.z                    = -11;
        pathPoints[1]           = p1;
        pipe.transform.position = p1;
        // to
        Vector3 p3 = toPos;

        p3.z          = -11;
        pathPoints[3] = p3;
        // first liverage
        Vector3 p0 = p1;

        p0.x         += UnityEngine.Random.Range(-4.0f, 4.0f);
        p0.y         += UnityEngine.Random.Range(-2.0f, -4.0f);
        pathPoints[0] = p0;
        // second liverage
        Vector3 p4 = p3;

        p4.x         += UnityEngine.Random.Range(-4.0f, 4.0f);
        p4.y         += UnityEngine.Random.Range(2.0f, 4.0f);
        pathPoints[4] = p4;
        // middle point
        Vector3 p2 = (p1 + p3) / 2.0f;

        p2.x         += UnityEngine.Random.Range(-3.0f, 3.0f);
        pathPoints[2] = p2;
        //
        LTSpline spline = new LTSpline(pathPoints);
        //
        //GameObject trailEffect = GameObject.Instantiate(FlyEffectPrefab, Vector3.zero, Quaternion.identity) as GameObject;
        //trailEffect.transform.SetParent(pipe.transform, false);
        //trailEffect.transform.localPosition = Vector3.zero;
        ////trailEffect.transform.position = fromPos;
        ////trailEffect.transform.localScale = new Vector3(0, 0, 1);
        ////LeanTween.scale(trailEffect, Vector3.one, Consts.ADD_POINTS_EFFECT_TIME / 2.0f)
        ////    .setEase(LeanTweenType.easeInOutSine)
        ////    .setLoopPingPong(1)
        Vector3 startAngle = pipe.transform.eulerAngles;

        LeanTween.value(pipe.gameObject, 0.0f, 1.0f, Consts.ADD_POINTS_EFFECT_TIME)
        .setOnUpdate((float norm) =>
        {
            Vector3 pos             = spline.point(norm);
            pipe.transform.position = pos;
        })
        .setOnComplete(() =>
        {
            //Destroy(trailEffect, Consts.ADD_POINTS_EFFECT_TIME + 0.2f);
            pipe.transform.localScale = Vector3.one;
            //pipe.PlayHideAnimation();
            pipe.gameObject.SetActive(false);
            pipe.transform.localScale = Vector3.zero;
            Slots[pipeColor].CheckMark.SetActive(true);
        })
        .setEaseInOutSine();
        LeanTween.rotateX(pipe.gameObject, startAngle.x + 40, (Consts.ADD_POINTS_EFFECT_TIME - 0.05f) / 2.0f)
        .setLoopPingPong(1)
        .setEase(LeanTweenType.easeInOutSine);
        LeanTween.rotateY(pipe.gameObject, startAngle.y + 40, (Consts.ADD_POINTS_EFFECT_TIME - 0.05f) / 2.0f)
        .setLoopPingPong(1)
        .setEase(LeanTweenType.easeInOutSine);
        float scale = 0.85f;

        LeanTween.scale(pipe.gameObject, new Vector3(scale, scale, scale), Consts.ADD_POINTS_EFFECT_TIME - 0.1f);
    }