コード例 #1
0
ファイル: Clouds.cs プロジェクト: thexa4/ticktick
        /// <summary>
        /// Creates new Clouds SpriteSet
        /// </summary>
        /// <param name="game">Game to bind to</param>
        /// <param name="n">Number of clouds</param>
        public Clouds(Game game, Int32 n)
            : base(game)
        {
            _velocities = new Dictionary<Sprite, float>();
            _cloudSprites = new Sprite[5];
            for (Int32 i = 0; i < _cloudSprites.Length; i++)
            {
                _cloudSprites[i] = new Sprite(game, String.Format("Graphics/Backgrounds/spr_cloud_{0}", i + 1));
                _cloudSprites[i].Enabled = false;
                _cloudSprites[i].Visible = false;
                _velocities.Add(_cloudSprites[i], 0);
            }

            // We only want different sprites to be visible. We have this number of
            // sprites (length) and we want that number of sprites (n). So get the
            // minimum and all will be fine.
            visible = Math.Min(n, _cloudSprites.Length);
        }
コード例 #2
0
ファイル: LevelScreen.cs プロジェクト: thexa4/ticktick
        /// <summary>
        /// Initializes the screen
        /// </summary>
        public override void Initialize()
        {
            _keyboardController = new KeyboardController(this.Game, Keys.W, Keys.A, Keys.D);
            _keyboardController.Initialize();

            /////////////////////////////////////
            // Build the layers
            /////////////////////////////////////

            // Add the sky
            var _backgroundSky = new Sprite(this.Game, "Graphics/Backgrounds/spr_sky");
            _background.Add(_backgroundSky);

            // Add a few random mountains
            var _mountains = new Sprite[5];
            for (int i = 0; i < 5; i++)
            {
                _mountains[i] = new Sprite(this.Game, String.Format("Graphics/Backgrounds/spr_mountain_{0}", (this.ScreenManager.Random.Next(2) + 1)));
                _background.Add(_mountains[i]);
            }

            // Add the clouds
            _background.Add(new Clouds(this.Game, 2));

            // Get the tiles
            var tiles = _levelData.GenerateComponents(this.Game, _foreground, out _levelState);
            foreach (var tile in tiles)
            {
                _foreground.Add(tile);
                if (tile.GetType() == typeof(Player))
                {
                    _player = tile as Player;
                    _playerController = new PlayerController(Game, _keyboardController, _player);
                    _playerController.Initialize();
                    _camera.FocusOn(_player);
                }
            }

            // Add the time
            _overlay.Add(new Sprite(this.Game, "Graphics/Sprites/spr_timer") { Position = Vector2.One * 10 });
            _overlay.Add(new TimerDisplay(this.Game, _levelState) { Position = new Vector2(31, 36) });

            // Add the quit button
            var quitButton = new Button(this.Game, this.InputManager, "Graphics/Sprites/spr_button_quit");
            _overlay.Add(quitButton);

            /////////////////////////////////////
            // Initialize the screen components
            /////////////////////////////////////

            base.Initialize();
            _camera.Initialize();
            _background.Initialize();
            _foreground.Initialize();
            _overlay.Initialize();

            _backgroundSky.Position = Vector2.UnitY * (this.ScreenManager.ScreenHeight - _backgroundSky.Texture.Height);
            foreach (var mountain in _mountains)
                mountain.Position = Vector2.UnitX * (Single)(this.ScreenManager.Random.NextDouble() * this.ScreenManager.ScreenWidth - mountain.Texture.Width / 2) +
                    Vector2.UnitY * (this.ScreenManager.ScreenHeight - mountain.Texture.Height);

            quitButton.Position = new Vector2(this.ScreenManager.ScreenWidth - quitButton.Texture.Width - 10, 10);

            /////////////////////////////////////
            // Action handlers
            /////////////////////////////////////

            quitButton.OnClicked += new ButtonClickDelegate(quitButton_OnClicked);
            _levelState.OnCompleted += new EventHandler(_levelState_OnCompleted);
            _levelState.OnLost += new EventHandler(_levelState_OnLost);

            System.Diagnostics.Debug.WriteLine("Called init");
        }