Example #1
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();

            #region Basic Game Logic

            if (monster.Health > 0 && player.Hero.Health > 0)
            {
                gameSeconds = (ulong)gameTime.TotalGameTime.TotalSeconds;
                if (gameSeconds > prevGameSeconds)
                {
                    hero.Health -= monster.Attack;

                    Debug.WriteLine("Hero health: {0} -- gameSeconds: {1} ---- prevGameSeconds: {2} --- real seconds: {3}", player.Hero.Health, gameSeconds, prevGameSeconds, gameTime.TotalGameTime.TotalSeconds);
                    prevGameSeconds = gameSeconds;
                }

                // (NOTE): click implemented
                mouseNewState = Mouse.GetState();
                if (mouseNewState.LeftButton == ButtonState.Pressed && mouseOldState.LeftButton == ButtonState.Released)
                {
                    monster.Health -= hero.Attack;
                }
                mouseOldState = mouseNewState;
            }

            #endregion

            #region Reset Logic

            if (monster.Health <= 0)
            {
                player.Score++;
                match.Level++;

                // (NOTE): re-initialize monster
                // (NOTE): Monster
                monsterPos = new Vector2(150f, 100f);
                monster = new MonsterModel
                {
                    Attack = 1 + match.Level,
                    Health = 10 * match.Level,
                    MonsterId = 2,
                    ImageData = "monster",
                    Name = "Genericus " + match.Level
                };

                monsterRect = new Rectangle(10, 100, 100, 100);
                monsterScale = new Vector2(0.3f);

                // (NOTE): re-initialize hero
                // (NOTE): Hero
                hero.Attack = 1 + match.Level;
                hero.Health = 10 * match.Level;
            }

            if (player.Hero.Health <= 0)
            {
                if (player.Score > 0)
                    player.Score--;

                // (NOTE): re-initialize hero
                // (NOTE): Hero
                hero.Attack = 1 + match.Level;
                hero.Health = 10 * match.Level;
            }

            #endregion

            base.Update(gameTime);
        }
Example #2
0
 /// <summary>
 /// Returns a Monster based on specified monsterModel.
 /// </summary>
 /// <param name="monsterModel"></param>
 /// <returns></returns>
 public Monster Create(MonsterModel monsterModel)
 {
     return new Monster
     {
         Name = monsterModel.Name,
         Attack = monsterModel.Attack,
         Health = monsterModel.Health,
         Id = monsterModel.MonsterId,
         ImageData = monsterModel.ImageData
     };
 }
Example #3
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()
        {
            IsMouseVisible = true;
            mouse = Mouse.GetState();

            // (NOTE): Hero
            heroPos = new Vector2(100f, 100f);
            hero = new HeroModel
            {
                Attack = 1,
                Health = 20,
                HeroId = 1,
                ImageData = "healer",
                Magic = 10,
                Name = "Healer"
            };

            heroRect = new Rectangle(10, 100, 64, 64);
            heroScale = new Vector2(0.1f);

            // (NOTE): Monster
            monsterPos = new Vector2(150f, 100f);
            monster = new MonsterModel
            {
                Attack = 1,
                Health = 20,
                MonsterId = 1,
                ImageData = "monster",
                Name = "Genericus"
            };

            monsterRect = new Rectangle(10, 100, 100, 100);
            monsterScale = new Vector2(0.3f);

            // (NOTE): Player
            playerList = new List<PlayerModel>();
            player = new PlayerModel
            {
                Hero = hero,
                Name = "Zeqzor",
                PlayerId = 1,
                Score = 0
            };
            playerList.Add(player);

            // (NOTE): Match
            match = new MatchModel
            {
                Level = 1,
                MatchId = 1,
                Monster = monster,
                Players = playerList,
            };

            base.Initialize();
        }