Example #1
0
        public static Ship ActivateShip(bool isCollisionBoxActive)
        {
            ShipManager shipMan = ShipManager.GetInstance();

            PCSTree pcsTree = GameObjectManager.GetRootTree();

            Debug.Assert(pcsTree != null);

            Ship pShip = new Ship(GameObjectName.Ship, SpriteBaseName.Ship, 150.0f, 100.0f);

            shipMan.pShip = pShip;

            SpriteBatch sbAliens = SpriteBatchManager.Find(SpriteBatchName.Aliens);
            SpriteBatch sbBoxes  = SpriteBatchManager.Find(SpriteBatchName.Boxes);

            if (isCollisionBoxActive)
            {
                pShip.ActivateCollisionSprite(sbBoxes);
            }
            pShip.ActivateGameSprite(sbAliens);
            //sbAliens.Attach(pShip.pProxySprite);

            GameObject pShipRoot = GameObjectManager.Find(GameObjectName.ShipRoot);

            Debug.Assert(pShipRoot != null);
            pShip.Update();
            pcsTree.Insert(shipMan.pShip, pShipRoot);
            return(shipMan.pShip);
        }
Example #2
0
        public static void MoveShip(float x, float y)
        {
            Ship pShip = GetShip();

            pShip.x = x;
            pShip.y = y;
            pShip.Update();
        }
Example #3
0
        public void Update(CanvasBitmap alienImage, CanvasBitmap shipImage, CanvasBitmap laserImage)//CanvasDrawingSession image)//
        {
            if (gameOver == false)
            {
                if (MoveShipLeft(ship.MoveLeft) == true || MoveShipRight(ship.MoveRight) == true)
                {
                    ship.Update();
                }

                alien.Update();

                drawables.Add(ship);
                for (int i = 0; i < 10; i++)
                {
                    drawables.Add(AlienList[i]);
                }
                if (Gamepad.Gamepads.Count > 0)
                {
                    controller = Gamepad.Gamepads.First();
                    var reading = controller.GetCurrentReading();
                    if (reading.Buttons.HasFlag(GamepadButtons.A))
                    {
                        lasers.ShootLaser(laserImage, ship);
                        lasers.Update(laserImage);
                        lasers = new Lasers(lasers.X, lasers.Y, laserImage);
                        drawables.Add(lasers);
                    }
                }
                Collide(lasers, AlienList);

                gameOver = HitAll(AlienList); //if gameOver turns true, should quit

                if (gameOver == false)
                {
                    int lastAlienToTouch = 0;
                    for (int index = 1; index <= 10; index++)
                    {
                        if (AlienList[index - 1].GotHit == false && AlienList[index - 1].Y == 400)
                        {
                            lastAlienToTouch = index - 1;

                            if (score.LivesLeft == 0)
                            {
                                gameOver = true;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        public static void GetNextShip()
        {
            //get the instance of the ship manager;
            ShipManager pShipMan = ShipManager.privInstance();

            Debug.Assert(pShipMan != null);

            Ship nextShip = null;

            //if there's another ship, get and prepare it
            if (pShipMan.privHasAnotherShip())
            {
                nextShip = (Ship)pShipMan.pCurrentShip.pChild;
                Debug.Assert(nextShip != null);

                //set the coordinates to starting position
                nextShip.x = pShipMan.startShip_PosX;
                nextShip.y = pShipMan.startShip_PosY;
                nextShip.SetState(State.Ready);
                //update the positioning;
                nextShip.pProxySprite.Update();
                nextShip.Update();

                //remove rendering of current ship (off screen);
                //todo FIX THIS - Cheap Hack to just render the old ships WAYY off screen!
                pShipMan.pCurrentShip.x = -1000.0f;
                pShipMan.pCurrentShip.y = -1000.0f;
                pShipMan.pCurrentShip.SetState(State.End);
                pShipMan.pCurrentShip.pProxySprite.Update();

                ////define an override remove inside of Ship class
                //pShipMan.pCurrentShip.Remove();

                pShipMan.pCurrentShip = nextShip;
                pShipMan.pCurrentShip.Update();

                Debug.Assert(pShipMan.pCurrentShip != null);

                //remove the current ship;
            }

            //return nextShip;
        }
Example #5
0
        protected override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            _scrollingBackground.Update(elapsed * 100);

            if (_gameOver && !_playGameOver)
            {
                _upgrade.GameOver            = true;
                _ship.GameOver               = true;
                _spaceInvadersBoard.GameOver = true;
                _playGameOver = true;
            }

            if (_playGameOver && _play)
            {
                AssetsManager.GameOver.Play();
                _playGameOver = false;
                _play         = false;
            }
            else if (_playYouWin && _play)
            {
                AssetsManager.YouWin.Play();
                _playYouWin = false;
                _play       = false;
            }

            if (_spaceInvadersBoard.SpaceInvaderList.Count <= 0)
            {
                _playYouWin = true;
            }

            _spaceInvadersBoard.Update(gameTime);
            _ship.Update(gameTime);
            _upgrade.Update(gameTime);

            foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList)
            {
                SpaceInvader.UpdateShipPosition(_ship.ShipPosition);

                //Invader hits ship
                if (SpaceInvader.HasWeapon)
                {
                    foreach (InvaderBullet Bullet in SpaceInvader.InvaderWeapon.Bullets)
                    {
                        if (CheckCollision(Bullet, _ship))
                        {
                            Bullet.Hit = true;
                            _ship.Lives--;
                        }
                    }
                }

                //Game Over
                if (CheckCollision(_ship, SpaceInvader) || _ship.Lives <= 0)
                {
                    _gameOver = true;
                }
            }

            for (int i = 0; i < _upgrade.LaserUpgrades.Count; i++)
            {
                if (CheckCollision(_upgrade.LaserUpgrades[i], _ship))
                {
                    _ship.Weapon.WeaponState = WeaponState.Laser;
                    AssetsManager.UpgradeSoundEffect.Play();
                    _upgrade.LaserUpgrades[i].DisposeFromList();
                    _upgrade.LaserUpgrades.RemoveAt(i);
                }
            }

            for (int i = 0; i < _upgrade.RocketUpgrades.Count; i++)
            {
                if (CheckCollision(_upgrade.RocketUpgrades[i], _ship))
                {
                    _ship.Weapon.WeaponState = WeaponState.Rocket;
                    AssetsManager.UpgradeSoundEffect.Play();
                    _upgrade.RocketUpgrades[i].DisposeFromList();
                    _upgrade.RocketUpgrades.RemoveAt(i);
                }
            }

            if (_ship.Weapon.WeaponState == WeaponState.Normal)
            {
                foreach (NormalBullet Bullet in _ship.Weapon.NormalWeapon.Bullets)
                {
                    foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList)
                    {
                        if (CheckCollision(Bullet, SpaceInvader))
                        {
                            SpaceInvader.Hit = true;
                            Bullet.Hit       = true;
                        }
                    }
                }
            }
            else if (_ship.Weapon.WeaponState == WeaponState.Rocket)
            {
                foreach (RocketBullet Bullet in _ship.Weapon.RocketWeapon.Bullets)
                {
                    foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList)
                    {
                        if (CheckCollision(Bullet, SpaceInvader))
                        {
                            SpaceInvader.Hit = true;
                            Bullet.Hit       = true;
                        }
                    }
                }
            }
            else if (_ship.Weapon.WeaponState == WeaponState.Laser)
            {
                foreach (LaserBullet Bullet in _ship.Weapon.LaserWeapon.Bullets)
                {
                    foreach (SpaceInvaderObject SpaceInvader in _spaceInvadersBoard.SpaceInvaderList)
                    {
                        if (CheckCollision(Bullet, SpaceInvader))
                        {
                            SpaceInvader.Hit = true;
                            Bullet.Hit       = true;
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
Example #6
0
        private static Ship CreateShips()
        {
            ShipManager pShipMan = ShipManager.privInstance();

            Debug.Assert(pShipMan != null);

            // get the game object tree
            PCSTree rootGamObjTree = GameObjectManager.GetRootTree();

            Debug.Assert(rootGamObjTree != null);

            //create the root - coordinates are 0 since it's a root
            //ShipRoot pShipRoot = new ShipRoot(GameObject.Name.ShipRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);
            //DeathManager.Attach(shipRoot);

            //todo find the ship object from loading instead of creating a new one
            // copy over safe copy (new or find precreated game object)

            //todo - refactor this using object pooling for ships - also will need more than these 3 ships w/ two player!
            //Create 3 ships total-----------------

            //create the starting ship;
            Ship pShip = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 0, pShipMan.startShip_PosX, pShipMan.startShip_PosY);

            //set as the ship managers current ship
            pShipMan.pCurrentShip = pShip;

            // Attach the sprite to the correct sprite batch
            SpriteBatch pSB_GameSprites = SpriteBatchManager.Find(SpriteBatch.Name.GameSprites);
            SpriteBatch pSB_Boxes       = SpriteBatchManager.Find(SpriteBatch.Name.SpriteBoxes);

            pSB_GameSprites.Attach(pShip.pProxySprite);
            pShip.ActivateCollisionSprite(pSB_Boxes);


            // Attach the ship to the ship root
            // get the root (created before this function was called)
            GameObject pShipRoot = GameObjectManager.Find(GameObject.Name.ShipRoot);

            Debug.Assert(pShipRoot != null);

            // Add current ship tree to GameObject Tree - {update and collisions}
            rootGamObjTree.Insert(pShipMan.pCurrentShip, pShipRoot);

            //TESTING - CREATING 2 EXTRA SHIPS-------------------------------------------

            //extra ship one
            Ship pShipOne = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 1, pShipMan.extraShipOne_X, pShipMan.extraShip_Y);

            //add to the ship tree as well as root game object tree
            rootGamObjTree.Insert(pShipOne, pShipMan.pCurrentShip);

            // Attach the sprite to the correct sprite batch

            pSB_GameSprites.Attach(pShipOne.pProxySprite);
            pShipOne.ActivateGameSprite(pSB_GameSprites);
            pShipOne.ActivateCollisionSprite(pSB_Boxes);

            //update the position of the new ship
            pShipOne.Update();

            //extra ship two
            Ship pShipTwo = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 2, pShipMan.extraShipTwo_X, pShipMan.extraShip_Y);


            //add to the ship tree as well as root game object tree
            rootGamObjTree.Insert(pShipTwo, pShipOne);

            // Attach the sprite to the correct sprite batch
            pSB_GameSprites.Attach(pShipTwo.pProxySprite.pSprite);
            pShipTwo.ActivateGameSprite(pSB_GameSprites);
            pShipTwo.ActivateCollisionSprite(pSB_Boxes);

            //update the position of the new ship
            pShipTwo.Update();

            //END TESTING OF CREATING 2 EXTRA SHIPS-------------------------------------------


            //attach the shipRoot tree to the root game object tree
            //GameObjectManager.AttachTree(pShipRoot, rootGamObjTree);
            GameObjectManager.AttachTree(pShipRoot);

            return(pShipMan.pCurrentShip);
        }