Example #1
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // Get ControlManager from services
            _controlManager = (ControlManager)Game.Services.GetService(typeof(ControlManager));

            // Add new control (title)
            Control title = new Control("Lost Gold", Control.TextSizeOptions.Large);
            title.offsetY = -150;
            _controlManager.Add(title);

            // Add new control (byline)
            Control byLine = new Control("by Lars Boldt", Control.TextSizeOptions.Small);
            byLine.offsetY = -120;
            _controlManager.Add(byLine);

            // Add new selectablecontrol (Start game)
            SelectableControl newGameLbl = new SelectableControl("Start new game", Control.TextSizeOptions.Medium);
            newGameLbl.OnSelect += new EventHandler(newGameLbl_onSelect);
            _controlManager.Add(newGameLbl);

            // Add new selectablecontrol (exit game)
            SelectableControl exitLbl = new SelectableControl("Exit", Control.TextSizeOptions.Medium);
            exitLbl.offsetY = 30;
            exitLbl.OnSelect += new EventHandler(exitLbl_onSelect);
            _controlManager.Add(exitLbl);

            base.Initialize();
        }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Skip XML Dtd processing
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.DtdProcessing = 0;
            // Read in TMX level
            StreamReader stream = System.IO.File.OpenText("Content/Maps/Level.tmx");
            // Create XmlReader based on level stream
            XmlReader reader = XmlReader.Create(stream, settings);
            // Initialize engine with level xml
            engine = new Engine.Engine(this, reader);
            // Add engine to components
            Components.Add(engine);
            // Disable engine (Titlescreen is startup screen)
            engine.Visible = false;
            engine.Enabled = false;
            // Add engine to services
            Services.AddService(typeof(Engine.Engine), engine);

            // Add InputManager (Keyboard, GamePad)
            Components.Add(new InputManager(this));

            // Add titlescreen
            titleScreen = new TitleScreen(this);
            Components.Add(titleScreen);

            // Add ControlManager
            controlManager = new ControlManager(this);
            Components.Add(controlManager);
            Services.AddService(typeof(ControlManager), controlManager);

            base.Initialize();
        }
Example #3
0
        /// <summary>
        /// Load content
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            // SpriteBatch
            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            // Character
            _character = new Character(Game);
            // Set character position
            _character.X = _startX;
            _character.Y = _startY;
            // Get starting animation frame art for character
            _characterFrameArt = _character.getCurrentFrame(0, new GameTime());
            // Set character speed
            _characterSpeed = 2;

            // Camera2d
            _camera2d = new Camera2d();
            // Center camera on player
            _camera2d.Pos = centerCameraOnCharacter();
            // Camera zoom level
            _camera2d.Zoom = 1.5f;

            // Ambient sound - Load effect
            _ambientSound = Game.Content.Load<SoundEffect>(@"Sounds\AfternoonAmbienceSimple_01");
            _ambientPlayer = _ambientSound.CreateInstance();
            // Loop soundeffect
            _ambientPlayer.IsLooped = true;

            // Add each tile in each layer as a drawable
            foreach (Layer l in _layers)
            {
                foreach (LayerTile lt in l.LayerTiles)
                {
                    AddDrawable(
                        new DrawData(lt.TileSetTile.Art,
                            new Rectangle(
                                lt.X * _tileWidth,
                                lt.Y * _tileHeight,
                                lt.TileSetTile.Art.Width,
                                lt.TileSetTile.Art.Height
                            )
                        )
                    );
                }
            }

            // Get Control Manager
            _controlManager = (ControlManager)Game.Services.GetService(typeof(ControlManager));

            // Create timer control
            _timer = new Control(timeLeftToString(), Control.TextSizeOptions.Large);
            _timer.Id = "timer";
            _timer.CenterText = false;
            _timer.Position = Vector2.Zero;
            _timer.Color = Color.Goldenrod;
        }