예제 #1
0
파일: Game1.cs 프로젝트: caijo/StarDefense
        /// <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);

            background = new Background(
                Content,
                @"Textures\PrimaryBackground",
                @"Textures\ParallaxStars");

            player = new Player(Content.Load<Texture2D>(@"Textures\PlayerShip"));

            bullets[0] = new Bullet(Content.Load<Texture2D>(@"Textures\PlayerBullet"));

            for (int x = 1; x < iMaxBullets; x++)
                bullets[x] = new Bullet();

            t2dEnemyShip = Content.Load<Texture2D>(@"Textures\enemy");

            for (int i = 0; i < iTotalMaxEnemies; i++)
            {
                Enemies[i] = new Enemy(t2dEnemyShip, 0, 0, 32, 32, 1);
            }

            t2dExplosionSheet = Content.Load<Texture2D>(@"Textures\Explosions");
            for (int i = 0; i < iTotalMaxEnemies + 1; i++)
            {
                Explosions[i] = new Explosion(t2dExplosionSheet,
                                0, rndGen.Next(8) * 64, 64, 64, 16);
            }

            t2dTitleScreen = Content.Load<Texture2D>(@"Textures\TitleScreen");
            // TODO: use this.Content to load your game content here
        }
예제 #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);

            background = new Background(
                Content,
                @"Textures\PrimaryBackground",
                @"Textures\ParallaxStars",
                @"Textures\shop2");

            player = new Player(Content.Load<Texture2D>(@"Textures\PlayerShip"));

            bullets[0] = new Bullet(Content.Load<Texture2D>(@"Textures\PlayerBullet"));

            for (int x = 1; x < iMaxBullets; x++)
                bullets[x] = new Bullet();

            t2dEnemyShip = Content.Load<Texture2D>(@"Textures\enemy");

            for (int i = 0; i < iTotalMaxEnemies; i++)
            {
                Enemies[i] = new Enemy(t2dEnemyShip, 0, 0, 32, 32, 1);
            }

            t2dExplosionSheet = Content.Load<Texture2D>(@"Textures\Explosions");
            for (int i = 0; i < iTotalMaxEnemies + 1; i++)
            {
                Explosions[i] = new Explosion(t2dExplosionSheet,
                                0, rndGen.Next(8) * 64, 64, 64, 16);
            }

            t2dTitleScreen = Content.Load<Texture2D>(@"Textures\TitleScreen");
            t2dShopScreen = Content.Load<Texture2D>(@"Textures\ParallaxStars");

            t2dGameScreen = Content.Load<Texture2D>(@"Textures\GameScreen");

            spriteFont = Content.Load<SpriteFont>(@"Fonts\Pericles");

            //populate powerup texture array
            //Regex r = new Regex("");
            //string temp = Regex.Replace(Directory.GetCurrentDirectory(),);
            //System.String pathStr =Directory.GetCurrentDirectory() + "\\Textures\\sprites";
            string[] filePaths = Directory.GetFiles(@"Content\Textures\sprites", "*.xnb");
            Array.Sort<string>(filePaths);
            textures = new Texture2D[filePaths.Length];
            for (int i = 0; i < filePaths.Length; i++)
            {
                string s = filePaths[i];
                int length = s.IndexOf(".");
                System.Diagnostics.Debug.WriteLine("original string: " + s + s.Substring(8, length-8) + "lenght " + length.ToString());
                //textures[i] = Content.Load<Texture2D>(Path.GetFullPath(filePaths[i]));
                textures[i] = Content.Load<Texture2D>(s.Substring(8, length - 8));
            }

            for (int i = 0; i < iMaxPowerups; i++)
            {
                powerups[i] = new PowerUp(textures, 0);
            }
            iTextureSize = textures.Length - 1;
            shopPowerUp = new PowerUp(textures,textures.Length-1);

            for (int i = 0; i < iMaxInventory; i++)
            {
                inventory[i] = new PowerUp(textures,0);
            }

            PlayerShots[0] = Content.Load<SoundEffect>(@"Sounds\Scifi002");
            PlayerShots[1] = Content.Load<SoundEffect>(@"Sounds\Scifi050");
            ExplosionSounds[0] = Content.Load<SoundEffect>(@"Sounds\battle003");
            ExplosionSounds[1] = Content.Load<SoundEffect>(@"Sounds\battle004");
            PowerUpPickupSound = Content.Load<SoundEffect>(@"Sounds\Scifi041");

            // TODO: use this.Content to load your game content here
        }