Пример #1
0
        private void AddEnemy()
        {
            // Create the animation object
            Animation enemyAnimation = new Animation();

            // Initialize the animation with the correct animation information
            int enemyFrameCount = 8;

            // Randomly generate the position of the enemy
            Vector2 position = new Vector2(GameplayScreen.Random.Next(250, this.ScreenManager.GraphicsDevice.Viewport.Width + this.enemyTexture.Width / 2), GameplayScreen.Random.Next(100, this.ScreenManager.GraphicsDevice.Viewport.Height - 100));

            // Create an enemy

            RotatingEnemy enemy;

            switch (Random.Next(9) % 8)
            {
                case 1:
                    enemy = new Roach();
                    this.enemyTexture = this.enemyAnimationTextures[6];
                    break;
                case 2:
                    enemy = new FireRoach();
                    this.enemyTexture = this.enemyAnimationTextures[7];
                    break;
                case 3:
                    enemy = new Fly();
                    this.enemyTexture = this.enemyAnimationTextures[2];
                    break;
                case 4:
                    enemy = new FireFly();
                    this.enemyTexture = this.enemyAnimationTextures[3];
                    break;
                //case 5:
                //    break;
                //case 6:
                //    break;
                //case 7:
                //    break;
                //case 8:
                //    break;
                default:
                    enemy = new Roach();
                    break;

            }

            enemyAnimation.Initialize(this.enemyTexture, Vector2.Zero, this.enemyTexture.Width / enemyFrameCount, this.enemyTexture.Height, enemyFrameCount, 30, Color.White, 1f, true);

            // Initialize the enemy
            enemy.Initialize(enemyAnimation, position, 0, 300);

            // Add the enemy to the active enemies list
            this.enemies.Add(enemy);
        }
Пример #2
0
 private void AddExplosion(Vector2 position)
 {
     Animation explosion = new Animation();
     int explosionFrameCount = 12;
     explosion.Initialize(this.explosionTexture, position, this.explosionTexture.Width / explosionFrameCount, this.explosionTexture.Height, explosionFrameCount, 45, Color.White, 1f, false);
     this.explosions.Add(explosion);
     SoundCaller explosionSound = new SoundCaller(this.roachSmashed);
     //
 }
Пример #3
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (this.content == null)
                {
                    this.content = new ContentManager(this.ScreenManager.Game.Services, "Content");
                }

                this.gameFont = this.content.Load<SpriteFont>("gamefont");
                // Create a new SpriteBatch, which can be used to draw textures.
                this.spriteBatch = new SpriteBatch(this.ScreenManager.GraphicsDevice);

                this.roachSmashed = content.Load<SoundEffect>(("Sounds\\roach_smashed"));
                this.shotSound = content.Load<SoundEffect>(("Sounds\\shot"));
                this.turretSound = content.Load<SoundEffect>(("Sounds\\turretLaunch"));
                // TODO: use this.Content to load your game content here

                //player
                Animation playerAnimation = new Animation();
                string plTexture = "player_2_animation";
                if (CharacterSelectionScreen.currentRace == CharacterSelectionScreen.Race.Administrator)
                {
                    plTexture = "player_2_animation";
                }
                else if (CharacterSelectionScreen.currentRace == CharacterSelectionScreen.Race.Designer)
                {
                    plTexture = "femaleFigure_walk";
                }
                else
                {
                    plTexture = "maleFigure_walk";
                }
                Texture2D playerTexture = this.content.Load<Texture2D>(plTexture);
                int playerFrames = 1;
                playerAnimation.Initialize(playerTexture, Vector2.Zero, playerTexture.Width / playerFrames, playerTexture.Height, playerFrames, 30, Color.White, 1f, true);

                Vector2 playerPosition = new Vector2(this.ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.X, this.ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Y +
                                                                                                                 this.ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
                this.player.Initialize(playerAnimation, playerPosition);

                //background screen
                this.mainframe = new Microsoft.Xna.Framework.Rectangle(0, 0, this.ScreenManager.GraphicsDevice.Viewport.Width, this.ScreenManager.GraphicsDevice.Viewport.Height);
                this.background = this.content.Load<Texture2D>("circuitBoard");

                //enemy
                this.enemyTexture = this.content.Load<Texture2D>("roach");
                enemyAnimationTextures = new List<Texture2D>();
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("ant"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("ant_ghost"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("fly"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("fly_ghost"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("moth"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("moth_ghost"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("roach"));
                enemyAnimationTextures.Add(this.content.Load<Texture2D>("roach_ghost"));

                //projectile
                this.projectileTexture = this.content.Load<Texture2D>("laser");
                this.turretProjTexture = this.content.Load<Texture2D>("turretProjectile");

                //effect explosions
                this.explosionTexture = this.content.Load<Texture2D>("explosion_2");

                //solid objects texture
                this.solidTexture = this.content.Load<Texture2D>("solid");
                //turret texture
                this.turretTexture = this.content.Load<Texture2D>("turret");
                InitializeSolids();

                //add turret that uses the same texture from solid
                InitializeTurrets();

                this.font = this.content.Load<SpriteFont>("gameFont");

                this.ScreenManager.Game.ResetElapsedTime();
            }
            #if WINDOWS_PHONE
            if (Microsoft.Phone.Shell.PhoneApplicationService.Current.State.ContainsKey("PlayerPosition"))
            {
            playerPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["PlayerPosition"];
            enemyPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["EnemyPosition"];
            }
            #endif
        }