Пример #1
0
        public void moveTowardsPlayer(Player thePlayer, Vector2 Viewport)
        {
            Vector2 preModifiedPlayerLoc = thePlayer.getCurrentPos();
            Vector2 playerLoc            = new Vector2(preModifiedPlayerLoc.X + Viewport.X, preModifiedPlayerLoc.Y + Viewport.Y);


            if (playerLoc.X < zombieLoc.X)
            {
                zombieLoc.X -= moveSpeed;
            }
            else if (playerLoc.X > zombieLoc.X)
            {
                zombieLoc.X += moveSpeed;
            }

            if (playerLoc.Y < zombieLoc.Y)
            {
                zombieLoc.Y -= moveSpeed;
            }
            else if (playerLoc.Y > zombieLoc.Y)
            {
                zombieLoc.Y += moveSpeed;
            }

            //zombies get excited by food and groan.
            if ((playerLoc.X >= zombieLoc.X - 100) && (playerLoc.X <= zombieLoc.X + 100) &&
                (playerLoc.Y >= zombieLoc.Y - 100) && (playerLoc.Y <= zombieLoc.Y + 100))
            {
                if (thePlayer.getIsDead())
                {
                    groanInstance.Stop();
                }
                else if (groanInstance.State == SoundState.Stopped)
                {
                    groanInstance.Volume = 0.50f;
                    //groanInstance.IsLooped = false;
                    groanInstance.Play();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();

            if (currentPlayer.getIsDead())
            {
                string  gameOver = "A Zombie got your brains -  Game Over! ";
                Vector2 position = new Vector2((graphics.PreferredBackBufferWidth / 2) - (font.MeasureString(gameOver).X / 2), graphics.PreferredBackBufferHeight / 2);
                spriteBatch.DrawString(font, gameOver, position, Color.Red);
            }
            else
            {
                currentMap.drawMap(spriteBatch);

                currentPlayer.drawPlayer(spriteBatch);

                foreach (Zombie zed in zombies)
                {
                    zed.drawZombie(spriteBatch, currentMap.getViewport());
                }

                if (attacking)
                {
                    //spriteBatch.Draw(attackingWeaponTexture, attackingWeaponPosition, Color.White);
                    spriteBatch.Draw(attackingWeaponTexture, attackingWeaponPosition, null, Color.White, RotationAngle,
                                     attackingWeaponOrigin, 1.0f, SpriteEffects.None, 0f);
                }

                if (constructionMenuOpen)
                {
                    conMenu.draw(spriteBatch);
                }
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
Пример #3
0
        public void moveTowardsPlayer(Player thePlayer, Vector2 Viewport)
        {
            Vector2 preModifiedPlayerLoc = thePlayer.getCurrentPos();
            Vector2 playerLoc = new Vector2(preModifiedPlayerLoc.X + Viewport.X, preModifiedPlayerLoc.Y + Viewport.Y);

            if (playerLoc.X < zombieLoc.X)
            {
                zombieLoc.X -= moveSpeed;
            }
            else if (playerLoc.X > zombieLoc.X)
            {
                zombieLoc.X += moveSpeed;
            }

            if (playerLoc.Y < zombieLoc.Y)
            {
                zombieLoc.Y -= moveSpeed;
            }
            else if (playerLoc.Y > zombieLoc.Y)
            {
                zombieLoc.Y += moveSpeed;
            }

            //zombies get excited by food and groan.
            if ((playerLoc.X >= zombieLoc.X - 100) && (playerLoc.X <= zombieLoc.X + 100) &&
                (playerLoc.Y >= zombieLoc.Y - 100) && (playerLoc.Y <= zombieLoc.Y + 100))
            {
                if (thePlayer.getIsDead())
                {
                    groanInstance.Stop();
                }
                else if (groanInstance.State == SoundState.Stopped)
                {
                    groanInstance.Volume = 0.50f;
                    //groanInstance.IsLooped = false;
                    groanInstance.Play();
                }
            }
        }