public Banana(Mono dueño, int XE, int YE)
        {
            mono      = dueño;
            Image     = Game1.TheGame.Content.Load <Texture2D>("Images/banana_shoot");
            Rectangle = new Rectangle(XE, YE, 50, 50);
            Vida      = 100;
            var w = Image.Width / 12;

            for (int i = 0; i < 12; i++)
            {
                rectangulos.Add(new Rectangle(w * i, 0, w, Image.Height));
            }
        }
Beispiel #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 > 200)
            {
                lasttime = gameTime.TotalGameTime;
                Mono ElMono = null;
                foreach (var item in Game1.TheGame.sprites)
                {
                    if (item is Mono)
                    {
                        ElMono = item as Mono;
                        break;
                    }
                }
                foreach (var item in Game1.TheGame.sprites)
                {
                    if (item is Mono)
                    {
                        ElMono = item as Mono;
                        break;
                    }
                }
                if (ElMono == null)
                {
                    throw new NullReferenceException("No esta la vaca???");
                }
                if (Rectangle.Intersects(ElMono.Rectangle))
                {
                    SoundEffect sonido = Game1.TheGame.Sounds[Game1.Sonidos.Grito];
                    sonido.CreateInstance();
                    sonido.Play();
                    Explosion explosion = new Explosion(Rectangle.Location.X, Rectangle.Location.Y);
                    ElMono.Vida  -= 20;
                    ElMono.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);
            }
        }