Exemple #1
0
        public static ICharacter MakePlayer(PlayerChars type)
        {
            ICharacter player;

            switch (type)
            {
            case PlayerChars.TheGuy:
                player = new TheGuy();
                break;

            case PlayerChars.Redhead:
                player = new Redhead();
                break;

            case PlayerChars.Blondy:
                player = new Blondy();
                break;

            default:
                throw new CharacterException($"{typeof(PlayerFacory).Name} does not contain such character.");
            }

            player.Died    += (sender, args) => GfxHandler.AddDeathEffect(sender);
            player.Damaged += (sender, args) => GfxHandler.AddBloodEffect(sender);

            return(player);
        }
Exemple #2
0
        public Rectangle InfalateBBox()
        {
            Rectangle originaBBox = GfxHandler.GetBBox(this);

            originaBBox.Inflate(50, 50);
            return(originaBBox);
        }
Exemple #3
0
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;
            stages = GameStages.Game_Stage;
            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            GfxHandler.Load(this.Content);

            GoldCoin coin = new GoldCoin(new Vector2(300, 300), "TestObjects/coin");

            // testEnemyTex = Content.Load<Texture2D>(@"TestObjects/cockSprite");
            Vector2 enemyPos = new Vector2(550, 350);
            Vector2 pos      = new Vector2(
                GlobalVariables.WindowWidth / 2 - 140,
                GlobalVariables.WindowHeight / 2);

            this.sampleEnemy = new Enemy(enemyPos, @"TestObjects/cockSprite", 100, 100, 1, this.testLevel);
            this.testPlayer  = new TestChar(pos, @"Player/p1Rotation", 100, 100, 2, this.testLevel);

            this.testLevel = new Level(@"..\..\..\Content\Maps\testMap2.txt", this.testPlayer);

            this.testLevel.Assets.Add(coin);

            this.sampleEnemy.Level = this.testLevel;
            this.testPlayer.Level  = this.testLevel;
            this.testLevel.Enemies.Add(this.sampleEnemy);

            // TODO: Get Width and Heignt based on the level size?
            this.graphics.PreferredBackBufferWidth  = GlobalVariables.WindowWidth;  // set this value to the desired width of your window
            this.graphics.PreferredBackBufferHeight = GlobalVariables.WindowHeight; // set this value to the desired height of your window
            this.graphics.ApplyChanges();
        }
Exemple #4
0
        protected override void Draw(GameTime gameTime)
        {
            this.GraphicsDevice.Clear(Color.Black);

            // Vector2 origin = new Vector2(GfxHandler.GetWidth(this.testPlayer) / 2, GfxHandler.GetHeight(this.testPlayer) / 2);
            // TODO: Add your drawing code here
            if (this.stage == GameStages.GameStage)
            {
                this.statPanel.Draw(this.player, this.spriteBatch);

                GfxHandler.DrawLevel(this.spriteBatch, this.player.Level);
            }
            else if (this.stage == GameStages.DeathStage)
            {
                //this.statPanel.EndScreen(this.Content, this.spriteBatch);
                this.GraphicsDevice.Clear(Color.AliceBlue);
                this.deathScreen.Draw(this.spriteBatch, this.GraphicsDevice);
            }
            else
            {
                this.GraphicsDevice.Clear(Color.Wheat);
                this.startScreen.Draw(this.spriteBatch, this.GraphicsDevice);
            }

            base.Draw(gameTime);
        }
Exemple #5
0
 public void PopulateInventory(ICharacter character, SpriteBatch spriteBatch)
 {
     IPickable[] inv = (character as Player).Inventory;
     for (int i = 0; i < inv.Length; i++)
     {
         if (inv[i] != null)
         {
             Texture2D uhm = GfxHandler.GetTexture(inv[i] as IGameObject);
             spriteBatch.Draw(uhm, new Vector2(slots[i].Position.X, slots[i].Position.Y), Color.White);
         }
     }
 }
Exemple #6
0
 public override string IsClicked()
 {
     foreach (Button button in Buttons)
     {
         if (button.IsClicked)
         {
             GfxHandler.ClearEffects();
             button.IsClicked = false;
             return("Replay");
         }
     }
     return(null);
 }
Exemple #7
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 (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }
            if (this.stages == GameStages.Game_Stage && this.testLevel.Character.CurrentHealth <= 0)
            {
                stages = GameStages.Death_Stage;
            }
            //if(stages == GameStages.Start_Stage)
            //{
            //    this.staRtScreen.Update(gameTime);
            //}

            if (stages == GameStages.Game_Stage)
            {
                timeSinceLastUpdate += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceLastUpdate >= oneSec)
                {
                    timeSinceLastUpdate = 0;
                    this.testLevel.Character.CooldownTimer += 1;
                }
                this.testPlayer.Move();
                GfxHandler.GetSprite(this.testPlayer).Update(gameTime, this.testPlayer);

                foreach (Character enemy in this.testLevel.Enemies.ToList())
                {
                    enemy.Move();
                    GfxHandler.GetSprite(enemy).Update(gameTime, enemy);
                }

                foreach (Projectile projectile in this.testLevel.Projectiles.ToList())
                {
                    projectile.Move();
                    GfxHandler.GetSprite(projectile).Update(gameTime);
                }
            }
            else
            {
            }

            base.Update(gameTime);
        }
Exemple #8
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)
        {
            this.GraphicsDevice.Clear(Color.Black);

            // Vector2 origin = new Vector2(GfxHandler.GetWidth(this.testPlayer) / 2, GfxHandler.GetHeight(this.testPlayer) / 2);
            // TODO: Add your drawing code here
            if (stages == GameStages.Game_Stage)
            {
                this.spriteBatch.Begin();


                this.testLevel.Assets.ForEach(t => this.spriteBatch.Draw(GfxHandler.GetTexture(t), t.Position));



                this.spriteBatch.End();
                this.statScreen.DrawHealth(this.testLevel.Character, this.Content, this.spriteBatch);
                GfxHandler.GetSprite(this.sampleEnemy).Draw(this.spriteBatch, this.sampleEnemy.Position);
                GfxHandler.GetSprite(this.testPlayer).Draw(this.spriteBatch, this.testPlayer.Position, this.testPlayer.FacingAngle, this.testPlayer.MovementAngle);

                foreach (var projectile in this.testLevel.Projectiles.ToList())
                {
                    GfxHandler.GetSprite(projectile).Draw(this.spriteBatch, projectile.Position, projectile.Angle);

                    if (projectile.Lifetime > projectile.Range)
                    {
                        this.testLevel.Projectiles.Remove(projectile);
                    }
                }
            }
            else if (this.stages == GameStages.Death_Stage)
            {
                this.statScreen.EndScreen(this.Content, this.spriteBatch);
            }
            else
            {
                this.staRtScreen.DrawStartScreen(this.spriteBatch, this.Content);
            }


            base.Draw(gameTime);
        }
Exemple #9
0
        public static IEnumerable <ICharacter> MakeRandomEnemies(IList <SpawnLocation> locations)
        {
            IList <ICharacter> enemies = new List <ICharacter>();

            for (int i = 0; i < locations.Count; i++)
            {
                Rectangle hugeBox = locations[i].InfalateBBox();

                var        randomPosition = new Vector2(Rng.Next(hugeBox.Left + 10, hugeBox.Right - 10), Rng.Next(hugeBox.Top + 10, hugeBox.Bottom - 10));
                ICharacter enemy;

                switch (Rng.Next(0, 3))
                {
                case 0:
                    enemy = new Zombie(randomPosition, locations[i]);
                    break;

                case 1:
                    enemy = new Crawler(randomPosition, locations[i]);
                    break;

                case 2:
                    // Skip some locations for a bit randomness.
                    continue;

                default:
                    enemy = new Chicken(randomPosition, locations[i]);
                    break;
                }

                enemy.Died    += (sender, args) => GfxHandler.AddDeathEffect(sender);
                enemy.Died    += (sender, args) => ItemFactory.SpawnPotionByChance(sender);
                enemy.Damaged += (sender, args) => GfxHandler.AddBloodEffect(sender);

                enemies.Add(enemy);
            }

            return(enemies);
        }
Exemple #10
0
        protected override void LoadContent()
        {
            this.IsMouseVisible = true;

            this.graphics.PreferredBackBufferWidth  = GlobalVariables.WindowWidthDefault;  // set this value to the desired width of your window
            this.graphics.PreferredBackBufferHeight = GlobalVariables.WindowHeightDefault; // set this value to the desired height of your window
            this.graphics.ApplyChanges();

            this.statPanel   = new StatPanel();
            this.startScreen = new StartScreen();
            this.deathScreen = new DeathScreen();

            this.stage = GameStages.Start_Stage;

            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            GfxHandler.Load(this.Content);

            this.startScreen.Load(this.Content);
            this.deathScreen.Load(this.Content);
            this.statPanel.Load(this.Content);
        }
Exemple #11
0
        protected override void Update(GameTime gameTime)
        {
            GlobalVariables.GlobalTimer += gameTime.ElapsedGameTime.Milliseconds;

            MouseState mouse = Mouse.GetState();

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (this.stage == GameStages.Start_Stage)
            {
                string characterClass = this.startScreen.IsClicked();

                if (characterClass != null)
                {
                    if (characterClass == "Redhead")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.Redhead);
                    }
                    else if (characterClass == "Guy")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.TheGuy);
                    }
                    else if (characterClass == "Blondie")
                    {
                        this.player = PlayerFacory.MakePlayer(PlayerChars.Blondy);
                    }

                    this.startScreen.UnloadButtons();
                    this.stage = GameStages.GameStage;

                    this.player.Level = LevelFactory.MakeLevel(this.player, Maps.HouseMap);
                }

                this.startScreen.Update(mouse);
            }

            if (this.stage == GameStages.DeathStage)
            {
                this.player.Level = null;
                string death = this.deathScreen.IsClicked();
                if (death != null)
                {
                    this.startScreen.UnloadButtons();
                    this.stage = GameStages.Start_Stage;
                }

                this.deathScreen.Update(mouse);
            }

            if (this.stage == GameStages.GameStage)
            {
                GfxHandler.UpdateLevel(gameTime, this.player.Level);

                if (this.player.CurrentHealth <= 0)
                {
                    this.stage        = GameStages.DeathStage;
                    this.player.Level = null;
                }
            }

            base.Update(gameTime);
        }