public static void HitCollision(SpriteAnimation first, SpriteAnimation second, GameTime gameTime)
 {
     String method = HitActions[(int)first.Information.CurrentState, (int)second.Information.CurrentState];
     if (method != null)
     {
         if (second.Information.Position - second.Information.Range - first.Information.Position < 15)
         {
             first.GetType().GetMethod(method).Invoke(first, new object[] {gameTime});
             if (method != "AnimateHitBlock" && method != "AnimateHitDownBlock")
                 if (!first.Information.IsHited)
                 {
                     first.Information.Health -= second.Information.Damage;
                     first.Information.IsHited = true;
                 }
         }
     }
     else
         first.Information.IsHited = false;
     method = HitActions[(int) second.Information.CurrentState, (int) first.Information.CurrentState];
     if (method != null)
     {
         if (second.Information.Position - first.Information.Position - first.Information.Range < 15)
         {
             second.GetType().GetMethod(method).Invoke(second, new object[] {gameTime});
             if (method != "AnimateHitBlock" && method != "AnimateHitDownBlock")
                 if (!second.Information.IsHited)
                 {
                     second.Information.Health -= first.Information.Damage;
                     second.Information.IsHited = true;
                 }
         }
     }
     else
         second.Information.IsHited = false;
 }
        public static void RepairMoveCollision(SpriteAnimation first, SpriteAnimation second, int width)
        {
            if (first.Information.CurrentState == PlayerState.Move)
            {
                if (first.moveDelta < 0)
                {
                    if (first.Information.Position > 100)
                        first.Position = new Vector2(first.Position.X + first.moveDelta, first.Position.Y);
                }
                else
                {
                    if (second.Information.Position - first.Information.Position - first.moveDelta > 0)
                        first.Position = new Vector2(first.Position.X + first.moveDelta, first.Position.Y);
                }
            }
            if (second.Information.CurrentState == PlayerState.Move)
            {
                if (second.moveDelta > 0)
                {
                    if (second.Information.Position < width - 20)
                        second.Position = new Vector2(second.Position.X + second.moveDelta, second.Position.Y);
                }
                else
                {
                        if (second.Information.Position - first.Information.Position + second.moveDelta > 0)
                    second.Position = new Vector2(second.Position.X + second.moveDelta, second.Position.Y);                    
                }
            }

        }
 public static void DetectWinner(GameTime gameTime, SpriteAnimation first, SpriteAnimation second)
 {
     SpriteAnimation winner = null;
     bool hasWinner = false;
     if (first.Information.Health == 0)
     {
         winner = second;
         hasWinner = true;
         GameState.SecondWin();
     }
     if (second.Information.Health == 0)
     {
         winner = first;
         hasWinner = true;
         GameState.FirstWin();
     }
     if (hasWinner)
     {
         if (!GameState.NextRound(first, second))
         {
             GameState.IsEnd = true;
             winner.Win(gameTime);
         }
     }
 }
 private static void Routine(SpriteAnimation firstSprite, SpriteAnimation secondSprite)
 {
     firstSprite.Information.Health = GameSettings.MaxHealth;
     firstSprite.Position = new Vector2(GameSettings.FirstPosition.X - 100, GameSettings.FirstPosition.Y);
     firstSprite.Routine();
     secondSprite.Information.Health = GameSettings.MaxHealth;
     secondSprite.Position = new Vector2(GameSettings.FirstPosition.X + 100, GameSettings.FirstPosition.Y);
     secondSprite.Routine();
 }
 public static bool NextRound(SpriteAnimation firstSprite, SpriteAnimation secondSprite)
 {
     if (firstWin == 2 || secondWin == 2)
     {
         CurrentRound = 1;
         Routine(firstSprite, secondSprite);
         ShowWinner = false;
         return false;
     }
     CurrentRound += 1;
     Routine(firstSprite, secondSprite);
     ShowWinner = true;
     return true;
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            var scorpionDictionary = DictionaryLoader.GetDictionary(GameSettings.firstName, Content);
            var subZeroDictionary = DictionaryLoader.GetDictionary(GameSettings.secondName, Content);
            var firstHealth = new HealthBar(GameSettings.HealthBar, Content.Load<Texture2D>("DamageBar"));
            var secondHealth = new HealthBar(new Vector2(width - GameSettings.HealthBar.X, GameSettings.HealthBar.Y), Content.Load<Texture2D>("DamageBar"));
            var firstMoves = new PlayerControls();
            firstMoves.GetFirstPlayerKeyboard();
            var secondMoves = new PlayerControls();
            secondMoves.GetSecondPlayerKeyboard();
            
            //first player
            var firstSprite = new SpriteAnimation(GameSettings.SpriteWidth, GameSettings.SpriteHeigth, false)
            {
                SpriteTexture = scorpionDictionary,
                Moves = firstMoves,
                Position = new Vector2(GameSettings.FirstPosition.X - 100, GameSettings.FirstPosition.Y)
            };

            //second player
            var secondSprite = new SpriteAnimation(GameSettings.SpriteWidth, GameSettings.SpriteHeigth, true)
            {
                SpriteTexture = subZeroDictionary,
                Moves = secondMoves,
                Position = new Vector2(GameSettings.FirstPosition.X + 100, GameSettings.FirstPosition.Y)
            };

            //game screen
            var arenaRect = new Rectangle(0, 0, graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width, graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height);
            var arenaTexture = Content.Load<Texture2D>("Arenas//TheDeadPoolArena");
            gameScreen = new GameScreen(this, Content.Load<SpriteFont>("Pristina"), Content.Load<SpriteFont>("Courier New"), width, arenaTexture, arenaRect)
            {
                FirstSprite = firstSprite,
                FirstHealthBar = firstHealth,

                SecondSprite = secondSprite,
                SecondHealthBar = secondHealth,
            };

            //menu screen
            var font = Content.Load<SpriteFont>("Narkisim");
            var gameNameItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width/2, 100),
                MenuItemName = "Mortal Kombat",
                MenuItemOrigin = font.MeasureString("Mortal Kombat")/2
            };
            font = Content.Load<SpriteFont>("Viner Hand ITC");
            var startItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 300),
                MenuItemName = "New game",
                MenuItemOrigin = font.MeasureString("New game") / 2
            };
            var helpItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 400),
                MenuItemName = "Help",
                MenuItemOrigin = font.MeasureString("Help") / 2
            };
            var exitItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 500),
                MenuItemName = "Exit",
                MenuItemOrigin = font.MeasureString("Exit") / 2
            };
            var menuItems = new MenuItem[]
            {
                startItem,
                helpItem,
                exitItem,
                gameNameItem
            };
            var texture = Content.Load<Texture2D>("BackgroundMenu");
            var rect = new Rectangle(0, 0, graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Width,
                graphics.GraphicsDevice.Adapter.CurrentDisplayMode.Height);
            menuScreen = new MenuScreen(this, menuItems, texture, rect);

            //help screen
            helpScreen = new HelpScreen(this, texture, rect, Content.Load<SpriteFont>("Courier new"), Content.Load<SpriteFont>("Viner Hand ITC"), firstMoves, secondMoves);

            //game pause screen
            font = Content.Load<SpriteFont>("Viner Hand ITC");
            var resumeItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 300),
                MenuItemName = "Resume",
                MenuItemOrigin = font.MeasureString("Resume") / 2
            };
            exitItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 400),
                MenuItemName = "Exit",
                MenuItemOrigin = font.MeasureString("Exit") / 2
            };
            menuItems = new MenuItem[]
            {
                resumeItem,
                exitItem
            };
            gamePauseScreen = new GamePauseScreen(this, menuItems);

            //game restart screen
            font = Content.Load<SpriteFont>("Viner Hand ITC");
            var restartItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 300),
                MenuItemName = "New game",
                MenuItemOrigin = font.MeasureString("New game") / 2
            };
            exitItem = new MenuItem
            {
                MenuFont = font,
                MenuItemPosition = new Vector2(width / 2, 400),
                MenuItemName = "Exit",
                MenuItemOrigin = font.MeasureString("Exit") / 2
            };
            menuItems = new MenuItem[]
            {
                restartItem,
                exitItem
            };
            gameRestartScreen = new GameRestartScreen(this, menuItems);

            Components.Add(menuScreen);
            Components.Add(gameScreen);
            Components.Add(helpScreen);
            Components.Add(gamePauseScreen);
            Components.Add(gameRestartScreen);
            menuScreen.Show();
        }
 public static SpriteAnimation GetWinner(SpriteAnimation first, SpriteAnimation second)
 {
     if (firstWin == 2)
         return first;
     return second;
 }