Exemple #1
0
    //当攻击键按下 TODO 不对啊还有子弹条没考虑进去-->有道理哦
    //那还要留一个UI的接口
    public void Fire()
    {
        if (FireLock)
        {
            return;
        }
        if (canFire)
        {
            float damage = 0;
            float speed  = 0;
            EffectManager.EffectType effectType = EffectManager.EffectType.End;
            GameObject BulletPrefab             = BulletNormal;
            switch (bulletType)
            {
            case BulletType.None:
                damage       = NoneDamage;
                speed        = NoneSpeed;
                effectType   = EffectManager.EffectType.PlayerNormalOut;
                BulletPrefab = BulletNormal;
                break;

            case BulletType.Strong:
                damage       = StrongDamage;
                speed        = StrongSpeed;
                effectType   = EffectManager.EffectType.PlayerStrongOut;
                BulletPrefab = BulletStrong;
                break;

            case BulletType.Bounce:
                damage       = BounceDamage;
                speed        = BounceSpeed;
                effectType   = EffectManager.EffectType.PlayerTanOut;
                BulletPrefab = BulletTan;
                break;

            default:
                break;
            }
            canFire = false;
            float interval = shoot_interval - shoot_change_interval * energy / maxEnergy;
            damage += damage * energy / maxEnergy * damage_change;
            bullet -= fireCost * interval;
            StartCoroutine(Statics.WorkAfterSeconds(() => canFire = true, interval));
            var        pos      = Statics.V3toV2(transform.position);
            GameObject GObullet = GameObject.Instantiate(BulletPrefab, Statics.V2toV3(canBomb ? FirePosHeart.position : FirePosEdge.position), Quaternion.identity) as GameObject;
            GObullet.SetActive(true);
            //bullet.GetComponent<SpriteRenderer>().sprite = sprite;
            PlayerBullet playerBullet = GObullet.AddComponent <PlayerBullet>();
            playerBullet.Init(bulletType, damage, false, GObullet.AddComponent <Move>());
            float angle = Mathf.Atan2((MOUSE - pos).y, (MOUSE - pos).x) * Mathf.Rad2Deg + Random.Range(-deviation, deviation) * (1 - energy / maxEnergy);
            GObullet.transform.rotation = Quaternion.Euler(0, 0, angle);
            Vector2 direct = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad));
            playerBullet.move.SetLineType(pos, direct, speed * 2, 0, 0, GObullet.GetComponent <Rigidbody2D>());
            //playerBullet.StartCoroutine(Statics.WorkAfterSeconds(() => { playerBullet.move.acc = 0; }, 0.5f));
            EffectManager.Instance.PlayEffect(effectType, canBomb ? FirePosHeart.position : FirePosEdge.position, transform.rotation, 1f);
            AudioManager.Instance.PlaySound("Shoot2");
        }
    }
Exemple #2
0
    void SimpleFire()
    {
        UseEnergy(simpleCost);

        GameObject   bullet       = factory.Spawn(FactoryManager.ProductType.playerBullet);
        PlayerBullet playerBullet = bullet.GetComponent <PlayerBullet>();

        Vector2 bulletPosition = new Vector2(transform.position.x, transform.position.y);

        playerBullet.SetBulletType(bulletType);
        playerBullet.Init(damage, speed, Vector2.right, bulletPosition);
    }
Exemple #3
0
    void SpiralFire()
    {
        UseEnergy(spiralCost);

        for (int i = 0; i < 4; i++)
        {
            GameObject   bullet       = factory.Spawn(FactoryManager.ProductType.playerBullet);
            PlayerBullet playerBullet = bullet.GetComponent <PlayerBullet>();

            Vector2 bulletPosition = new Vector2(transform.position.x, transform.position.y);
            playerBullet.SetBulletType(bulletType);
            playerBullet.Init(damage, speed, Rotate(Vector2.right, i * Mathf.PI / 2), bulletPosition);
        }
    }
    public void Shoot(GameObject bullet, float damage)
    {
        PlayerBullet playerBulletOne   = Instantiate(bullet, shootPoint.position, transform.rotation).GetComponent <PlayerBullet>();
        PlayerBullet playerBulletTwo   = Instantiate(bullet, shootPoint.position, transform.rotation).GetComponent <PlayerBullet>();
        PlayerBullet playerBulletThree = Instantiate(bullet, shootPoint.position, transform.rotation).GetComponent <PlayerBullet>();
        PlayerBullet playerBulletFour  = Instantiate(bullet, shootPoint.position, transform.rotation).GetComponent <PlayerBullet>();
        PlayerBullet playerBulletFive  = Instantiate(bullet, shootPoint.position, transform.rotation).GetComponent <PlayerBullet>();

        audio[0].Play();

        playerBulletOne.Init(damage);
        playerBulletTwo.Init(damage, new Vector3(0.1f, 0.1f, 0f));
        playerBulletThree.Init(damage, new Vector3(-0.1f, -0.1f, 0f));
        playerBulletFour.Init(damage, new Vector3(0.1f, 0.2f, 0f));
        playerBulletFive.Init(damage, new Vector3(-0.1f, -0.2f, 0f));
    }
    protected virtual PlayerBullet CreateandPushBullet(GameObject bullet)
    {
        GameObject obj = Instantiate(bullet, Vector3.zero, Quaternion.identity) as GameObject;

        obj.tag              = "PlayerBullet";
        obj.layer            = 11;
        obj.transform.parent = gameObject.transform;

        PlayerBullet newBullet = obj.AddComponent <PlayerBullet>();

        newBullet.Init();

        obj.SetActive(false);

        m_CurBulletList.Enqueue(newBullet);

        return(newBullet);
    }
    private void CheckForEnemies()
    {
        if (shotTimer >= shotTimerMax)
        {
            bool hasShot = false;

            List <Collider2D> colliders = new List <Collider2D>(Physics2D.OverlapCircleAll(transform.position, 1f));

            colliders.ForEach(collider => {
                Enemy enemy = collider.GetComponent <Enemy>();
            });

            colliders.ForEach(collider => {
                if (collider.tag == "Enemy" && !hasShot)
                {
                    Enemy enemy = collider.GetComponent <Enemy>();

                    if (!enemy.isDead)
                    {
                        Vector3 objectPosition = enemy.transform.position;
                        Vector3 towerPosition  = towerShotgun.transform.position;

                        objectPosition.x = objectPosition.x - towerPosition.x;
                        objectPosition.y = objectPosition.y - towerPosition.y;

                        towerShotgun.transform.rotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Atan2(objectPosition.y, objectPosition.x) * Mathf.Rad2Deg));

                        PlayerBullet playerBullet = Instantiate(laser, towerShotgun.transform.position, towerShotgun.transform.rotation).GetComponent <PlayerBullet>();
                        playerBullet.Init(1f);

                        hasShot   = true;
                        shotTimer = 0f;
                    }
                }
            });
        }
        else
        {
            shotTimer += Time.deltaTime;
        }
    }
Exemple #7
0
 public void ShootCut()
 {
     Debug.Log("cut run");
     foreach (var item in KeyPoints)
     {
         Vector2 tmpvec = transform.TransformPoint(item.vector) - transform.position;
         Debug.Log(tmpvec);
         GameObject GObullet = GameObject.Instantiate(BulletCut, transform.position, Quaternion.identity) as GameObject;
         GObullet.SetActive(true);
         GObullet.GetComponent <PlayerCut>().SetAngle(item.left, item.right);
         PlayerBullet playerBullet = GObullet.AddComponent <PlayerBullet>();
         playerBullet.Init(BulletType.Strong, 50, false, GObullet.AddComponent <Move>());
         float angle = Mathf.Rad2Deg * Mathf.Atan2(tmpvec.y, tmpvec.x);
         GObullet.transform.rotation = Quaternion.Euler(0, 0, angle);
         Vector2 direct = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad));
         playerBullet.move.rotate = 180;
         playerBullet.move.SetLineType(transform.position, direct, CutVelocity, CutAcc, CutAccTime, GObullet.GetComponent <Rigidbody2D>());
         if (CutLastTime > 0.001f)
         {
             Destroy(GObullet, CutLastTime);
         }
         //playerBullet.StartCoroutine(Statics.WorkAfterSeconds(() => { playerBullet.move.acc = 0; }, 0.5f));
     }
 }