コード例 #1
0
        public ScoreScene(
            Game game,
            SpriteFont font,
            IDictionary<int, string> highScores,
            Texture2D background,
            params Tuple<int, IController>[] playerScores)
            : base(game)
        {
            var backgroundComponent = new ImageComponent(game, background, ImageComponent.DrawMode.Center);
            Components.Add(backgroundComponent);

            if (highScores.Count < 10 || playerScores.Any(ps => highScores.Keys.Any(k => k < ps.Item1)))
            {
                AcceptingInput = true;
                var highCount = playerScores.Count(ps => highScores.Keys.Any(k => k < ps.Item1));

                var remove = _highScores.Keys.OrderBy(k => k).Take(highCount);
                foreach (var r in remove)
                {
                    _highScores.Remove(r);
                }

                _playerEntries =
                    playerScores.OrderByDescending(ps => ps.Item1)
                                .Take(highCount)
                                .Select(ps => Tuple.Create(ps.Item1, ps.Item2, string.Empty))
                                .ToList();
                foreach (var pe in _playerEntries)
                {
                    highScores.Add(pe.Item1, pe.Item3);
                }
            }

            var y = 100;
            foreach (var hs in highScores.OrderByDescending(x => x.Key))
            {
                var component = new TextComponent(game, font, new Vector2(100, y), Color.White)
                                    {
                                        Visible = true,
                                        Enabled = true,
                                        Text = hs.Value + "   " + hs.Key
                                    };

                var playerScore = playerScores.LastOrDefault(ps => hs.Key == ps.Item1);
                var controller = playerScore != null ? playerScore.Item2 : null;
                Components.Add(component);
                _highScores.Add(hs.Key, Tuple.Create(string.Empty, component, controller));
                y += 100;
            }
        }
コード例 #2
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="game">The main game object</param>
        /// <param name="theTexture">Texture with the sprite elements</param>
        /// <param name="backgroundTexture">Texture for the background</param>
        /// <param name="font">Font used in the score</param>
        public ActionScene(Game game, Texture2D theTexture,
            Texture2D backgroundTexture, SpriteFont font)
            : base(game)
        {
            background = new ImageComponent(game, backgroundTexture,
                ImageComponent.DrawMode.Stretch);
            Components.Add(background);

            actionTexture = theTexture;

            // Get the current sprite batch
            spriteBatch = (SpriteBatch)
                Game.Services.GetService(typeof(SpriteBatch));

            // Get the audio library
            audio = (AudioLibrary)
                Game.Services.GetService(typeof(AudioLibrary));

            meteors = new MeteorsManager(Game, ref actionTexture);
            Components.Add(meteors);

            player1 = new Player(Game, ref actionTexture, PlayerIndex.One,
                new Rectangle(323, 15, 30, 30));
            player1.Initialize();
            Components.Add(player1);

            player2 = new Player(Game, ref actionTexture, PlayerIndex.Two,
                new Rectangle(360, 17, 30, 30));
            player2.Initialize();
            Components.Add(player2);

            scorePlayer1 = new Score(game, font, Color.Blue);
            scorePlayer1.Position = new Vector2(10, 10);
            Components.Add(scorePlayer1);
            scorePlayer2 = new Score(game, font, Color.Red);
            scorePlayer2.Position = new Vector2(
                Game.Window.ClientBounds.Width - 200, 10);
            Components.Add(scorePlayer2);

            rumblePad = new SimpleRumblePad(game);
            Components.Add(rumblePad);

            powerSource = new PowerSource(game, ref actionTexture);
            powerSource.Initialize();
            Components.Add(powerSource);
        }
コード例 #3
0
        ActionScene(
            Game game, Texture2D theTexture, Texture2D backgroundTexture, SpriteFont font, Vector2 gameoverPosition)
            : base(game)
        {
            this._audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));
            this._background = new ImageComponent(game, backgroundTexture, ImageComponent.DrawMode.Stretch);
            Components.Add(this._background);
            this._actionTexture = theTexture;
            this._spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            this._meteors = new MeteorsManager(Game, ref this._actionTexture);
            Components.Add(this._meteors);
            this._scoreFont = font;
            this._gameoverPosition = gameoverPosition;
            this._scorePlayer1 = new Score(game, font, Color.Blue) { Position = new Vector2(10, 10) };
            Components.Add(this._scorePlayer1);

            this._rumblePad = new SimpleRumblePad(game);
            Components.Add(this._rumblePad);
            this._powerSource = new PowerSource(game, ref this._actionTexture);
            Components.Add(this._powerSource);
            #if DEBUG
            this._positionDebugText = new TextComponent(game, this._scoreFont, new Vector2(), Color.Red);
            Components.Add(this._positionDebugText);
            #endif
        }
コード例 #4
0
        ActionScene(Game game, Texture2D theTexture, Texture2D backgroundTexture, SpriteFont font)
            : base(game)
        {
            _audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));
            _background = new ImageComponent(game, backgroundTexture, ImageComponent.DrawMode.Stretch);
            Components.Add(_background);

            _actionTexture = theTexture;

            _spriteBatch = (SpriteBatch) Game.Services.GetService(typeof (SpriteBatch));
            _meteors = new MeteorsManager(Game, ref _actionTexture);
            Components.Add(_meteors);

            _scoreFont = font;

            _scorePlayer1 = new Score(game, font, _player1FontColor) {Position = new Vector2(10, 10)};
            Components.Add(_scorePlayer1);

            _rumblePad = new SimpleRumblePad(game);
            Components.Add(_rumblePad);

            _powerSource = new PowerSource(game, ref _actionTexture);
            _powerSource.Initialize();
            Components.Add(_powerSource);

            _wrench = new Wrench(game, game.Content.Load<Texture2D>("wrench"));
            _wrench.Initialize();
            Components.Add(_wrench);

            #if DEBUG
            _positionDebugText=new TextComponent(game,_scoreFont,new Vector2(),Color.Red);
            Components.Add(_positionDebugText);
            #endif
        }