예제 #1
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, ExplosionManager explosions)
            : base(game)
        {
            // Get the current audiocomponent and play the background music
            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);

            player = new Player(Game, ref actionTexture);
            player.Initialize();
            Components.Add(player);

            score          = new Score(game, font, Color.LightGray);
            score.Position = new Vector2(1, 1);
            Components.Add(score);

            powerSource = new PowerSource(game, ref actionTexture);
            powerSource.Initialize();
            Components.Add(powerSource);

            _explosions = explosions;
        }
예제 #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, ExplosionManager explosions) 
            : base(game)
        {
            // Get the current audiocomponent and play the background music
            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);

            player = new Player(Game, ref actionTexture);
            player.Initialize();
            Components.Add(player);

            score = new Score(game, font, Color.LightGray);
            score.Position = new Vector2(1, 1);
            Components.Add(score);

            powerSource = new PowerSource(game, ref actionTexture);
            powerSource.Initialize();
            Components.Add(powerSource);
			
			_explosions = explosions;
        }
예제 #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            // Setup virtual gamepad
            gamepadTexture = Content.Load <Texture2D>("gamepad.png");
            ButtonDefinition BButton = new ButtonDefinition();

            BButton.Texture     = gamepadTexture;
            BButton.Position    = new Vector2(100, 420);
            BButton.Type        = Buttons.Back;
            BButton.TextureRect = new Rectangle(72, 77, 36, 36);

            ButtonDefinition AButton = new ButtonDefinition();

            AButton.Texture     = gamepadTexture;
            AButton.Position    = new Vector2(150, 420);
            AButton.Type        = Buttons.A;
            AButton.TextureRect = new Rectangle(73, 114, 36, 36);

            GamePad.ButtonsDefinitions.Add(BButton);
            GamePad.ButtonsDefinitions.Add(AButton);

            ThumbStickDefinition thumbStick = new ThumbStickDefinition();

            thumbStick.Position              = new Vector2(220, 400);
            thumbStick.Texture               = gamepadTexture;
            thumbStick.TextureRect           = new Rectangle(2, 2, 68, 68);
            GamePad.LeftThumbStickDefinition = thumbStick;

            // Create the audio bank
            audio = new AudioLibrary(Content);
            Services.AddService(typeof(AudioLibrary), audio);

            // Create the Start Scene
            smallFont              = Content.Load <SpriteFont>("menuSmall");
            largeFont              = Content.Load <SpriteFont>("menuLarge");
            startElementsTexture   = Content.Load <Texture2D>("startsceneelements.png");
            startBackgroundTexture = Content.Load <Texture2D>("startbackground");
            startScene             = new StartScene(this, smallFont, largeFont, startBackgroundTexture, startElementsTexture);
            Components.Add(startScene);

            // Start the game in the start Scene :)
            startScene.Show();
            activeScene = startScene;
        }
예제 #4
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 the current audiocomponent and play the background music
            audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));

            meteors.Clear();

            Start();

            for (int i = 0; i < meteors.Count; i++)
            {
                meteors[i].Initialize();
            }

            base.Initialize();
        }
예제 #5
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 the current audiocomponent and play the background music
            audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));

            meteors.Clear();

            Start();

            for (int i = 0; i < meteors.Count; i++)
            {
                meteors[i].Initialize();
            }

            base.Initialize();
        }
예제 #6
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="game">Main game object</param>
        /// <param name="smallFont">Font for the menu items</param>
        /// <param name="largeFont">Font for the menu selcted item</param>
        /// <param name="background">Texture for background image</param>
        /// <param name="elements">Texture with the foreground elements</param>
        public StartScene(Game game, SpriteFont smallFont, SpriteFont largeFont,
                          Texture2D background, Texture2D elements)
            : base(game)
        {
            this.elements = elements;
            Components.Add(new ImageComponent(game, background,
                                              ImageComponent.DrawMode.Stretch));

            // Create the Menu
            string[] items = { "Play!", "Help", "Quit" };
            menu = new TextMenuComponent(game, smallFont, largeFont);
            menu.SetMenuItems(items);
            Components.Add(menu);

            // Get the current spritebatch
            spriteBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            // Get the current audiocomponent and play the background music
            audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));
        }
예제 #7
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="game">Main game object</param>
        /// <param name="smallFont">Font for the menu items</param>
        /// <param name="largeFont">Font for the menu selcted item</param>
        /// <param name="background">Texture for background image</param>
        /// <param name="elements">Texture with the foreground elements</param>
        public StartScene(Game game, SpriteFont smallFont, SpriteFont largeFont,
                            Texture2D background,Texture2D elements)
            : base(game)
        {
            this.elements = elements;
            Components.Add(new ImageComponent(game, background, 
                                            ImageComponent.DrawMode.Stretch));

            // Create the Menu
            string[] items = {"Play!", "Help", "Quit"};
            menu = new TextMenuComponent(game, smallFont, largeFont);
            menu.SetMenuItems(items);
            Components.Add(menu);

            // Get the current spritebatch
            spriteBatch = (SpriteBatch) Game.Services.GetService(typeof (SpriteBatch));
            // Get the current audiocomponent and play the background music
            audio = (AudioLibrary)Game.Services.GetService(typeof(AudioLibrary));
        }
예제 #8
0
파일: Game1.cs 프로젝트: QHebert/monogame
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            // Setup virtual gamepad
            gamepadTexture = Content.Load<Texture2D>("gamepad.png");
            ButtonDefinition BButton = new ButtonDefinition();
            BButton.Texture = gamepadTexture;
            BButton.Position = new Vector2(100,420);
            BButton.Type = Buttons.Back;
            BButton.TextureRect = new Rectangle(72,77,36,36);

            ButtonDefinition AButton = new ButtonDefinition();
            AButton.Texture = gamepadTexture;
            AButton.Position = new Vector2(150,420);
            AButton.Type = Buttons.A;
            AButton.TextureRect = new Rectangle(73,114,36,36);

            GamePad.ButtonsDefinitions.Add(BButton);
            GamePad.ButtonsDefinitions.Add(AButton);

            ThumbStickDefinition thumbStick = new ThumbStickDefinition();
            thumbStick.Position = new Vector2(220,400);
            thumbStick.Texture = gamepadTexture;
            thumbStick.TextureRect = new Rectangle(2,2,68,68);
            GamePad.LeftThumbStickDefinition = thumbStick;

            // Create the audio bank
            audio = new AudioLibrary(Content);
            Services.AddService(typeof(AudioLibrary), audio);

            // Create the Start Scene
            smallFont = Content.Load<SpriteFont>("menuSmall");
            largeFont = Content.Load<SpriteFont>("menuLarge");
            startElementsTexture = Content.Load<Texture2D>("startsceneelements.png");
            startBackgroundTexture = Content.Load<Texture2D>("startbackground");
            startScene = new StartScene(this, smallFont, largeFont,startBackgroundTexture, startElementsTexture);
            Components.Add(startScene);

            // Start the game in the start Scene :)
            startScene.Show();
            activeScene = startScene;
        }