示例#1
0
        /// <summary>
        /// Adds points to the score.
        /// </summary>
        /// <param name="objectDestroyed">The object destroyed.</param>
        /// <param name="doublePoints">if set to <c>true</c> [double points].</param>
        public void AddPoints(GameObject objectDestroyed, bool doublePoints)
        {
            int pointsToAdd = 0;

            if (objectDestroyed.ObjectType == GameObject.GAME_OBJECT_TYPE.ASTEROID)
            {
                Asteroid analysedAsteroid = (Asteroid) objectDestroyed;
                if (analysedAsteroid.currentSize == Asteroid.Size.LARGE) pointsToAdd = POINTS_FOR_LARGE_ASTEROID;
                if (analysedAsteroid.currentSize == Asteroid.Size.MEDIUM) pointsToAdd = POINTS_FOR_MEDIUM_ASTEROID;
                if (analysedAsteroid.currentSize == Asteroid.Size.SMALL) pointsToAdd = POINTS_FOR_SMALL_ASTEROID;
            }
            if (objectDestroyed.ObjectType == GameObject.GAME_OBJECT_TYPE.ENEMY_SHIP)
            {
                EnemyShip analysedShip = (EnemyShip)objectDestroyed;
                if (analysedShip.ShipType == EnemyShip.ENEMY_SHIP_TYPE.SMALL) pointsToAdd = POINTS_FOR_SMALL_SHIP;
                if (analysedShip.ShipType == EnemyShip.ENEMY_SHIP_TYPE.BIG) pointsToAdd = POINTS_FOR_BIG_ENEMY_SHIP;
                if (analysedShip.ShipType == EnemyShip.ENEMY_SHIP_TYPE.CARRIER) pointsToAdd = POINTS_FOR_CARRIER;
            }

            if (doublePoints) pointsToAdd *= X2;

            if (currentScore / LIFE_GAIN_POINTS_INTERVAL < (currentScore + pointsToAdd) / LIFE_GAIN_POINTS_INTERVAL)
            {
                Player.GetInstance().NbOfCurrentLives++;
            }
            currentScore += pointsToAdd;
        }
示例#2
0
 /// <summary>
 /// Called when a collision occurs in other to make a certain event occure.
 /// </summary>
 /// <param name="elapsedGameTime">The elapsed game time.</param>
 /// <param name="hitter">The hitter.</param>
 /// <param name="overseeingGame">The overseeing game.</param>
 public virtual void OnHit(TimeSpan elapsedGameTime, GameObject hitter, MajorLeagueGamingAsteroids overseeingGame)
 {
 }
示例#3
0
        /// <summary>
        /// Called when a collision occurs in other to make a certain event occurs. 
        /// </summary>
        /// <param name="elapsedGameTime">The elapsed game time.</param>
        /// <param name="hitter">The hitter.</param>
        /// <param name="overseeingGame">The overseeing game.</param>
        public override void OnHit(TimeSpan elapsedGameTime, GameObject hitter, MajorLeagueGamingAsteroids overseeingGame)
        {
            if (lastDeathTime == null || elapsedGameTime - lastDeathTime >= INVINCIBILITY_FROM_RESPAWN)
            {
                nbOfCurrentLives--;
                if (nbOfCurrentLives == 0) Alive = false;
                lastDeathTime = elapsedGameTime;

                rotationAngle = 0;
                movementVector = Vector2.Zero;
                base.Initialize(this.image, new Vector2(MajorLeagueGamingAsteroids.SCREENWIDTH / 2, MajorLeagueGamingAsteroids.SCREENHEIGHT / 2));
            }
        }
示例#4
0
        /// <summary>
        /// Called when a collision occurs in other to make a certain event occure.
        /// </summary>
        /// <param name="elapsedGameTime">The elapsed game time.</param>
        /// <param name="hitter">The hitter.</param>
        /// <param name="overseeingGame">The overseeing game.</param>
        public override void OnHit(TimeSpan elapsedGameTime, GameObject hitter, MajorLeagueGamingAsteroids overseeingGame)
        {
            if (hitter.ObjectType == GAME_OBJECT_TYPE.ASTEROID && CanMerge(elapsedGameTime)) //If it's destroyed as a merge
            {
                if (!((Asteroid)hitter).hasMerged)
                {
                    float direction = (hitter.RotationAngle + rotationAngle) / 2;
                    Asteroid mergedRoid = new Asteroid(direction, elapsedGameTime, (Size)((int)currentSize + 1));
                    mergedRoid.Initialize(overseeingGame.GetTexture((MajorLeagueGamingAsteroids.TextureType)((int)currentSize + 1)), position);
                    overseeingGame.AddGameObject(mergedRoid);
                    mergedRoid.movementVector = new Vector2((movementVector.X + hitter.MovementVector.X) / 2, (movementVector.Y + hitter.MovementVector.Y) / 2);
                    hasMerged = true;
                }
            }
            else if (currentSize != Size.SMALL) //If destroyed and should split
            {
                Vector2 resultingDirectionVector = new Vector2((movementVector.X + hitter.MovementVector.X) / 2, (movementVector.Y + hitter.MovementVector.Y) / 2);
                float createdSpeed = (float)Math.Sqrt(resultingDirectionVector.X * resultingDirectionVector.X + resultingDirectionVector.Y * resultingDirectionVector.Y);
                float resultingDirection = GetAngleFromVector(resultingDirectionVector);

                Asteroid spawnling = new Asteroid(resultingDirection + (float)(Math.PI)/3, elapsedGameTime, (Size)((int)currentSize - 1));
                spawnling.Initialize(overseeingGame.GetTexture((MajorLeagueGamingAsteroids.TextureType)((int)currentSize - 1)), position);
                overseeingGame.AddGameObject(spawnling);
                spawnling.movementVector = new Vector2(0, 0);
                spawnling.AccelerateObject(createdSpeed);

                spawnling = new Asteroid(resultingDirection - (float)(Math.PI)/3, elapsedGameTime, (Size)((int)currentSize - 1));
                spawnling.Initialize(overseeingGame.GetTexture((MajorLeagueGamingAsteroids.TextureType)((int)currentSize - 1)), position);
                overseeingGame.AddGameObject(spawnling);
                spawnling.movementVector = new Vector2(0, 0);
                spawnling.AccelerateObject(createdSpeed);
            }
        }
示例#5
0
 /// <summary>
 /// Called when [hit] in order to give the player a extra life. We did not used the notify method because
 /// it is simpler to directly access the player via its singleton instance than to notify the manager.
 /// We tried to the notify method and all it did was adding way to many lives by power ups.
 /// </summary>
 /// <param name="elapsedGameTime">The elapsed game time.</param>
 /// <param name="hitter">The hitter.</param>
 /// <param name="overseeingGame">The overseeing game.</param>
 public override void OnHit(TimeSpan elapsedGameTime, GameObject hitter,
     MajorLeagueGamingAsteroids overseeingGame)
 {
     Player.GetInstance().NbOfCurrentLives++;
 }
 /// <summary>
 /// Adds the game object to the list of object that will be created. We use this function to avoid causing problems with a foreach loop.
 /// </summary>
 /// <param name="newObject">The new object.</param>
 public void AddGameObject(GameObject newObject)
 {
     objectsToCreate.Add(newObject);
 }