예제 #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");
        }
    }
예제 #2
0
 //初始化 应该写完了 TODO
 public void Init(float d, bool s, Move m, Type t, EffectManager.EffectType effect)
 {
     damage         = d;
     isStatic       = s;
     move           = m;
     type           = t;
     OnEffect       = effect;
     gameObject.tag = t.ToString();
 }