This is the preliminary level class. The level class handles rendering the map and handling all entities that happen to populate said map. These entities will be used to build the world and create event triggering, enemies, NPCs, etc. This should be where the majority of the game logic goes, via the interaction between entities. Level content will be loaded dynamically through some sort of WAD-type file.
Example #1
0
        /// <summary>
        /// The method to update all of the HUDItems' information.
        /// </summary>
        /// <param name="gameTime">The object that holds all the time information.</param>
        public void Update(GameTime gameTime, Pantheon gameReference, Level level)
        {
            Shield shield;

            PlayerCharacter player = (PlayerCharacter)(level.Entities["character"]);
            // Set the width of the Armor Bar with respect to the current percent of the player's armor.
            try
            {
                hudItems[0].Coordinates = new Rectangle(hudItems[0].Coordinates.X, hudItems[0].Coordinates.Y,
                    (int)(hudItems[0].DefaultWidth * ((float)player.CurrentArmor / player.TotalArmor)), hudItems[0].Coordinates.Height);

                // Get the Shield item
                if (!PlayerCharacter.inventory.equipped.ElementAt(6).isNull)
                {
                    shield = (Shield)PlayerCharacter.inventory.equipped.ElementAt(6);
                }
                else
                {
                    shield = new Shield();
                }

                // Update the Shield indicator
                int shieldPercent = (int)(100 * (float)shield.CurrentShield / shield.TotalShield);
                hudItems[1].SetOpacity((int)((shieldPercent - 55) * 5.66)); // (% - min) * (255 / (max - min))

                if (shieldPercent > 55 && !shield.isNull)
                {
                    hudItems[2].SetOpacity((int)(255 - (shieldPercent - 55) * 5.66));
                }
                else if (!shield.isNull)
                {
                    hudItems[2].SetOpacity((int)((shieldPercent - 10) * 5.66));
                }
                else
                {
                    hudItems[2].SetOpacity(0);
                }

                if (shieldPercent > 10 && !shield.isNull)
                {
                    hudItems[3].SetOpacity((int)(255 - (shieldPercent - 10) * 5.66));
                }
                else
                {
                    hudItems[3].SetOpacity(0);
                }

                if (shieldPercent <= 10 && shieldPercent > 0 && !shield.isNull)
                {
                    Boolean playSound = false;
                    if(shieldPercent == 10)
                    {
                        playSound = true;
                    }
                    hudItems[4].SetOpacity(danger);
                    danger = (danger + (30 - (shieldPercent * 2))) % 256;
                    // only make the noise once..otherwise it does it whenever it's less than 10%
                    if (playSound)
                    {
                        gameReference.audioManager.playSoundEffect("warning");
                        playSound = false;
                    }
                }
                else
                {
                    hudItems[4].SetOpacity(0);
                    danger = 0;
                }

                if (shieldPercent == 0 || shield.isNull)
                {
                    hudItems[5].SetOpacity(255);
                }
                else
                {
                    hudItems[5].SetOpacity(0);
                }

                // Update the Ammo Display
                if (player.ArmedItem.isNull)
                {
                    hudItems[6].Text = "0/0";
                }
                else
                {
                    hudItems[6].Text = (((Weapon)player.ArmedItem).CurrentAmmo.ToString()) +
                        "/" + (((Weapon)player.ArmedItem).TotalAmmo.ToString());

                    // Update the Reload Timer Bar
                    hudItems[7].Coordinates = new Rectangle(hudItems[7].Coordinates.X, hudItems[7].Coordinates.Y,
                        (int)(hudItems[7].DefaultWidth * (((Weapon)player.ArmedItem)).PercentToEndReload()), hudItems[7].Coordinates.Height);
                }
                hudItems[8].Image = player.ArmedItem.HUDRepresentation;
                if (!player.ArmedItem.isNull)
                {
                    hudItems[8].Coordinates = new Rectangle((int)HUDcoords.X, (int)HUDcoords.Y - (int)((SCREEN_WIDTH * .09) * ((Weapon)player.ArmedItem).Offset), (int)(SCREEN_WIDTH * .10), (int)(SCREEN_WIDTH * .10));
                }
                //debugString = (((Weapon)player.ArmedItem).ReloadDelay.Seconds * 1000 + ((Weapon)player.ArmedItem).ReloadDelay.Milliseconds).ToString();

            }
            catch (DivideByZeroException)
            {
                Console.Write("Total armor or shield is zero!");
            }
        }
Example #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)
        {
            CutsceneManager.Update(gameTime, this);

            ControlManager.Update();

            // REMOVE LATER
            if (Keyboard.GetState().IsKeyDown(Keys.Back)) { this.Exit(); }

            if (ControlManager.actions.Pause)
            {
                this.IsMouseVisible = true;
                menu.Update(gameTime, this);
            }
            else
            {
                menu.MenuState = "main";

                this.IsMouseVisible = false;

                if (currentLevel.LevelPlaying)
                {
                    if (!CutsceneManager.CutscenePlaying)
                    {
                        currentLevel.Update(gameTime, this);
                    }
                }
                else
                {
                    string nextLevel = currentLevel.NextLevel;
                    string prevLevel = currentLevel.LevelNum;
                    currentLevel = new Level(GraphicsDevice);
                    currentLevel.Load(nextLevel, prevLevel, this);
                }

                hud.Update(gameTime, this, this.currentLevel);
            }

            base.Update(gameTime);
        }
Example #3
0
        /// <summary>
        /// The method to update all of the HUDItems' information.
        /// </summary>
        /// <param name="gameTime">The object that holds all the time information.</param>
        public void Update(GameTime gameTime, Pantheon gameReference, Level level)
        {
            PlayerCharacter player = (PlayerCharacter)(level.Entities["character"]);
            // Set the width of the Armor Bar with respect to the current percent of the player's armor.
            try
            {
                hudItems[0].Coordinates = new Rectangle(hudItems[0].Coordinates.X, hudItems[0].Coordinates.Y,
                    (int)(hudItems[0].DefaultWidth * ((float)player.CurrentArmor / player.TotalArmor)), hudItems[0].Coordinates.Height);

                // Get the Shield item
                Shield shield = (Shield)player.EquippedItems["shield"];

                // Update the Shield indicator
                int shieldPercent = (int)(100 * (float)shield.CurrentShield / shield.TotalShield);
                hudItems[1].SetOpacity((int)((shieldPercent - 55) * 5.66)); // (% - min) * (255 / (max - min))

                if (shieldPercent > 55)
                {
                    hudItems[2].SetOpacity((int)(255 - (shieldPercent - 55) * 5.66));
                }
                else
                {
                    hudItems[2].SetOpacity((int)((shieldPercent - 10) * 5.66));
                }

                if (shieldPercent > 10)
                {
                    hudItems[3].SetOpacity((int)(255 - (shieldPercent - 10) * 5.66));
                }
                else
                {
                    hudItems[3].SetOpacity(0);
                }

                if (shieldPercent <= 10 && shieldPercent > 0)
                {
                    hudItems[4].SetOpacity(danger);
                    danger = (danger + (30 - (shieldPercent * 2))) % 256;
                }
                else
                {
                    hudItems[4].SetOpacity(0);
                    danger = 0;
                }

                if (shieldPercent == 0)
                {
                    hudItems[5].SetOpacity(255);
                }
                else
                {
                    hudItems[5].SetOpacity(0);
                }

                // Update the Ammo Display
                if (player.ArmedItem.isNull)
                {
                    hudItems[6].Text = "0/0";
                }
                else
                {
                    hudItems[6].Text = (((Weapon)player.ArmedItem).CurrentAmmo.ToString()) +
                        "/" + (((Weapon)player.ArmedItem).TotalAmmo.ToString());

                    // Update the Reload Timer Bar
                    hudItems[7].Coordinates = new Rectangle(hudItems[7].Coordinates.X, hudItems[7].Coordinates.Y,
                        (int)(hudItems[7].DefaultWidth * (((Weapon)player.ArmedItem)).PercentToEndReload()), hudItems[7].Coordinates.Height);
                }
                hudItems[8].Image = player.ArmedItem.HUDRepresentation;
                hudItems[8].Coordinates = new Rectangle((int)HUDcoords.X, (int)HUDcoords.Y, (int)(SCREEN_WIDTH * .09), (int)(SCREEN_HEIGHT * .05));
                //debugString = (((Weapon)player.ArmedItem).ReloadDelay.Seconds * 1000 + ((Weapon)player.ArmedItem).ReloadDelay.Milliseconds).ToString();

            }
            catch (DivideByZeroException)
            {
                Console.Write("Total armor or shield is zero!");
            }
        }
Example #4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            rand = new Random();
            ControlManager = new ControlManager();

            int SCREEN_WIDTH = GraphicsDevice.Viewport.Width;
            int SCREEN_HEIGHT = GraphicsDevice.Viewport.Height;

            menu = new Menu(SCREEN_WIDTH, SCREEN_HEIGHT);

            player = new PlayerCharacter(this);

            debugFont = Content.Load<SpriteFont>("Fonts/DebugFont");
            splashFont = Content.Load<SpriteFont>("Fonts/SplashFont");

            hud = new HUD(GraphicsDevice, Content, SCREEN_WIDTH, SCREEN_HEIGHT, debugFont);

            currentLevel = new Level(GraphicsDevice);

            CutsceneManager = new CutsceneManager(GraphicsDevice);

            EventManager = new EventManager(this);

            QuestManager = new QuestManager(this);

            audioManager = new AudioManager();

            base.Initialize();
        }