Exemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);



            // TODO: use this.Content to load your game content here

            texturen    = new Texture2D[3];
            texturen[0] = Content.Load <Texture2D>("moorhuhn_rechts");
            texturen[1] = Content.Load <Texture2D>("moorhuhn_links");
            texturen[2] = Content.Load <Texture2D>("moorhuhn_rechts_shot");
            //100,50,2,15,25
            background = Content.Load <Texture2D>("background");
            fadenkreuz = Content.Load <Texture2D>("fadenkreuz");

            schuss_voll = Content.Load <Texture2D>("schuss_voll");
            schuss1     = Content.Load <Texture2D>("schuss1");
            schuss2     = Content.Load <Texture2D>("schuss2");
            schuss3     = Content.Load <Texture2D>("schuss3");
            schuss4     = Content.Load <Texture2D>("schuss4");
            schuss5     = Content.Load <Texture2D>("schuss5");
            schuss6     = Content.Load <Texture2D>("schuss6");
            schuss7     = Content.Load <Texture2D>("schuss7");
            schuss8     = Content.Load <Texture2D>("schuss8");


            font = Content.Load <SpriteFont>("SpriteFont1");

            int i = rnd.Next(0, 2);

            sprite = new AnimatedSprite(texturen[i], 2, 5);
            sprite_liste.AddFirst(sprite);

            erschossenesHuhn = new AnimatedSprite(texturen[2], 2, 2);
            fallende_huener_liste.AddFirst(erschossenesHuhn);

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

            Position         = moorhuener.Position;
            mousePosition    = new Vector2(mouse.X, mouse.Y);
            aktuelleHuhn_pos = new Vector2[1];
        }
Exemplo n.º 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);
        }