Exemplo n.º 1
0
 //Constructor ----------------------------------------------------------------
 public MissleManager(ContentManager content, SpriteBatch spriteBatch)
 {
     this.z_playerShip = PlayerShip.getInstance();
     this.z_missiles = new List<MissileObject>();
     PlayerMissile1.Initialize(content);
     z_instanceOf = this;
 }
 //Constructor ----------------------------------------------------------------
 public MissleManager(Rectangle newViewPort, ContentManager content, SoundEffect sound, SpriteBatch spriteBatch, PlayerShip playerShip)
 {
     this.z_playerShip = playerShip;
     this.z_enemyManager = EnemyManager.getInstance(content, spriteBatch, newViewPort);
     this.z_FriendlyMissles = new List<MissleObject>();
     this.z_EnemyMissles = new List<MissleObject>();
     this.z_viewPort = newViewPort;
     this.z_friendlyMissleSprite1 = content.Load<Texture2D>("Content\\Images\\Missles\\Ball1");
     this.z_fireSound1 = sound;
     this.z_EnemyShipList = new List<IEnemyShip>();
     this.z_bulletPool = new BulletPool1(content, this.z_viewPort, this.z_playerShip, spriteBatch);
     this.z_enemyBulletPool1 = new EnemyBulletPool1(content, this.z_viewPort, spriteBatch);
     instanceOf = this;
 }
Exemplo n.º 3
0
        //Constructor
        public BulletPool1(ContentManager content, Rectangle viewPort, PlayerShip ship, SpriteBatch spriteBatch)
        {
            this.z_playerShip = ship;
            this.z_content = content;
            this.z_viewPort = viewPort;
            this.z_spriteBatch = spriteBatch;
            this.z_BulletPool = new List<PlayerMissile1>();
            this.z_image = z_content.Load<Texture2D>("Content\\Images\\Ball1");

            for (int i = 0; i < 100; i++)
            {
                this.z_BulletPool.Add(new PlayerMissile1(this.z_image, this.z_playerShip.Position, this.z_spriteBatch));
                this.z_BulletPool[i].IsAvailable=true;
            }
        }
Exemplo n.º 4
0
        //Main Update Method for GamePad
        public void MissleManagerUpdateFriendlyGamepad(GamePadState currentPadState, GamePadState previousPadState,
                                                        PlayerShip playerShip, SpriteBatch spriteBatch)
        {
            //For the simple collision checking
            //this.z_EnemyShipList = enemyList;
            //Same Algorithm as before, but with a gamePad controller [Fire = right Trigger]
            if (currentPadState.Triggers.Right >= .5f && previousPadState.Triggers.Right == 0 && playerShip.IsAlive)
            {
                this.z_missiles.Add(PlayerMissile1.GetNextMissile(new Vector2(playerShip.Position.X, playerShip.Top)));
            }

            //If List is not empty, update everything
            if (this.z_missiles.Count > 0)
                this.UpdateFriendlyList(spriteBatch);
        }
Exemplo n.º 5
0
        public StageManager(SpriteBatch spriteBatch, Rectangle viewPort, ContentManager content)
        {
            this.z_isGameOver = false;
            this.z_spriteBatch = spriteBatch;
            z_viewportRec = viewPort;
            this.z_contentManager = content;

            z_objects = new List<GameObject>();

            z_objects.Add(new ScrollingBackground(this.z_contentManager.Load<Texture2D>("Content\\Textures\\Starscape4")));

            //Set the starting position for player's ship
            this.z_startingPosition = new Vector2(z_viewportRec.Center.X,
                                                    z_viewportRec.Height - 80);

            //Create the player ship
            this.z_playerShip = PlayerShip.getInstance(this.z_contentManager.Load<Texture2D>("Content\\Images\\ship1"),
                                               this.z_startingPosition);

            // create the mission manager
            this.z_missionManager = new MissionManager(z_contentManager);

            //Set the player alive
            this.z_playerShip.IsAlive = true;

            //Load the Music
            this.z_MarksSong = this.z_contentManager.Load<Song>("Content\\Audio\\Music\\ATreeFalls");
            MediaPlayer.IsRepeating = true;

            //Load Fonts
            this.z_timerFont = this.z_contentManager.Load<SpriteFont>("Content\\Fonts\\TimerFont");
            this.z_livesFont = this.z_contentManager.Load<SpriteFont>("Content\\Fonts\\LivesFont");

            FloatingText.Initialize(z_contentManager, "Content\\Fonts\\TimerFont");

            //Load Achivement Stuff
            this.z_achivementFail = new GameObject(this.z_contentManager.Load<Texture2D>("Content\\Images\\AchievementFailed"));
            this.z_achivementFail.IsAlive = false;
            this.z_achivementFail.Position = new Vector2((z_viewportRec.Width / 2) - (this.z_achivementFail.Sprite.Width / 2),
                                                            z_viewportRec.Height - 100);
            this.z_achievementSound = this.z_contentManager.Load<SoundEffect>("Content\\Audio\\SoundFX\\AchievementSound");

            //Load the Settings for the MissleManager
            this.z_missleManager = new MissleManager(this.z_contentManager, this.z_spriteBatch);

            //Load the Settings for the EnemyManager
            this.z_enemyManager = EnemyManager.getInstance(this.z_contentManager, this.z_spriteBatch, z_viewportRec);
        }
        public StageManager(SpriteBatch spriteBatch, Rectangle viewPort, ContentManager content)
        {
            this.z_isGameOver = false;
            this.z_spriteBatch = spriteBatch;
            this.z_viewportRec = viewPort;
            this.z_contentManager = content;

            this.z_backgroundManager = new ScrollingBackgroundManager(this.z_viewportRec);

            this.z_backgroundManager.loadImage1(this.z_contentManager.Load<Texture2D>("Content\\Textures\\spaceBackground"));
            this.z_backgroundManager.loadImage2(this.z_contentManager.Load<Texture2D>("Content\\Textures\\spaceBackground"));

            //Set the starting position for player's ship
            this.z_startingPosition = new Vector2(this.z_viewportRec.Center.X,
                                                    this.z_viewportRec.Height - 80);

            //Create the player ship
            this.z_playerShip = PlayerShip.getInstance(this.z_contentManager.Load<Texture2D>("Content\\Images\\ship1"),
                                               this.z_startingPosition);

            //Set the player alive
            this.z_playerShip.setIsAlive(true);

            //Load the Music
            this.z_MarksSong = this.z_contentManager.Load<Song>("Content\\Audio\\Music\\ATreeFalls");
            MediaPlayer.IsRepeating = true;

            //Load Fonts
            this.z_timerFont = this.z_contentManager.Load<SpriteFont>("Content\\Fonts\\TimerFont");
            this.z_livesFont = this.z_contentManager.Load<SpriteFont>("Content\\Fonts\\LivesFont");

            //Load Achivement Stuff
            this.z_achivementFail = new GameObject(this.z_contentManager.Load<Texture2D>("Content\\Images\\AchievementFailed"));
            this.z_achivementFail.setPosition(new Vector2((this.z_viewportRec.Width / 2) - (this.z_achivementFail.getSprite().Width / 2),
                                                            this.z_viewportRec.Height - 100));
            this.z_achievementSound = this.z_contentManager.Load<SoundEffect>("Content\\Audio\\SoundFX\\AchievementSound");

            //Load the Settings for the asteroidManager
            this.z_asteroidManager = new AsteroidManager(AsteroidManager.AsteroidManagerState.Lite, this.z_viewportRec,
                                                         this.z_contentManager, this.z_spriteBatch);

            //Load the Settings for the MissleManager
            this.z_missleManager = new MissleManager(this.z_viewportRec, this.z_contentManager,
                                                     this.z_contentManager.Load<SoundEffect>("Content\\Audio\\SoundFX\\LaserPellet"), this.z_spriteBatch, this.z_playerShip);

            //Load the Settings for the EnemyManager
            this.z_enemyManager = EnemyManager.getInstance(this.z_contentManager, this.z_spriteBatch, this.z_viewportRec);
        }
Exemplo n.º 7
0
 public static PlayerShip getInstance(Texture2D loadedSprite, Vector2 startingPosition)
 {
     if (instanceOf == null)
         instanceOf = new PlayerShip(loadedSprite, startingPosition);
     return instanceOf;
 }
        //Method for Updating the asteroids
        public void updateAsteroids(PlayerShip playerShip)
        {
            foreach (Asteroid asteroid in this.z_asteroidHolder)
            {
                //If the asteroid has gone off the screen, reset it back to the top
                if (asteroid.getPosition().Y > this.z_viewPort.Height+(asteroid.getSprite().Height*1.5) ||
                    asteroid.getHasBeenHit())
                {
                    asteroid.sethasBeenHit(false);
                    //Then reset it and rerandomize it's variables
                    //Not sure if reloading a new image for each asteroid is a good idea
                    //Might cause game lag**
                    asteroid.setSprite(z_content.Load<Texture2D>
                                       ("Images\\Asteroids\\Asteroid" + this.getRandomImage()));
                    asteroid.setPosition(new Vector2(this.getRandomWidth(), this.getRandomHeight()));
                    asteroid.setSpeed(this.getRandomSpeed());
                    //Because The rotation is perfectly centered, asteroids that move slow look really
                    //Off balance. So instead I'm temporarily scaling rotation speed with the asteroids traveling speed
                    //asteroid.setRotationSpeed(this.getRandomRotationSpeed());
                    asteroid.setRotationSpeed((asteroid.getSpeed() / 50)*this.getRandomRotationDirection());
                    asteroid.setIsAlive(true);
                }

                //If an asteroid has hit the player, then do something
                if (asteroid.getHitRec().Intersects(playerShip.getHitRec()))
                {
                    asteroid.sethasBeenHit(true);
                    playerShip.setHealth(0);
                }

                //Otherwise Update it's new position
                asteroid.AstroUpdate();

            }
        }
Exemplo n.º 9
0
        //Accessors
        //Mutators
        // This function initializes the internal pool and loads in the image to use to create all the
        // 'Enemy1' type ships. It also creates a few bullets in the pool for fast retrieval.
        public static void Initialize(ContentManager content, Rectangle viewport)
        {
            zs_pool = new List<EnemySimpleBullet>();
            zs_sound = content.Load<SoundEffect>("Content\\Audio\\SoundFX\\LaserPellet");
            zs_image = content.Load<Texture2D>("Content\\Images\\Missiles\\EnemyBulletRed");
            zs_playerShip = PlayerShip.getInstance();
            zs_viewport = viewport;

            for (int i = 0; i < 50; i++)
            {
                zs_pool.Add(new EnemySimpleBullet());
            }
        }
Exemplo n.º 10
0
        //Mutator Methods ------------------------------------------------------------
        //Update and Draw Methods --------------------------------------------------------------
        //Main Update Method for Keyboard
        public void MissleManagerUpdateFriendlyKeyboard(KeyboardState currentKeyState, KeyboardState previousKeyState,
                                                        PlayerShip playerShip, SpriteBatch spriteBatch)
        {
            //The Alogrithm:
            //Determine if the player shot a missle
            //If so then add it the List
            //If the list is not empty, update each missle
            //While checking each missle, make sure it hasn't left the screen or collided with something
            //If so, remove it from the list

            if (currentKeyState.IsKeyDown(Keys.Space) && previousKeyState.IsKeyUp(Keys.Space) && playerShip.IsAlive)
            {
                //Create and add a new Missle Object
                this.z_missiles.Add(PlayerMissile1.GetNextMissile(new Vector2(playerShip.Position.X, playerShip.Top)));
            }

            //If List is not empty, update everything
            if (this.z_missiles.Count > 0)
                this.UpdateFriendlyList(spriteBatch);
        }
        //Update and Draw Methods --------------------------------------------------------------
        //Main Update Method for Keyboard
        public void MissleManagerUpdateFriendlyKeyboard(KeyboardState currentKeyState, KeyboardState previousKeyState,
                                                        PlayerShip playerShip, SpriteBatch spriteBatch)
        {
            this.z_EnemyShipList = this.z_enemyManager.getEnemiesList();
            //The Alogrithm:
            //Determine if the player shot a missle
            //If so then add it the List
            //If the list is not empty, update each missle
            //While checking each missle, make sure it hasn't left the screen or collided with something
            //If so, remove it from the list

            if (currentKeyState.IsKeyDown(Keys.Space) && previousKeyState.IsKeyUp(Keys.Space) && playerShip.getIsAlive())
            {
                //Play a fire sound
                this.z_fireSound1.Play(.2f, 0, 0);

                //Create and add a new Missle Object
                this.z_FriendlyMissles.Add(this.z_bulletPool.getNextAvailableEnemy());
                /*
                this.z_FriendlyMissles.Add(new PlayerMissle1(this.z_friendlyMissleSprite1,
                                                             new Vector2(playerShip.getPosition().X
                                                                         + playerShip.getSprite().Width / 2
                                                                         - this.z_friendlyMissleSprite1.Width / 2,
                                                                 playerShip.getPosition().Y), spriteBatch));
                 * */
            }

            this.MissleManagerUpdateEnemy();

            //If List is empty, nothing to update, exit this update function
            if (this.z_FriendlyMissles.Count <= 0)
                return;

            this.UpdateFriendlyList();
        }
        //Main Update Method for GamePad
        public void MissleManagerUpdateFriendlyGamepad(GamePadState currentPadState, GamePadState previousPadState,
                                                        PlayerShip playerShip, SpriteBatch spriteBatch)
        {
            //For the simple collision checking
            //this.z_EnemyShipList = enemyList;
            //Same Algorithm as before, but with a gamePad controller [Fire = right Trigger]
            if (currentPadState.Triggers.Right >= .5f && previousPadState.Triggers.Right == 0 && playerShip.getIsAlive())
            {
                this.z_FriendlyMissles.Add(new PlayerMissle1(this.z_friendlyMissleSprite1,
                                                             new Vector2(playerShip.getPosition().X
                                                                         + playerShip.getSprite().Width / 2
                                                                         - this.z_friendlyMissleSprite1.Width / 2,
                                                                 playerShip.getPosition().Y), spriteBatch));

                //Play a fire sound
                this.z_fireSound1.Play(.2f, 0, 0);
            }

            this.MissleManagerUpdateEnemy();
            //If List is empty, nothing to update, exit this update function
            if (this.z_FriendlyMissles.Count <= 0)
                return;

            this.UpdateFriendlyList();
        }