Пример #1
0
        //update method
        public override void Update(GameTime gameTime)
        {
            //determine how much damage the bullet should do
            foreach (GameComponent g in game.Components)
            {
                if (g is PlayerSprite)
                {
                    PlayerSprite p = (PlayerSprite)g;
                    Weapon       w = p.GetWeapon();
                    if (w.GetWeaponType() == WeaponType.Shotgun)
                    {
                        damage = 1;
                    }
                    else
                    {
                        damage = 1;
                    }
                }
            }

            //logic for determining which direction the bullet should move
            position += direction * speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            Sprite collisionSprite = new Sprite(game);

            //check for collisions
            foreach (GameComponent g in game.Components)
            {
                if (g is Enemy)
                {
                    Enemy     s = (Enemy)g;
                    Rectangle b = s.getRectangle();
                    if (b.Intersects(this.boundingBox))
                    {
                        collisionSprite = s;
                        remove          = true;
                        s.removeHelth(damage);
                        s.setShouldColor();
                    }
                }
            }

            //remove objects that have collided (can't be removed in the loop)
            if (remove)
            {
                game.Components.Remove(this);
            }

            base.Update(gameTime);
        }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            //determine which icon to display
            if (player.hasPistol == true && type == WeaponType.Pistol)
            {
                WeaponAcquired();
            }
            if (player.hasAssaultRifle == true && type == WeaponType.AssaultRifle)
            {
                WeaponAcquired();
            }
            if (player.hasShotgun == true && type == WeaponType.Shotgun)
            {
                WeaponAcquired();
            }

            if (type == player.GetWeapon().GetWeaponType())
            {
                WeaponEquipped();
            }
        }