Beispiel #1
0
        public static void LoadContent(ContentManager content, GameWindow window)
        {
            enemies = new List <Enemies>();
            Random random = new Random();

            menu = new Menu((int)State.Menu);
            menu.AddItem(content.Load <Texture2D>("sprites/menu/start"), (int)State.Level);
            menu.AddItem(content.Load <Texture2D>("sprites/menu/highscore"), (int)State.Highscore);
            menu.AddItem(content.Load <Texture2D>("sprites/menu/exit"), (int)State.Quit);
            player    = new Player(content.Load <Texture2D>("sprites/player/tempplayer"), 380, 400);
            scoreText = new PrintText(content.Load <SpriteFont>("sprites/Fonts/firstfont"));

            Texture2D enemyOne = content.Load <Texture2D>("sprites/enemies/enemyOne");
            Texture2D enemyTwo = content.Load <Texture2D>("sprites/enemies/enemyThree");

            for (int i = 0; i < 5; i++)
            {
                int rndX  = random.Next(140, window.ClientBounds.Width - enemyOne.Width - 140);
                int tempY = 100;
                NormalZombieBear temp1 = new NormalZombieBear(enemyOne, rndX, tempY, 1f, 0, 0);
                enemies.Add(temp1);
            }
            for (int i = 0; i < 3; i++)
            {
                int     rndX  = random.Next(100, window.ClientBounds.Width - enemyTwo.Width);
                int     Y     = 50;
                Enemy_2 temp2 = new Enemy_2(enemyTwo, rndX, Y, 1f, 0, 0);
                enemies.Add(temp2);
            }
            bas = new Base(content.Load <Texture2D>("sprites/player/Stacket"), 0, 280);
        }
Beispiel #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            Random     random     = new Random();
            MouseState state      = Mouse.GetState();
            Texture2D  tempSprite = Content.Load <Texture2D>("sprites/enemies/tempenemy");


            player.Update(Window, gameTime);
            {
                foreach (Enemies e in enemies.ToList())
                {
                    if (e.IsAlive)
                    {
                        e.Update(Window);

                        if (state.LeftButton == ButtonState.Pressed && player.CheckCollision(e))
                        {
                            if (gameTime.TotalGameTime.TotalMilliseconds > timeSinceLastKill + 300)
                            {
                                e.IsAlive = false;
                                player.Points++;
                                enemies.Remove(e);
                            }
                        }
                        if (bas.CheckCollision(e))
                        {
                            player.IsAlive = false;
                        }
                    }
                }
                if (enemies.Count < 5)
                {
                    int rndX              = random.Next(100, Window.ClientBounds.Width - tempSprite.Width - 100);
                    int tempY             = 100;
                    NormalZombieBear temp = new NormalZombieBear(tempSprite, rndX, tempY, 1f, 0, 0);
                    enemies.Add(temp);
                }
            }


            /*switch (currentstate)
             * {
             *  case State.Menu:
             *
             *
             *  default:
             *      KeyboardState keyboardState = Keyboard.GetState();
             *      currentStateHigh = State.EnterHighScore;
             *      break;
             * }if (highscore.EnterUpdate(gameTime, player.Points)) currentStateHigh = State.PrintHighScore;
             *      break;*/

            base.Update(gameTime);
        }
Beispiel #3
0
        private static void Reset(GameWindow window, ContentManager content)
        {
            player.Reset();
            enemies.Clear();

            Random    random   = new Random();
            Texture2D enemyOne = content.Load <Texture2D>("sprites/enemies/enemyOne");
            Texture2D enemyTwo = content.Load <Texture2D>("sprites/enemies/enemyThree");

            for (int i = 0; i < 5; i++)
            {
                int rndX  = random.Next(140, window.ClientBounds.Width - enemyOne.Width - 140);
                int tempY = 100;
                NormalZombieBear temp1 = new NormalZombieBear(enemyOne, rndX, tempY, 1f, 0, 0);
                enemies.Add(temp1);
            }
            for (int i = 0; i < 2; i++)
            {
                int     rndX  = random.Next(100, window.ClientBounds.Width - enemyTwo.Width);
                int     Y     = 50;
                Enemy_2 temp2 = new Enemy_2(enemyTwo, rndX, Y, 1f, 0, 0);
                enemies.Add(temp2);
            }
        }
Beispiel #4
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);
            enemies     = new List <Enemies>();
            Random random = new Random();

            player = new Player(Content.Load <Texture2D>("sprites/player/tempplayer"), 380, 400);

            Texture2D tempSprite = Content.Load <Texture2D>("sprites/enemies/tempenemy");

            for (int i = 0; i < 5; i++)
            {
                int rndX              = random.Next(100, Window.ClientBounds.Width - tempSprite.Width - 100);
                int tempY             = 100;
                NormalZombieBear temp = new NormalZombieBear(tempSprite, rndX, tempY, 1f, 0, 0);
                enemies.Add(temp);
            }
            bas = new Base(Content.Load <Texture2D>("sprites/player/Stacket"), 0, 280);

            //font = Content.Load<SpriteFont>("sprites/Fonts/firstfont");

            GameElements.LoadContent(Content, Window);
        }
Beispiel #5
0
        public static State RunUpdate(ContentManager content, GameWindow window, GameTime gameTime)
        {
            Random     random = new Random();
            int        rnd;
            MouseState state    = Mouse.GetState();
            Texture2D  enemyOne = content.Load <Texture2D>("sprites/enemies/enemyOne");
            Texture2D  enemyTwo = content.Load <Texture2D>("sprites/enemies/enemyThree");


            player.Update(window, gameTime);

            foreach (Enemies e in enemies.ToList())
            {
                if (e.IsAlive)
                {
                    e.Update(window);

                    if (state.LeftButton == ButtonState.Pressed && player.CheckCollision(e))
                    {
                        if (gameTime.TotalGameTime.TotalMilliseconds > timeSinceLastKill + 300)
                        {
                            e.IsAlive = false;
                            player.Points++;
                            enemies.Remove(e);
                            timeSinceLastKill = gameTime.TotalGameTime.TotalMilliseconds;
                        }
                    }
                    if (bas.CheckCollision(e))
                    {
                        player.IsAlive = false;
                    }
                }
            }
            if (enemies.Count < 8)
            {
                rnd = random.Next(1, 3);

                switch (rnd)
                {
                case 1:
                    int rndX              = random.Next(100, window.ClientBounds.Width - enemyOne.Width - 100);
                    int tempY             = 100;
                    NormalZombieBear temp = new NormalZombieBear(enemyOne, rndX, tempY, 1f, 0, 0);
                    enemies.Add(temp);
                    break;

                case 2:
                    int     rndSpeedX = random.Next(1, 3);
                    int     rndX2     = random.Next(140, window.ClientBounds.Width - enemyTwo.Width - 140);
                    int     tempY2    = 50;
                    Enemy_2 temp2     = new Enemy_2(enemyTwo, rndX2, tempY2, 1f, 0, 0);
                    enemies.Add(temp2);
                    break;
                }
            }
            if (!player.IsAlive)
            {
                Reset(window, content);
                return(State.Menu);
            }
            return(State.Level);
        }