Exemplo n.º 1
0
    //读取对象池
    public void GetOut(string objectName, BulletManager.BulletType bulletType, Transform parent = null, Transform gun = null)
    {
        Bullet pre;

        if (pool.ContainsKey(objectName) && pool[objectName].Count > 0 && pool[objectName][0].bulletWorkType == Bullet.BulletWorkType.Idle)//如果存在子弹是关闭状态
        {
            pre = pool[objectName][0];
            pre.transform.parent   = parent;
            pre.transform.position = BulletPosition(gun);//gun.position;
            pre.transform.rotation = pre.m_transfrom.rotation;
            pre.gameObject.SetActive(true);
            BulletEmission(pre.transform, gun.transform);
        }
        else
        {
            if (!pool.ContainsKey(objectName))
            {
                GameObject gameObject = GameObject.Instantiate(Resources.Load(((int)bulletType).ToString())) as GameObject;
                gameObject.GetComponent <Bullet>().bulletWorkType = Bullet.BulletWorkType.Work;
                gameObject.transform.parent   = parent;
                gameObject.name               = objectName;
                gameObject.transform.position = BulletPosition(gun);//gun.position;
                gameObject.transform.rotation = gameObject.GetComponent <Bullet>().m_transfrom.rotation;
                prefab = gameObject;
                BulletEmission(gameObject.transform, gun.transform);
            }
        }
    }
Exemplo n.º 2
0
        public override void Update()
        {
            base.Update();
            if (IsActive)
            {
                if (!RocketIsOn && (Math.Abs(sprite.Rotation) <= accAngle) || (Math.Abs(sprite.Rotation) >= Math.PI - accAngle))
                {
                    sprite.Rotation = 0;
                    RigidBody.SetXVelocity(900 * Math.Sign(Velocity.X));

                    BulletManager.BulletType current = BulletManager.BulletType.Minipig;

                    if (pigShootCounter <= 3)
                    {
                        float random = (float)RandomGenerator.GetRandom(-200, 200);
                        Shootchild(current, new Vector2(sprite.position.X + random, sprite.position.Y + 30));

                        pigCounter = 0f;
                        pigShootCounter++;
                    }
                    else
                    {
                        OnDie();
                    }
                }
            }
        }
Exemplo n.º 3
0
    private void KeyInputUpdate()
    {
        BulletManager.BulletType currentBulletType = bulletType;

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            bulletType = BulletManager.BulletType.Default;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            bulletType = BulletManager.BulletType.Rapid;
        }
        else if (Input.GetKey(KeyCode.UpArrow))
        {
            bulletType = BulletManager.BulletType.Grendate;
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            bulletType = BulletManager.BulletType.WideA;
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            bulletType = BulletManager.BulletType.WideB;
        }

        if (currentBulletType != bulletType)
        {
            bulletManager.SetBulletType(bulletType);
        }
    }
Exemplo n.º 4
0
        public override Bullet Shoot(BulletManager.BulletType type, float speedPercentage = 1)
        {
            LastShootedBullet = base.Shoot(type, speedPercentage);
            shootCounter      = shootDelay;
            stateMachine.Switch((int)States.Shoot);

            return(LastShootedBullet);
        }
Exemplo n.º 5
0
        public void Shootchild(BulletManager.BulletType type, Vector2 position)
        {
            Bullet b = BulletManager.GetBullet(type);

            if (b != null)
            {
                Vector2 direction = new Vector2(0, 10);
                b.Shoot(position, direction);
            }
        }
Exemplo n.º 6
0
        public override Bullet Shoot(BulletManager.BulletType type, float speedPercentage = 1)
        {
            LastShotBullet    = base.Shoot(type, speedPercentage);
            shootCounter      = shootDelay;
            CurrentBulletType = Weapons.DecrementBullets();
            ((PlayScene)Game.CurrentScene).StopTimer();
            stateMachine.Switch((int)States.Shoot);


            return(LastShotBullet);
        }
Exemplo n.º 7
0
        public virtual void Shoot(BulletManager.BulletType type)
        {
            Bullet b = BulletManager.GetBullet(type);

            if (b != null)
            {
                float bulletOffsetX = b.Width / 2;
                if (b is EnemyBullet)
                {
                    bulletOffsetX = -bulletOffsetX;
                }
                b.Shoot(Position + cannonOffset + new Vector2(bulletOffsetX, 0));
            }
        }
Exemplo n.º 8
0
        public override void Shoot(BulletManager.BulletType type)
        {
            base.Shoot(type);
            int randBullet = RandomGenerator.GetRandom(0, 100);

            if (randBullet <= 30)
            {
                currentBulletType = BulletManager.BulletType.BigBlueLaser;
            }
            else
            {
                currentBulletType = BulletManager.BulletType.FireGlobe;
            }
        }
Exemplo n.º 9
0
        public override Bullet Shoot(BulletManager.BulletType type, float speedPercentage = 1.0f)
        {
            Bullet b = BulletManager.GetBullet(type);

            if (b != null)
            {
                float bulletOffsetX = b.Width / 2;

                Vector2 direction = new Vector2((float)Math.Cos(turret.Rotation), (float)Math.Sin(turret.Rotation));

                b.Shoot(turret.position + direction * (turretLength + bulletOffsetX), direction * speedPercentage);
                CameraManager.SetTarget(b);
            }

            return(b);
        }
Exemplo n.º 10
0
        public Bullet(Vector2 position, Vector2 velocity, String textureName = "bullet") : base(position, textureName)
        {
            IsActive = false;
            Type     = BulletManager.BulletType.StdBullet;

            sprite.pivot = new Vector2(sprite.Width / 2, sprite.Height / 2);
            ray          = sprite.Width / 2;

            RigidBody      = new RigidBody(sprite.position, this, null, null, true);
            RigidBody.Type = (uint)PhysicsManager.ColliderType.Bullet;
            RigidBody.SetCollisionMask((uint)(PhysicsManager.ColliderType.Player | PhysicsManager.ColliderType.Enemy));

            RigidBody.Velocity = new Vector2(velocity.X, velocity.Y);

            Rotation = (float)Math.Atan2(Velocity.Y, Velocity.X);//not updated!
        }
Exemplo n.º 11
0
        public override Bullet Shoot(BulletManager.BulletType type, float speedPercentage = 1.0f)
        {
            Bullet b = BulletManager.GetBullet(type);

            if (b != null)
            {
                float bulletOffsetX = b.Width / 2;

                Vector2 direction = new Vector2((float)Math.Cos(turret.Rotation), (float)Math.Sin(turret.Rotation));

                //AudioSource t = ((PlayScene)Game.CurrentScene).GetSource;
                //t.Play(AudioManager.GetAudio("shot"));
                //t.Volume = 0.5f;
                AudioManager.SetAudio("shot", speedPercentage);

                b.Shoot(turret.position + direction * (turretLength + bulletOffsetX), direction * speedPercentage);
                CameraManager.SetTarget(b);
            }

            return(b);
        }
Exemplo n.º 12
0
 public virtual Bullet Shoot(BulletManager.BulletType type, float speedPercentage = 1.0f)
 {
     return(null);
 }
Exemplo n.º 13
0
 public void AddBullets(BulletManager.BulletType type, int numBullets)
 {
     weapons[(int)type].NumBullets = weapons[(int)type].NumBullets + numBullets;
 }