Пример #1
0
    private void PrepareToPut()
    {
        if (putting)
        {
            return;
        }

        if (shakeCameraOnDestroy)
        {
            CameraControl.ins.ShakeCamera(shakeInfo);
        }

        putting = true;
        if (destroyRewards.Length > 0)
        {
            SpawnDestroyEvent();
        }

        if (triggerAnimation.BeenSet)
        {
            GetComponent <Animator>().SetTrigger(triggerAnimation.trigger);
        }
        else
        {
            WeaponPrefabPool.GetPool(type).PutWeapon(this);
        }
    }
Пример #2
0
    private void SpawnDestroyEvent()
    {
        float chance = Random.Range(0f, 1f);

        for (int i = 0; i < destroyRewards.Length; i++)
        {
            if (chance <= destroyRewards[i].Chance)
            {
                Vector3 vec = new Vector3(Random.Range(0f, 1f), Random.Range(0f, 1f));
                switch (destroyRewards[i].Type)
                {
                case DestroyEventType.MedPack:
                    RewardPrefabPool.GetPool(RewardType.MedPack).GetFromPool().Setup(transform.position, RandomVec() * 2);
                    break;

                case DestroyEventType.MissileSupply:
                    RewardPrefabPool.GetPool(RewardType.MissileSupply).GetFromPool().Setup(transform.position, RandomVec() * 2);
                    break;

                case DestroyEventType.Explode:
                    Weapon explosion = WeaponPrefabPool.GetPool(WeaponType.Explosion).GetFromPool();
                    explosion.Setup(transform.position, Vector3.zero);
                    explosion.StartCoroutine(DelayExecute(1, delegate {
                        explosion.GetComponent <Animator>().SetTrigger("End");
                    }));
                    break;
                }

                if (onlyOneDestroyEvent)
                {
                    break;
                }
            }
        }
    }
Пример #3
0
    public void ShootMissle()
    {
        if (stuning)
        {
            return;
        }

        if (missleCount > 0)
        {
            WeaponPrefabPool misslePool = WeaponPrefabPool.GetPool(WeaponType.PlayerMissle);
            if (misslePool.AliveObjects.Count == 0)
            {
                missleCount--;
                misslePool.GetFromPool().Setup(transform.position, Vector2.up * missleSpeed);
            }
        }
    }
Пример #4
0
    void Spawn()
    {
        WeaponPrefabPool pool = WeaponPrefabPool.GetPool(spawnWeaponeType);

        if (spawnLimit > -1 && pool.AliveObjects.Count >= spawnLimit)
        {
            return;
        }

        if (spawnType == SpawnType.OneByOne)
        {
            spawningPosIndex++;
            if (spawningPosIndex >= spawningPos.Length)
            {
                spawningPosIndex = 0;
            }

            float   angle;
            Vector3 axis;
            spawningPos[spawningPosIndex].rotation.ToAngleAxis(out angle, out axis);
            angle += 90 + Random.Range(-2f, 2f);

            Weapon bullet = pool.GetFromPool();

            bullet.Setup(spawningPos[spawningPosIndex].position, MiltiplyVector2(DegreeToVector2(angle), vecMultiplier), rotateType == RotateType.None? Quaternion.identity : transform.rotation);
        }
        else
        {
            for (spawningPosIndex = 0; spawningPosIndex < spawningPos.Length; spawningPosIndex++)
            {
                float   angle;
                Vector3 axis;
                spawningPos[spawningPosIndex].rotation.ToAngleAxis(out angle, out axis);

                Weapon bullet = pool.GetFromPool();
                angle += 90 + Random.Range(-2f, 2f);

                bullet.Setup(spawningPos[spawningPosIndex].position, MiltiplyVector2(DegreeToVector2(angle), vecMultiplier), rotateType == RotateType.None ? Quaternion.identity : transform.rotation);
            }
        }
    }
Пример #5
0
    private void DecideMovement()
    {
        runAwayFrom.Clear();
        getCloseTo.Clear();
        float x = transform.position.x, y = transform.position.y;

        if (Boss.ins.UsingLaser)
        {
            runAwayFrom.Add(new Vector3(Boss.ins.transform.position.x, y));
        }

        List <Weapon> bombs = WeaponPrefabPool.GetPool(WeaponType.BossBomb).AliveObjects;

        for (int _i = 0; _i < bombs.Count; _i++)
        {
            Vector3 bombPos = bombs[_i].transform.position;

            float distance = (bombPos - transform.position).sqrMagnitude;
            if (distance < 16)
            {
                runAwayFrom.Add(bombPos);
            }
            else if (bombPos.y > y && Mathf.Abs(bombPos.x - x) < 3)
            {
                getCloseTo.Add(new Vector3(bombPos.x, y));
            }
        }

        List <Weapon> bullets = WeaponPrefabPool.GetPool(WeaponType.BossBullet).AliveObjects;

        for (int _i = 0; _i < bullets.Count; _i++)
        {
            Vector3 bulletPos = bullets[_i].transform.position;

            float distance = (bulletPos - transform.position).sqrMagnitude;
            if (distance < 4)
            {
                runAwayFrom.Add(bulletPos);
            }
            else if (bulletPos.y > y && Mathf.Abs(bulletPos.x - x) < 3)
            {
                getCloseTo.Add(new Vector3(bulletPos.x, y));
            }
        }

        List <Weapon> minions = WeaponPrefabPool.GetPool(WeaponType.Minion).AliveObjects;

        for (int _i = 0; _i < minions.Count; _i++)
        {
            Vector3 minionPos = minions[_i].transform.position;

            float distance = (minionPos - transform.position).sqrMagnitude;
            if (distance < 9)
            {
                runAwayFrom.Add(minionPos);
            }
            else if (minionPos.y > y && Mathf.Abs(minionPos.x - x) < 3)
            {
                getCloseTo.Add(new Vector3(minionPos.x, y));
            }
        }

        // for (int i = 0; i < MedPack.Pools.AliveObjects.Count; i++) {
        //     Vector3 medPackPos = MedPack.Pools.AliveObjects[i].transform.position;

        //     float distance = (medPackPos - transform.position).sqrMagnitude;
        //     if (distance < 11) {
        //         getCloseTo.Add(medPackPos);
        //     }
        // }

        result = Vector3.zero;

        if (runAwayFrom.Count > 0 || getCloseTo.Count > 0)
        {
            for (int i = 0; i < runAwayFrom.Count; i++)
            {
                float distance = (runAwayFrom[i] - transform.position).sqrMagnitude;
                if (distance == 0)
                {
                    result += RandomVectorDirection();
                }
                else
                {
                    result += (transform.position - runAwayFrom[i]) * Mathf.Min(0.9f / distance, 2);
                }
            }

            for (int i = 0; i < getCloseTo.Count; i++)
            {
                float distance = (getCloseTo[i] - transform.position).sqrMagnitude;
                if (distance != 0)
                {
                    result += (getCloseTo[i] - transform.position) * Mathf.Min(0.4f / distance, 2);
                }
            }
        }
        else
        {
            result.x = Boss.ins.transform.position.x - x;
        }

        controller.SetNextMovement(new PlayerContoller.Movement(result));
    }
Пример #6
0
 void OnTriggerAnimationEnd()
 {
     WeaponPrefabPool.GetPool(type).PutWeapon(this);
 }