示例#1
0
 public Moorhuener(AnimatedSprite huhn, Random rnd)
 {
     this.Huhn     = huhn;
     this.rnd      = rnd;
     this.Position = new Vector2((float)rnd.Next(100, 900), (float)rnd.Next(100, 500));
 }
示例#2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }


            if (moorhuener_liste.Count < 20)
            {
                if (timer >= 0.5f)
                {
                    int i = rnd.Next(0, 2);
                    sprite = new AnimatedSprite(texturen[i], 2, 5);

                    moorhuener = new Moorhuener(sprite, rnd);
                    moorhuener_liste.AddFirst(moorhuener);
                    sprite_liste.AddFirst(sprite);
                    timer = 0;


                    Console.WriteLine(i);
                }
            }
            sprite.Update();
            foreach (AnimatedSprite a in sprite_liste)
            {
                a.Update();
            }

            //foreach (AnimatedSprite a in fallende_huener_liste)
            //{
            //  a.Update();
            //}



            if (moorhuener_liste.Count >= 19)
            {
                moorhuener_liste.RemoveLast();
                sprite_liste.RemoveLast();
            }


            mouse_alt = mouse;
            mouse     = Mouse.GetState();
            Rectangle rechteck_mouse = new Rectangle(mouse.X, mouse.Y, 1, 1);



            List <Moorhuener> abgeschossen = new List <Moorhuener>();
            List <Moorhuener> druassen     = new List <Moorhuener>();



            foreach (Moorhuener a in moorhuener_liste)
            {
                if (a.Huhn.Texture == texturen[0])
                {
                    a.Position.X += 4.0f;
                    Rectangle rechteck_huhn = new Rectangle((int)a.Position.X, (int)a.Position.Y, a.Huhn.breite, a.Huhn.hoehe);
                    if (a.Position.X <= 1000)
                    {
                        if (rechteck_huhn.Intersects(rechteck_mouse))
                        {
                            if (mouse.LeftButton == ButtonState.Pressed && mouse_alt.LeftButton == ButtonState.Released)
                            {
                                abgeschossen.Add(a);
                                //  fallende_huener_liste.AddFirst(erschossenesHuhn);
                            }
                        }
                    }
                    else
                    {
                        druassen.Add(a);
                    }
                }
                else if (a.Huhn.Texture == texturen[1])
                {
                    a.Position.X -= 4.0f;
                    Rectangle rechteck_huhn = new Rectangle((int)a.Position.X, (int)a.Position.Y, a.Huhn.breite, a.Huhn.hoehe);
                    if (a.Position.X <= 1000)
                    {
                        if (rechteck_huhn.Intersects(rechteck_mouse))
                        {
                            if (mouse.LeftButton == ButtonState.Pressed && mouse_alt.LeftButton == ButtonState.Released)
                            {
                                abgeschossen.Add(a);
                                // fallende_huener_liste.AddFirst(erschossenesHuhn);
                            }
                        }
                    }
                    else
                    {
                        druassen.Add(a);
                    }
                }
            }

            foreach (Moorhuener i in druassen)
            {
                moorhuener_liste.Remove(i);
            }



            foreach (Moorhuener i in abgeschossen)
            {
                if (i.Huhn.Texture == texturen[0])
                {
                    counter += 5;
                }
                else if (i.Huhn.Texture == texturen[1])
                {
                    counter += 10;



                    // sprite = new AnimatedSprite(texturen[2], 2, 2);
                    //moorhuener = new Moorhuener(sprite, rnd);
                }
                else
                {
                    counter += 20;
                }
                moorhuener_liste.Remove(i);
            }

            Rectangle rechteck_fadenkreuz = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, fadenkreuz.Width, fadenkreuz.Height);

            if (mouse.X != rechteck_fadenkreuz.X && mouse.Y != rechteck_fadenkreuz.Y)
            {
                mousePosition = new Vector2(mouse.X - (fadenkreuz.Width / 2), mouse.Y - (fadenkreuz.Height / 2));
            }
            if (mouse.LeftButton == ButtonState.Pressed && mouse_alt.LeftButton == ButtonState.Released)
            {
                schuesse -= 1;
                if (schuesse == 0)
                {
                    magazin_leer = true;
                }
            }
            KeyboardState keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.R))

            {
                if (schuesse <= 0)
                {
                    magazin_leer = false;
                    schuesse     = 8;
                }
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }