Esempio n. 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="game"></param>
 /// <param name="player"></param>
 public PlayerController(Game game, KeyboardController kc, Player player)
     : base(game)
 {
     Player = player;
     _kc = kc;
 }
Esempio n. 2
0
        /// <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");
        }