Beispiel #1
0
        public NewMatchState(IAnarkanoidGame arkanoidGame, IKeysConfiguration keysConfiguration) : base(arkanoidGame, keysConfiguration)
        {
            AnarkanoidGame.ComponentManager.Clear();
            AnarkanoidGame.CurrentLives = Configuration.InitialLives;

            _levelText = new ShowText(Configuration, new Size(Configuration.ScreenSize.Width, Configuration.ScreenSize.Height))
            {
                Position = new Microsoft.Xna.Framework.Vector2(150, 120)
            };
            AnarkanoidGame.ComponentManager.AddText(_levelText, string.Format(LEVEL_TEXT, AnarkanoidGame.CurrentStage + 1));

            _text = new ShowText(Configuration, new Size(Configuration.ScreenSize.Width, Configuration.ScreenSize.Height))
            {
                Position = new Microsoft.Xna.Framework.Vector2(150, 150)
            };
            AnarkanoidGame.ComponentManager.AddText(_text, string.Format(TEXT_FORMAT, 3 - _totalTicks));

            Components.SpaceShip.Reset();
            AnarkanoidGame.ComponentManager.AddSpaceShip(AnarkanoidGame.ComponentManager.SpaceShip);

            var ball = AnarkanoidGame.ComponentManager.BallRepository.GetBasicBall();

            ball.Reset();
            AnarkanoidGame.ComponentManager.AddBall(ball);

            var boardFileName   = Environment.CurrentDirectory + "\\Boards\\" + AnarkanoidGame.ComponentManager.Configuration.Boards[AnarkanoidGame.CurrentStage] + ".stage";
            var boardDefinition = new BoardDefinition(boardFileName);

            AnarkanoidGame.ComponentManager.LoadBoard(boardDefinition);

            _timer          = new Timer(1000);
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
            _returnState = this;

            CommandPerKey.Add(Keys.Left, CommandsFactory.GetMoveSpaceShipToLeftCommand());
            CommandPerKey.Add(Keys.Right, CommandsFactory.GetMoveSpaceShipToRightCommand());
        }
Beispiel #2
0
        public IntroGameState(IAnarkanoidGame anarkanoidGame, IKeysConfiguration keys) : base(anarkanoidGame, keys)
        {
            KeyDelay      = KEY_DELAY;
            TOTAL_OPTIONS = OPTIONS_TEXTS.Length;
            AnarkanoidGame.CurrentStage = 0;

            var backgroundSize = new Size(
                AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Width,
                AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Height
                );

            _background = new CustomElement(AnarkanoidGame.ComponentManager.Configuration, backgroundSize)
            {
                Scale = new Vector2(BACKGROUND_SCALE, BACKGROUND_SCALE)
            };
            AnarkanoidGame.ComponentManager.AddComponentByAssetName(_background, "Title");

            var spaceInvaderSize = new Size(
                AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Width / SPACE_INVADER_PERCENT_SCALE,
                AnarkanoidGame.ComponentManager.Configuration.ScreenSize.Height / SPACE_INVADER_PERCENT_SCALE
                );

            _spaceInvader = new CustomElement(AnarkanoidGame.ComponentManager.Configuration, spaceInvaderSize)
            {
                Position = SPACE_INVADER_POSITION
            };
            AnarkanoidGame.ComponentManager.AddComponentByAssetName(_spaceInvader, "SpaceInvader");

            var subtitle = new ShowText(AnarkanoidGame.ComponentManager.Configuration, OPTION_TEXT_SIZE)
            {
                Position    = SUBTITLE_POSITION,
                SpriteColor = Color.Red,
                Scale       = new Vector2(1.5f, 1.5f)
            };

            AnarkanoidGame.ComponentManager.AddText(subtitle, SUBTITLE_TEXT);

            //SUBTITLE_TEXT

            var textTopPosition = FIRST_OPTION_TEXT_POSITION.Y;

            _optionsText = new List <ShowText>();
            foreach (string optionText in OPTIONS_TEXTS)
            {
                var text = new ShowText(AnarkanoidGame.ComponentManager.Configuration, OPTION_TEXT_SIZE)
                {
                    Position    = new Vector2(FIRST_OPTION_TEXT_POSITION.X, textTopPosition),
                    SpriteColor = Color.Black
                };
                AnarkanoidGame.ComponentManager.AddText(text, optionText);
                _optionsText.Add(text);
                textTopPosition += text.Size.Height;
            }

            ACTIONS = new System.Action[]
            {
                NewGameSelected, ConfigureControlsSelected, ToggleFullScreenSelected, ExitGameSelected
            };

            AnarkanoidGame.ComponentManager.SpaceShip.Scale    = new Vector2(.8f, .8f);
            AnarkanoidGame.ComponentManager.SpaceShip.Position = new Vector2(
                _optionsText[0].Position.X - AnarkanoidGame.ComponentManager.SpaceShip.Size.Width,
                _optionsText[0].Position.Y + 10
                );
            AnarkanoidGame.ComponentManager.AddSpaceShip(AnarkanoidGame.ComponentManager.SpaceShip);

            CommandsFactory.GetDelayedActionCommand(ToggleSpceInvaderPosition, 1000).Execute();

            CommandPerKey.Add(Keys.Up, CommandsFactory.GetActionCommand(MoveUpOption));
            CommandPerKey.Add(Keys.Down, CommandsFactory.GetActionCommand(MoveDownOption));
            CommandPerKey.Add(Microsoft.Xna.Framework.Input.Keys.Enter, CommandsFactory.GetActionCommand(EnterPressed));

            _returnState = this;

            AnarkanoidGame.ComponentManager.PlaySound("Anarky");
        }