예제 #1
0
        public Sprite(ContentStore content, string texName, float defaultXPos, float defaultYPos, int spriteWidth, int spriteHeight)
        {
            //assign and load content
            mContentStore = content;
            mTexture      = mContentStore.getTexture(texName);
            mTexName      = texName;
            //cal aspect ratio and dimensions
            //float aspect = mTexture.Width / mTexture.Height;
            //int height = (int)Math.Round(inDrawWidth * aspect);

            //generate a rectangle with the dimentions of the texture
            mRectangle = new Rectangle(0, 0, spriteWidth, spriteHeight);
            Console.WriteLine();
            SetPosition(defaultXPos, defaultYPos);
        }
예제 #2
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);

            screenWidth  = GraphicsDevice.Viewport.Width;
            screenHeight = GraphicsDevice.Viewport.Height;

            //load sounds
            string gunSound       = "laser";
            string backgroundSong = "spaceInvaders";

            mContentStore.addSoundEffect(gunSound);
            mContentStore.addSong(backgroundSong);
            mSoundManager.playSong(mContentStore.getSong(backgroundSong));
            mSoundManager.setVolume(0.1f);

            //fonts
            mContentStore.addSpriteFont("MessageFont");


            //init the enemies list
            mEnemies   = new List <Enemy>();
            mBarricade = new List <Barricade>();

            //splash screen texture
            string splashScreenTex = "splashScreen";

            mContentStore.addTexture(splashScreenTex);
            //gameplay background
            string backGroundTexture = "BackGrounds";

            mContentStore.addTexture(backGroundTexture);
            //Enemy texture
            string enemyTexture = "Alien1";

            mContentStore.addTexture(enemyTexture);
            //space ship texture
            string spaceShipTexture = "SpaceShip";

            mContentStore.addTexture(spaceShipTexture);
            int spaceshipWidth = screenWidth / 25;
            //barricade texture
            string barricateTexture = "block";

            mContentStore.addTexture(barricateTexture);
            int barricadeWidth = 10;
            //bullet texture
            string bulletTexture = "bullet";

            mContentStore.addTexture(bulletTexture);
            int bulletWidth = screenWidth / 20;



            //add player with a new mover
            int playerHorisontalSpeed = 200;

            int [] playerDimentions = { 50, 50 };
            mPlayer = new Player(mContentStore, spaceShipTexture, bulletTexture, gunSound, screenWidth / 2, screenHeight - playerDimentions[0] /*mContentStore.getTexture(spaceShipTexture).Height*/, playerHorisontalSpeed, 0, playerDimentions[0], playerDimentions[1]);

            //add enemies
            int numEnemyRows = 3, numEnemiyCols = 5;
            int enemyPosX = 0, enemyPosY = 0;
            int enemySpacingX = 50, enemySpacingY = 60;

            int[] enemyDimentions = { 30, 30 };
            for (int i = 0; i < numEnemiyCols; i++)
            {
                for (int j = 0; j < numEnemyRows; j++)
                {
                    mEnemies.Add(new Enemy(mContentStore, enemyTexture, enemyPosX + (i * enemySpacingX), enemyPosY + (j * enemySpacingY), 0, 0, enemyDimentions[0], enemyDimentions[1]));
                }
            }
            //add barricades
            int numBarricades    = 4;
            int barricadeOffset  = (int)(screenWidth * 0.2f);
            int barricadeSpacing = 150;

            int[] barricadeDimentions = { 75, 25 };
            for (int i = 0; i < numBarricades; i++)
            {
                mBarricade.Add(new Barricade(mContentStore, barricateTexture, i * barricadeSpacing + barricadeOffset,
                                             (screenHeight * 0.9f) - mContentStore.getTexture(barricateTexture).Height,
                                             barricadeDimentions[0], barricadeDimentions[1]));
            }


            //the required things for the scenes
            int[]  splashImageDimentions = { screenWidth, screenHeight };
            Sprite splashImage           = new Sprite(mContentStore, splashScreenTex, 0, 0, splashImageDimentions[0], splashImageDimentions[1]);

            //gameplay background
            Sprite backGroundImage = new Sprite(mContentStore, backGroundTexture, 0, 0, splashImageDimentions[0], splashImageDimentions[1]);

            //create the scenes
            SplashScreen   splashScreen = new SplashScreen(splashImage, 1);                                  //create splash screen
            MainMenu       mainMenu     = new MainMenu(splashImage, mContentStore.GetSpriteFont("MessageFont"));
            GameplayScene  gameScene    = new GameplayScene(mPlayer, mEnemies, mBarricade, backGroundImage); //create gameplay scene
            HighScoreScene highScore    = new HighScoreScene(splashImage, mContentStore.GetSpriteFont("MessageFont"));


            //add the scenes to the manager
            mSceneManager.addScene(splashScreen); //add the splash screen
            mSceneManager.addScene(mainMenu);     //add the splash screen
            mSceneManager.addScene(gameScene);    //add the scene to the manager
            mSceneManager.addScene(highScore);


            startPlayingGame();
        }