Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            bulletTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (bulletTimer >= 1.0f && targets.Count != 0)
            {
                for (int i = 0; i < directions.Length; i++)
                {
                    Bullet bullet = new Bullet(bulletTexture, Vector2.Subtract(center, new Vector2(bulletTexture.Width / 2)), directions[i], 6, damage, content);
                    bulletList.Add(bullet);
                }
                bulletTimer = 0;
            }

            for (int i = 0; i < bulletList.Count; i++)
            {
                Bullet bullet = bulletList[i];
                bullet.Update(gameTime);

                if (!IsInRange(bullet.Center))
                {
                    bullet.Kill();
                }

                for (int j = 0; j < targets.Count; j++)
                {
                    if (targets[j] != null && Vector2.Distance(bullet.Center, targets[j].Center) < 48)
                    {
                        targets[j].CurrentHealth -= bullet.Damage;
                        bullet.Kill();
                        break;
                    }
                }

                if (bullet.IsDead())
                {
                    bulletList.Remove(bullet);
                    i--;
                }
            }
            //base.Update(gameTime);
        }
Esempio n. 2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (bulletTimer >= 0.75f && target != null)
            {
                Bullet bullet = new Bullet(bulletTexture, Vector2.Subtract(center,
                                                                           new Vector2(bulletTexture.Width / 2)), rotation, 6, damage, content);

                bulletList.Add(bullet);
                bulletTimer = 0;
            }

            for (int i = 0; i < bulletList.Count; i++)
            {
                Bullet bullet = bulletList[i];

                bullet.SetRotation(rotation);
                bullet.Update(gameTime);

                if (!IsInRange(bullet.Center))
                {
                    bullet.Kill();
                }

                if (target != null && Vector2.Distance(bullet.Center, target.Center) < 12)
                {
                    target.CurrentHealth -= bullet.Damage;
                    bullet.Kill();
                }

                if (bullet.IsDead())
                {
                    bulletList.Remove(bullet);
                    i--;
                }
            }
        }