ImageController Controls one image but can have many positions And different animations on differente positions
Inheritance: Controller
Example #1
0
 private void BgImageAnimationDone(ImageController target, ImageModel imagePosition)
 {
     if (imagePosition.CurrentPos.Y <= -10)
     {
         target.IsVisible = false;
     }
 }
        public override void Load(ContentManager content)
        {
            Vector2 percentPos = new Vector2(330 * characterModel.playerIndex + 30, Constants.WindowHeight - 120);

            thumb = new ImageView(content.Load <Texture2D>(GamePadControllers[characterModel.playerIndex].PlayerModel.SelectedCharacter.thumbnail),
                                  percentPos, 159, true);
            thumb.Scale = 0.6f;
            AddView(thumb);


            percentBox = new TextBox("0%", GetFont("Impact.large"), percentPos + new Vector2(180, 40), Color.White, 1f);
            percentBox.StaticPosition = true;
            percentBox.Layer          = 150;
            percentBox.Origin         = new Vector2(20, 0);
            AddView(percentBox);

            percentBg = new ImageView(content.Load <Texture2D>("GameStuff/PlayerPercentBg"), percentPos + new Vector2(0, 94), 149, true);
            AddView(percentBg);

            if (gameOptions.UseLifes)
            {
                lifes = new ImageController(Screen, "GameStuff/Life", 160, true);
                AddController(lifes);
                for (int i = 0; i < gameOptions.Lifes; i++)
                {
                    lifes.AddPosition(percentPos + new Vector2(i * 16 + 130, 100), 400);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Show the character at bottom of screen when cursor hovers a characterThumb
        /// </summary>
        private void hoverCharacter(int playerIndex, int characterIndex)
        {
            //Get the character model
            CharacterStats chModel = characterModels[characterIndex];

            //Get character pose by using index
            ImageController img = characterImages[characterIndex];

            //Checks if player already has an entry for hovered character
            //Removes the hovered character
            if (characterHover.ContainsKey(playerIndex))
            {
                img.RemovePosition(characterHover[playerIndex]);
            }
            //If not hovered character add playerIndex to dictionary
            else
            {
                characterHover.Add(playerIndex, null);
            }

            ImageModel model = img.AddPosition(playerIndex * 260, 720, playerIndex);

            model.Id = characterIndex;
            img.AnimatePos(model, playerIndex * 260, 450, 300);
            characterHover[playerIndex] = model;

            //characterThumbs[index].Scale = 1.05f;
            characterThumbs[characterIndex].AnimateScale(1.1f, 500);
            characterThumbs[characterIndex].GetAt(0).CurrentRotation = 0.05f;

            img.IsVisible = true;
        }
Example #4
0
        private void OnAnimationDone(ImageController img, ImageModel pos)
        {
            switch (State)
            {
            case PopupState.Colapsed:
                break;

            case PopupState.GamePause:
                ShowGamePauseMenu();
                break;

            case PopupState.Removed:
                break;

            case PopupState.Options:
                ShowOptionsMenu();
                break;

            case PopupState.Help:
                ShowHelpMenu();
                break;

            default:
                break;
            }
        }
Example #5
0
        public override void Load(ContentManager content)
        {
            //Initialises the view for the menu entries
            menuView                  = new MenuView(FontDefualt);
            menuView.Layer            = 1001;
            menuView.StartingPosition = new Vector2(175, 0);
            menuView.StaticPosition   = true;

            //Loads the menu background
            bg = new ImageController(Screen, "Menu/PopupMenu", 1000, true);
            bg.SetPosition(175, -700);
            //content, "Menu/PopupMenu", 175, -700);
            bg.OnAnimationDone += OnAnimationDone;
            AddController(bg);

            //Create the menu models
            createGamePauseMenu(FontDefualt);
            createOptionsMenu(FontDefualt);
            createHelpMenu(FontDefualt);

            //Adds listeners to cursors
            Screen.cursorsController.OnCursorClick      += OnCursorClick;
            Screen.cursorsController.OnCursorCollision  += OnCursorCollision;
            Screen.cursorsController.OnCursorSeparation += OnCursorSeparation;

            SubscribeToGameState = true;
        }
Example #6
0
 public MoveController(ScreenManager screen, CharacterStats characterStats, int index)
     : base(screen)
 {
     Img = new ImageController(Screen, characterStats.moveAnimations, 120, false);
     Img.FramesPerRow = 6;
     Img.SetFrameRectangle(100, 100);
     Img.OriginDefault = new Vector2(50, 50);
     moves = new List<MoveModel>();
     explotions = new List<Explotion>();
     playerIndex = index;
 }
Example #7
0
 public MoveController(ScreenManager screen, CharacterStats characterStats, int index)
     : base(screen)
 {
     Img = new ImageController(Screen, characterStats.moveAnimations, 120, false);
     Img.FramesPerRow = 6;
     Img.SetFrameRectangle(100, 100);
     Img.OriginDefault = new Vector2(50, 50);
     moves             = new List <MoveModel>();
     explotions        = new List <Explotion>();
     playerIndex       = index;
 }
Example #8
0
        public override void Load(ContentManager content)
        {
            bg = new ImageController(Screen, Model.bgImage, Vector2.Zero, 1, true);
            AddController(bg);

            map = new ImageController(Screen, Model.mapImage, Vector2.Zero, 3, false);
            AddController(map);
            SetUpMap();

            SubscribeToGameState = true;
        }
Example #9
0
        public override void Load(ContentManager content)
        {
            bg = new ImageController(Screen, Model.bgImage, Vector2.Zero, 1, true);
            AddController(bg);

            map = new ImageController(Screen, Model.mapImage, Vector2.Zero, 3, false);
            AddController(map);
            SetUpMap();

            SubscribeToGameState = true;
        }
Example #10
0
        public override void Load(ContentManager content)
        {
            powerUps   = Serializing.LoadPowerUps();
            powerUpImg = new ImageController(Screen, "GameStuff/PowerUps", 120, false);
            powerUpImg.FrameRectangle = new Rectangle(0, 0, 50, 50);
            powerUpImg.OriginDefault  = new Vector2(25, 25);
            //powerUpImg.FramesPerRow = 5;
            powerUpImg.ScaleDefault = 0;
            AddController(powerUpImg);

            generateTimeToNext();
        }
Example #11
0
        public override void Load(ContentManager content)
        {
            powerUps = Serializing.LoadPowerUps();
            powerUpImg = new ImageController(Screen, "GameStuff/PowerUps", 120, false);
            powerUpImg.FrameRectangle = new Rectangle(0, 0, 50, 50);
            powerUpImg.OriginDefault = new Vector2(25, 25);
            //powerUpImg.FramesPerRow = 5;
            powerUpImg.ScaleDefault = 0;
            AddController(powerUpImg);

            generateTimeToNext();
        }
Example #12
0
        public override void Load(ContentManager content)
        {
            Screen.soundController.LoadGameSounds(content, this, map.CurrentMap.backgroundMusic);

            this.camera = new CameraController(Screen, map.Model.zoomBox);

            //The effects image for hits
            this.effectImg = new ImageController(Screen, "GameStuff/GameEffects", 110);
            this.effectImg.OriginDefault    = new Vector2(130 / 2, 130 / 2);
            this.effectImg.ScaleDefault     = 0.1f;
            this.effectImg.OnAnimationDone += OnHitAnimationDone;
            this.effectImg.SetFrameRectangle(200, 200);
            this.effectImg.FramesPerRow = 2;
            AddController(effectImg);

            //Creates the countdown before starting game
            countDown = new ImageController(Screen, "GameStuff/CountDown", 900, true);
            countDown.OriginDefault = new Vector2(150, 150);
            countDown.ScaleDefault  = 0;
            countDown.SetFrameRectangle(300, 300);
            countDown.FramesPerRow = 2;
            var imgModel = countDown.SetPosition(Constants.WindowWidth / 2, Constants.WindowHeight / 2);

            //Set callback to determin when the game is finished
            imgModel.Callback = countDownNext;
            countDown.AnimateScale(0.7f, (countDownTime / 4) * 1000, true);
            AddController(countDown);

            gameOver = new ImageController(Screen, "GameStuff/GameOver", 150, true);
            gameOver.OriginDefault = new Vector2(300, 100);
            gameOver.ScaleDefault  = 0;

            this.powerUps = new PowerUpController(Screen, map.Model.DropZone);
            AddController(powerUps);

            //Creates characterController, and PlayerStatsController
            createCharacters(content);

            if (!Screen.GameOptions.UseLifes)
            {
                timeLeft             = new TimeSpan(0, Screen.GameOptions.Minutes, 0);
                timer                = new TextBox(getTimeLeft(), FontDefualt, new Vector2(Constants.WindowWidth - 80, 10), Color.White);
                timer.Layer          = 150;
                timer.StaticPosition = true;
                AddView(timer);
            }

            AddController(camera);
            AddController(this.map);

            SubscribeToGameState = true;
        }
Example #13
0
        public override void Load(ContentManager content)
        {
            Screen.soundController.LoadGameSounds(content, this, map.CurrentMap.backgroundMusic);

            this.camera = new CameraController(Screen, map.Model.zoomBox);

            //The effects image for hits
            this.effectImg = new ImageController(Screen, "GameStuff/GameEffects", 110);
            this.effectImg.OriginDefault = new Vector2(130 / 2, 130 / 2);
            this.effectImg.ScaleDefault = 0.1f;
            this.effectImg.OnAnimationDone += OnHitAnimationDone;
            this.effectImg.SetFrameRectangle(200, 200);
            this.effectImg.FramesPerRow = 2;
            AddController(effectImg);

            //Creates the countdown before starting game
            countDown = new ImageController(Screen, "GameStuff/CountDown", 900, true);
            countDown.OriginDefault = new Vector2(150, 150);
            countDown.ScaleDefault = 0;
            countDown.SetFrameRectangle(300, 300);
            countDown.FramesPerRow = 2;
            var imgModel = countDown.SetPosition(Constants.WindowWidth / 2, Constants.WindowHeight / 2);
            //Set callback to determin when the game is finished
            imgModel.Callback = countDownNext;
            countDown.AnimateScale(0.7f, (countDownTime/4) * 1000, true);
            AddController(countDown);

            gameOver = new ImageController(Screen, "GameStuff/GameOver", 150, true);
            gameOver.OriginDefault = new Vector2(300, 100);
            gameOver.ScaleDefault = 0;

            this.powerUps = new PowerUpController(Screen, map.Model.DropZone);
            AddController(powerUps);

            //Creates characterController, and PlayerStatsController
            createCharacters(content);

            if (!Screen.GameOptions.UseLifes)
            {
                timeLeft = new TimeSpan(0, Screen.GameOptions.Minutes, 0);
                timer = new TextBox(getTimeLeft(), FontDefualt, new Vector2(Constants.WindowWidth - 80, 10), Color.White);
                timer.Layer = 150;
                timer.StaticPosition = true;
                AddView(timer);
            }

            AddController(camera);
            AddController(this.map);

            SubscribeToGameState = true;
        }
Example #14
0
        private void LoadCharacters(ContentManager content)
        {
            //Loads the characters from the xml files
            characterModels = Serializing.LoadCharacters();

            characterThumbs = new List <ImageController>();
            characterImages = new List <ImageController>();

            int i = 0;
            int row = 0, col = 0;

            //Create textures for thumb and image for every character model
            foreach (CharacterStats character in characterModels)
            {
                ImageController thumb = new ImageController(Screen, character.thumbnail, 3, true);
                thumb.OriginDefault = new Vector2(Constants.ThumbWith - 10, Constants.ThumbHeight - 10) / 2;
                thumb.IsVisible     = false;
                thumb.ScaleDefault  = 0.1f;

                ImageModel thumbModel = thumb.SetPosition(col * Constants.ThumbWith + 200, row * Constants.ThumbHeight + 210);
                thumbModel.SetBoundBox(World, Constants.ThumbWith - 20, Constants.ThumbHeight - 20, new Vector2(10, 0),
                                       Category.Cat5, Category.Cat4, true);
                thumbModel.BoundBox.IsSensor = true;
                thumbModel.BoundBox.Enabled  = false;
                thumbModel.BoundBox.UserData = i;

                AddController(thumb);
                characterThumbs.Add(thumb);

                //Check if new row
                if (i == 4)
                {
                    row++;
                    col = 0;
                }
                else
                {
                    col++;
                }
                i++;

                //Creates the images for every texture
                var img = new ImageController(Screen, character.image, 4, true);
                AddController(img);
                characterImages.Add(img);
            }
        }
Example #15
0
        public override void Load(ContentManager content)
        {
            Screen.cursorsController.OnCursorClick      += OnCursorClick;
            Screen.cursorsController.OnCursorCollision  += OnCursorCollision;
            Screen.cursorsController.OnCursorSeparation += OnCursorSeparation;

            //Loads the background for selectionmenuy and startscreen
            startScreen = new ImageController(Screen, "Menu/StartScreen", 1, true);
            startScreen.OnAnimationDone += BgImageAnimationDone;
            startScreen.IsVisible        = true;
            AddController(startScreen);

            selectionScreen                  = new ImageController(Screen, "Menu/SelectionScreen", 1, true);
            selectionScreen.IsVisible        = false;
            selectionScreen.OnAnimationDone += BgImageAnimationDone;
            AddController(selectionScreen);


            //Loads Maps
            LoadMaps(content);
            //Loads characters
            LoadCharacters(content);
            //Loads textboxes
            LoadText();

            //Creates the help and options button
            helpBox    = CreateBtn(Constants.WindowWidth - 100, 40, 180, 80, "help");
            optionsBox = CreateBtn(90, 40, 180, 80, "options");

            foreach (var pad in GamePadControllers)
            {
                pad.OnStartPress += OnStartPress;
                pad.OnBackPress  += OnBackPress;
            }

            //Loads the sounds for the menu
            Screen.soundController.LoadSelectionMenuSounds(content, this, characterModels);


            SubscribeToGameState = true;
        }
Example #16
0
        private void LoadMaps(ContentManager content)
        {
            //Loads all the map models from json textfiles
            mapModels = Serializing.LoadMaps();
            mapThumbs = new List <ImageController>();

            int row = 0, column = 0, i = 0;

            foreach (var map in mapModels)
            {
                ImageController thumb = new ImageController(Screen, map.thumbImage, 3, true);
                thumb.IsVisible     = false;
                thumb.ScaleDefault  = 0.1f;
                thumb.OriginDefault = new Vector2(300, 230) / 2;

                ImageModel img = thumb.SetPosition(300 * column + 200, row * 230 + 180);
                img.SetBoundBox(World, 280, 210, Vector2.Zero, Category.Cat5, Category.Cat4, true);
                img.BoundBox.IsSensor = true;
                img.BoundBox.Enabled  = false;
                img.BoundBox.UserData = i;

                AddController(thumb);
                mapThumbs.Add(thumb);

                if (column == 3)
                {
                    row++;
                    column = 0;
                }
                else
                {
                    column++;
                }

                i++;
            }
        }
Example #17
0
        public override void Load(ContentManager content)
        {
            Screen.cursorsController.OnCursorClick += OnCursorClick;
            Screen.cursorsController.OnCursorCollision += OnCursorCollision;
            Screen.cursorsController.OnCursorSeparation += OnCursorSeparation;

            //Loads the background for selectionmenuy and startscreen
            startScreen = new ImageController(Screen, "Menu/StartScreen", 1, true);
            startScreen.OnAnimationDone += BgImageAnimationDone;
            startScreen.IsVisible = true;
            AddController(startScreen);

            selectionScreen = new ImageController(Screen, "Menu/SelectionScreen", 1, true);
            selectionScreen.IsVisible = false;
            selectionScreen.OnAnimationDone += BgImageAnimationDone;
            AddController(selectionScreen);

            //Loads Maps
            LoadMaps(content);
            //Loads characters
            LoadCharacters(content);
            //Loads textboxes
            LoadText();

            //Creates the help and options button
            helpBox = CreateBtn(Constants.WindowWidth - 100, 40, 180, 80, "help");
            optionsBox = CreateBtn(90, 40, 180, 80, "options");

            foreach (var pad in GamePadControllers)
            {
                pad.OnStartPress += OnStartPress;
                pad.OnBackPress += OnBackPress;
            }

            //Loads the sounds for the menu
            Screen.soundController.LoadSelectionMenuSounds(content, this, characterModels);

            SubscribeToGameState = true;
        }
Example #18
0
        public override void Load(ContentManager content)
        {
            Vector2 percentPos = new Vector2(330 * characterModel.playerIndex + 30, Constants.WindowHeight - 120);

            thumb = new ImageView(content.Load<Texture2D>(GamePadControllers[characterModel.playerIndex].PlayerModel.SelectedCharacter.thumbnail),
                percentPos, 159, true);
            thumb.Scale = 0.6f;
            AddView(thumb);

            percentBox = new TextBox("0%", GetFont("Impact.large"), percentPos + new Vector2(180, 40), Color.White, 1f);
            percentBox.StaticPosition = true;
            percentBox.Layer = 150;
            percentBox.Origin = new Vector2(20, 0);
            AddView(percentBox);

            percentBg = new ImageView(content.Load<Texture2D>("GameStuff/PlayerPercentBg"), percentPos + new Vector2(0, 94), 149, true);
            AddView(percentBg);

            if (gameOptions.UseLifes)
            {
                lifes = new ImageController(Screen, "GameStuff/Life", 160, true);
                AddController(lifes);
                for (int i = 0; i < gameOptions.Lifes; i++)
                {
                    lifes.AddPosition(percentPos + new Vector2(i * 16 + 130, 100), 400);
                }
            }
        }
Example #19
0
        public override void Load(ContentManager content)
        {
            //Initialises the view for the menu entries
            menuView = new MenuView(FontDefualt);
            menuView.Layer = 1001;
            menuView.StartingPosition = new Vector2(175, 0);
            menuView.StaticPosition = true;

            //Loads the menu background
            bg = new ImageController(Screen, "Menu/PopupMenu", 1000, true);
            bg.SetPosition(175, -700);
            //content, "Menu/PopupMenu", 175, -700);
            bg.OnAnimationDone += OnAnimationDone;
            AddController(bg);

            //Create the menu models
            createGamePauseMenu(FontDefualt);
            createOptionsMenu(FontDefualt);
            createHelpMenu(FontDefualt);

            //Adds listeners to cursors
            Screen.cursorsController.OnCursorClick += OnCursorClick;
            Screen.cursorsController.OnCursorCollision += OnCursorCollision;
            Screen.cursorsController.OnCursorSeparation += OnCursorSeparation;

            SubscribeToGameState = true;
        }
Example #20
0
 private void OnAnimationDone(ImageController img, ImageModel pos)
 {
     switch (State)
     {
         case PopupState.Colapsed:
             break;
         case PopupState.GamePause:
             ShowGamePauseMenu();
             break;
         case PopupState.Removed:
             break;
         case PopupState.Options:
             ShowOptionsMenu();
             break;
         case PopupState.Help:
             ShowHelpMenu();
             break;
         default:
             break;
     }
 }
Example #21
0
        private void LoadMaps(ContentManager content)
        {
            //Loads all the map models from json textfiles
            mapModels = Serializing.LoadMaps();
            mapThumbs = new List<ImageController>();

            int row = 0, column = 0, i = 0;
            foreach (var map in mapModels)
            {
                ImageController thumb = new ImageController(Screen, map.thumbImage, 3, true);
                thumb.IsVisible = false;
                thumb.ScaleDefault = 0.1f;
                thumb.OriginDefault = new Vector2(300, 230)/2;

                ImageModel img = thumb.SetPosition(300 * column + 200, row * 230 + 180);
                img.SetBoundBox(World, 280, 210, Vector2.Zero, Category.Cat5, Category.Cat4, true);
                img.BoundBox.IsSensor = true;
                img.BoundBox.Enabled = false;
                img.BoundBox.UserData = i;

                AddController(thumb);
                mapThumbs.Add(thumb);

                if (column == 3)
                {
                    row++;
                    column = 0;
                }else
                    column++;

                i++;
            }
        }
Example #22
0
        private void LoadCharacters(ContentManager content)
        {
            //Loads the characters from the xml files
            characterModels = Serializing.LoadCharacters();

            characterThumbs = new List<ImageController>();
            characterImages = new List<ImageController>();

            int i = 0;
            int row = 0, col = 0;

            //Create textures for thumb and image for every character model
            foreach (CharacterStats character in characterModels)
            {

                ImageController thumb = new ImageController(Screen, character.thumbnail, 3, true);
                thumb.OriginDefault = new Vector2(Constants.ThumbWith - 10, Constants.ThumbHeight - 10) / 2;
                thumb.IsVisible = false;
                thumb.ScaleDefault = 0.1f;

                ImageModel thumbModel = thumb.SetPosition(col * Constants.ThumbWith + 200, row * Constants.ThumbHeight + 210);
                thumbModel.SetBoundBox(World, Constants.ThumbWith - 20, Constants.ThumbHeight - 20, new Vector2(10, 0),
                    Category.Cat5, Category.Cat4, true);
                thumbModel.BoundBox.IsSensor = true;
                thumbModel.BoundBox.Enabled = false;
                thumbModel.BoundBox.UserData = i;

                AddController(thumb);
                characterThumbs.Add(thumb);

                //Check if new row
                if (i == 4)
                {
                    row++;
                    col = 0;
                }
                else col++;
                i++;

                //Creates the images for every texture
                var img = new ImageController(Screen, character.image, 4, true);
                AddController(img);
                characterImages.Add(img);
            }
        }
Example #23
0
 private void BgImageAnimationDone(ImageController target, ImageModel imagePosition)
 {
     if (imagePosition.CurrentPos.Y <= -10)
         target.IsVisible = false;
 }
Example #24
0
 private void OnHitAnimationDone(ImageController target, ImageModel imagePosition)
 {
     target.RemovePosition(imagePosition);
 }
Example #25
0
        public override void Update(GameTime gameTime)
        {
            //If wait for gameovertext = true then game is over, just waiting for gameOver text to animate + som extra time
            if (CurrentState != GameState.GamePause)
            {
                if (!waitForGameOverText)
                {

                    bool gameOver = false;

                    #region Checks if game is over
                    //If uselifes is set, then check if there is only one player left with one life
                    //else check if timeLEft is 0
                    if (Screen.GameOptions.UseLifes)
                    {
                        //Checks if all except one player is dead
                        int deadPlayers = 0;
                        foreach (var stats in players)
                        {
                            if (stats.Value.PlayerStats.LifesLeft == 0)
                            {
                                deadPlayers++;
                            }
                        }

                        gameOver = deadPlayers == players.Count() - 1;

                    }
                    else
                    {
                        timeLeft = timeLeft - new TimeSpan(0, 0, 0, 0, gameTime.ElapsedGameTime.Milliseconds);
                        timer.Text = getTimeLeft();

                        if (timeLeft.Minutes <= 0 && timeLeft.Seconds <= 0)
                        {
                            gameOver = true;
                        }
                    }
                    #endregion

                    //If gameIsOVer and gameOver not is run yet
                    //Then add the gameover text and animate it in
                    //Game is put in gameover state when animation is done
                    if (gameOver)
                    {
                        Screen.popupMenuController.State = PopupState.Removed;

                        #region Check and sets which player that has won game
                        if (Screen.GameOptions.UseLifes)
                        {
                            //if use lifes it finds the player that has lifes left
                            players.Where(a => a.Value.PlayerStats.LifesLeft != 0).First().Value.PlayerStats.IsWinner = true;
                        }
                        else
                        {
                            int max = 0;
                            List<int> winners = new List<int>();
                            foreach (var p in players)
                            {
                                int kills = p.Value.PlayerStats.PlayerKills.Count();
                                if (kills > max)
                                {
                                    max = kills;
                                    winners = new List<int>() { p.Value.PlayerStats.PlayerIndex };
                                }
                                else if (kills == max)
                                {
                                    winners.Add(p.Value.PlayerStats.PlayerIndex);
                                }
                            }

                            foreach (var p in players)
                            {
                                if (winners.Exists(a => a == p.Value.PlayerStats.PlayerIndex))
                                {
                                    p.Value.PlayerStats.IsWinner = true;
                                }
                            }

                        }
                        #endregion

                        waitForGameOverText = true;

                        //Shows the gameover text
                        AddController(this.gameOver);
                        ImageModel model = this.gameOver.SetPosition(Constants.WindowWidth / 2, Constants.WindowHeight / 2);
                        //Animates it in
                        this.gameOver.AnimateScale(1f, 800, false);

                        //Disables the start menu so you can't press start while the gameovertext shows
                        Screen.popupMenuController.Disabled = true;
                    }
                }
                else
                {
                    //Terminate the controller and starts the menu controller when the gameoverwait is done
                    gameOverWait -= gameTime.ElapsedGameTime.Milliseconds;
                    if (gameOverWait <= 0)
                    {
                        CurrentState = GameState.GameOver;
                        AddController(new MenuController(Screen, GetGameStats()));
                        DisposeController(this);
                    }
                }
            }
        }
Example #26
0
 private void OnHitAnimationDone(ImageController target, ImageModel imagePosition)
 {
     target.RemovePosition(imagePosition);
 }
Example #27
0
        public override void Update(GameTime gameTime)
        {
            //If wait for gameovertext = true then game is over, just waiting for gameOver text to animate + som extra time
            if (CurrentState != GameState.GamePause)
            {
                if (!waitForGameOverText)
                {
                    bool gameOver = false;

                    #region Checks if game is over
                    //If uselifes is set, then check if there is only one player left with one life
                    //else check if timeLEft is 0
                    if (Screen.GameOptions.UseLifes)
                    {
                        //Checks if all except one player is dead
                        int deadPlayers = 0;
                        foreach (var stats in players)
                        {
                            if (stats.Value.PlayerStats.LifesLeft == 0)
                            {
                                deadPlayers++;
                            }
                        }

                        gameOver = deadPlayers == players.Count() - 1;
                    }
                    else
                    {
                        timeLeft   = timeLeft - new TimeSpan(0, 0, 0, 0, gameTime.ElapsedGameTime.Milliseconds);
                        timer.Text = getTimeLeft();

                        if (timeLeft.Minutes <= 0 && timeLeft.Seconds <= 0)
                        {
                            gameOver = true;
                        }
                    }
                    #endregion

                    //If gameIsOVer and gameOver not is run yet
                    //Then add the gameover text and animate it in
                    //Game is put in gameover state when animation is done
                    if (gameOver)
                    {
                        Screen.popupMenuController.State = PopupState.Removed;

                        #region Check and sets which player that has won game
                        if (Screen.GameOptions.UseLifes)
                        {
                            //if use lifes it finds the player that has lifes left
                            players.Where(a => a.Value.PlayerStats.LifesLeft != 0).First().Value.PlayerStats.IsWinner = true;
                        }
                        else
                        {
                            int        max     = 0;
                            List <int> winners = new List <int>();
                            foreach (var p in players)
                            {
                                int kills = p.Value.PlayerStats.PlayerKills.Count();
                                if (kills > max)
                                {
                                    max     = kills;
                                    winners = new List <int>()
                                    {
                                        p.Value.PlayerStats.PlayerIndex
                                    };
                                }
                                else if (kills == max)
                                {
                                    winners.Add(p.Value.PlayerStats.PlayerIndex);
                                }
                            }

                            foreach (var p in players)
                            {
                                if (winners.Exists(a => a == p.Value.PlayerStats.PlayerIndex))
                                {
                                    p.Value.PlayerStats.IsWinner = true;
                                }
                            }
                        }
                        #endregion

                        waitForGameOverText = true;

                        //Shows the gameover text
                        AddController(this.gameOver);
                        ImageModel model = this.gameOver.SetPosition(Constants.WindowWidth / 2, Constants.WindowHeight / 2);
                        //Animates it in
                        this.gameOver.AnimateScale(1f, 800, false);

                        //Disables the start menu so you can't press start while the gameovertext shows
                        Screen.popupMenuController.Disabled = true;
                    }
                }
                else
                {
                    //Terminate the controller and starts the menu controller when the gameoverwait is done
                    gameOverWait -= gameTime.ElapsedGameTime.Milliseconds;
                    if (gameOverWait <= 0)
                    {
                        CurrentState = GameState.GameOver;
                        AddController(new MenuController(Screen, GetGameStats()));
                        DisposeController(this);
                    }
                }
            }
        }
Example #28
0
        public override void OnNext(GameStateManager value)
        {
            ImageController animateIn = null, animateOut = null;

            switch (value.PreviousState)
            {
            case GameState.StartScreen:
                if (value.CurrentState != GameState.StartScreen)
                {
                    animateOut = startScreen;
                    RemoveView(tipsText);
                }
                break;

            case GameState.CharacterMenu:
                CharacterSelectionVisible = false;
                break;

            case GameState.MapsMenu:
                MapSelectionVisible = false;
                break;

            case GameState.GameOver:
                GameStatsVisible      = false;
                continueText.Position = new Vector2(250, 320);
                foreach (var pad in GamePadControllers)
                {
                    pad.PlayerModel.SelectedCharacter = null;
                }
                break;
            }

            switch (value.CurrentState)
            {
            case GameState.StartScreen:
                startScreen.IsVisible = true;
                animateOut            = selectionScreen;
                animateIn             = startScreen;
                AddView(tipsText);
                break;

            case GameState.CharacterMenu:
                selectionScreen.IsVisible = true;
                if (value.PreviousState != GameState.MapsMenu)
                {
                    animateIn = selectionScreen;
                }
                //Loads the sounds for the menu
                CharacterSelectionVisible = true;

                Screen.soundController.PlaySound("Menu/chooseCharacter");
                break;

            case GameState.MapsMenu:
                selectionScreen.IsVisible = true;
                //if selection screen not has position
                //then the gameplay has exited to mapselection
                if (selectionScreen.GetAt(0) == null)
                {
                    animateIn = selectionScreen;
                }
                MapSelectionVisible = true;
                break;

            case GameState.GamePlay:
                AddController(new GamePlayController(Screen, selectedMap));
                DisposeController(this);

                break;

            case GameState.GamePause:
                break;

            case GameState.GameOver:
                selectionScreen.IsVisible = true;
                animateIn        = selectionScreen;
                GameStatsVisible = true;
                Screen.popupMenuController.Disabled = false;
                break;
            }

            if (animateIn != null)
            {
                animateIn.Layer = 2;
                animateIn.SetPosition(-1280, 0);
                animateIn.AnimatePos(0, 0, 600, false);
            }
            if (animateOut != null)
            {
                animateOut.Layer = 1;
                animateOut.SetPosition(0, 0);
                animateOut.AnimatePos(1280, 0, 600, false);
            }
        }