Exemplo n.º 1
0
        public Misil(Vaca dueño, int XE, int YE)
        {
            vaca      = dueño;
            Image     = Game1.TheGame.Content.Load <Texture2D>("Images/disparo");
            Rectangle = new Rectangle(XE, YE, 50, 50);
            Vida      = 100;
            var w = Image.Width / 2;

            for (int i = 0; i < 2; i++)
            {
                rectangulos.Add(new Rectangle(w * i, 0, w, Image.Height));
            }
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            if (gameTime.TotalGameTime.Subtract(frametime).Milliseconds > 200)
            {
                frametime = gameTime.TotalGameTime;
                selectedRectangle++;
                if (selectedRectangle > 1)
                {
                    selectedRectangle = 0;
                }
            }
            #region coordenadas

            int x = Rectangle.X;

            x -= 2;

            Rectangle = new Rectangle(x, Rectangle.Y,
                                      Rectangle.Width, Rectangle.Height);

            if (Rectangle.X < -100)
            {
                Game1.TheGame.Actualizaciones.Add(this);
            }

            #endregion

            #region Choque

            if (gameTime.TotalGameTime.Subtract(lasttime).Milliseconds > 500)
            {
                lasttime = gameTime.TotalGameTime;
                Vaca LaVaca = null;
                foreach (var item in Game1.TheGame.sprites)
                {
                    if (item is Vaca)
                    {
                        LaVaca = item as Vaca;
                        break;
                    }
                }
                foreach (var item in Game1.TheGame.sprites)
                {
                    if (item is Vaca)
                    {
                        LaVaca = item as Vaca;
                        break;
                    }
                }
                if (LaVaca == null)
                {
                    throw new NullReferenceException("No esta la vaca???");
                }
                if (Rectangle.Intersects(LaVaca.Rectangle))
                {
                    SoundEffect sonido = Game1.TheGame.Sounds[Game1.Sonidos.Grito];
                    sonido.CreateInstance();
                    sonido.Play();
                    Explosion explosion = new Explosion(Rectangle.Location.X, Rectangle.Location.Y);
                    LaVaca.Vida  -= 20;
                    LaVaca.estado = 1;
                    Game1.TheGame.Actualizaciones.Add(this);
                    Game1.TheGame.Actualizaciones.Add(explosion);
                }
            }
            #endregion

            if (Vida <= 0)
            {
                Explosion explosion = new Explosion(Rectangle.Location.X, Rectangle.Location.Y);
                Game1.TheGame.Actualizaciones.Add(this);
                Game1.TheGame.Actualizaciones.Add(explosion);
            }
        }