/// <summary> /// This class is used to in order to make the ship shoot at the player. /// We know it is a very general name but it is implemented in other classes and is used /// in differents way. /// It is only named that way in order to be reusable and to lower the number of function that activates /// a action. /// </summary> /// <param name="elapsedGameTime">The elapsed game time.</param> /// <param name="overSeeingGame">The over seeing game.</param> public override void DoAction(TimeSpan elapsedGameTime, MajorLeagueGamingAsteroids overSeeingGame) { if (elapsedGameTime - lastProjectileLaunch >= LASER_DELAY) { ShootProjectile(elapsedGameTime, overSeeingGame); } }
/// <summary> /// Creates a big laser power ups. /// </summary> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>PowerUp.</returns> private static PowerUp CreateBigLasers(MajorLeagueGamingAsteroids overSeeingGame) { BigLaser slowMo = new BigLaser(); Vector2 spawnLocation = overSeeingGame.GetValidEnemySpawnLocation(); slowMo.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.BIG_LASERS_POWER_UP), spawnLocation); return slowMo; }
/// <summary> /// Creates a double points power up. /// </summary> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>PowerUp.</returns> private static PowerUp CreateDoublePoints(MajorLeagueGamingAsteroids overSeeingGame) { DoublePoints dp = new DoublePoints(); Vector2 spawnLocation = overSeeingGame.GetValidEnemySpawnLocation(); dp.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.X2), spawnLocation); return dp; }
/// <summary> /// Creates the power up using a already determined type. /// </summary> /// <param name="type">The type.</param> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>PowerUp.</returns> public static PowerUp CreatePowerUP(PowerUp.POWER_UP_TYPE type, MajorLeagueGamingAsteroids overSeeingGame) { PowerUp createdPowerUp; switch (type) { case PowerUp.POWER_UP_TYPE.EXTRA_LIFE: createdPowerUp = CreateExtraLife(overSeeingGame); break; case PowerUp.POWER_UP_TYPE.DOUBLE_POINTS: createdPowerUp = CreateDoublePoints(overSeeingGame); break; case PowerUp.POWER_UP_TYPE.SLOW_MO: createdPowerUp = CreateSlowMo(overSeeingGame); break; case PowerUp.POWER_UP_TYPE.BIG_LASER: createdPowerUp = CreateBigLasers(overSeeingGame); break; case PowerUp.POWER_UP_TYPE.SHOOT_FASTER: createdPowerUp = CreateShootFaster(overSeeingGame); break; default: createdPowerUp = CreateExtraLife(overSeeingGame); break; } return createdPowerUp; }
/// <summary> /// Creates the ship using a already determined type. /// </summary> /// <param name="type">The type.</param> /// <param name="spawnLocation">The spawn location.</param> /// <param name="overSeeingGame">The over seeing game.</param> /// <param name="startingAngle">The starting angle.</param> /// <returns>EnemyShip.</returns> public static EnemyShip CreateShip(EnemyShip.ENEMY_SHIP_TYPE type, Vector2 spawnLocation, MajorLeagueGamingAsteroids overSeeingGame, float startingAngle = Ship.HORIZONTAL_MOVEMENT_ANGLE) { EnemyShip createdShip; switch (type) { case EnemyShip.ENEMY_SHIP_TYPE.BIG: createdShip = CreateBigShip(startingAngle, spawnLocation, overSeeingGame); break; case EnemyShip.ENEMY_SHIP_TYPE.CARRIER: createdShip = CreateCarrierShip(startingAngle, spawnLocation, overSeeingGame); break; default: createdShip = CreateSmallShip(startingAngle, spawnLocation, overSeeingGame); break; } return createdShip; }
/// <summary> /// Finds out if a laser can be shot. If so, a new laser object is created and is shot. /// </summary> /// <param name="elapsedGameTime">The elapsed game time.</param> /// <param name="overSeeingGame">The over seeing game.</param> public abstract void ShootProjectile(TimeSpan elapsedGameTime, MajorLeagueGamingAsteroids overSeeingGame);
/// <summary> /// Finds out if a small ship can be shot. If so, a new small ship object is created and is shot. /// </summary> /// <param name="elapsedGameTime">The elapsed game time.</param> /// <param name="overSeeingGame">The over seeing game.</param> public override void ShootProjectile(TimeSpan elapsedGameTime, MajorLeagueGamingAsteroids overSeeingGame) { Vector2 launchedShipPos = new Vector2(position.X, position.Y); launchedShipPos.Y += 30; GameObject launchedShip = ShipFactory.CreateShip(ENEMY_SHIP_TYPE.SMALL, launchedShipPos, overSeeingGame, rotationAngle); overSeeingGame.AddGameObject(launchedShip); launchedShipPos = new Vector2(position.X, position.Y); launchedShipPos.Y -= 30; launchedShip = ShipFactory.CreateShip(ENEMY_SHIP_TYPE.SMALL, launchedShipPos, overSeeingGame, rotationAngle); overSeeingGame.AddGameObject(launchedShip); lastProjectileLaunch = elapsedGameTime; }
/// <summary> /// Finds out if a laser can be shot. If so, a new laser object is created and is shot. /// </summary> /// <param name="elapsedGameTime">The elapsed game time.</param> /// <param name="overSeeingGame">The over seeing game.</param> public override void ShootProjectile(TimeSpan elapsedGameTime, MajorLeagueGamingAsteroids overSeeingGame) { TimeSpan delayToUse; if (fastFire) { delayToUse = LASER_DELAY_FAST_FIRE; if (SHOOTING_MODIFIER_DURATION < elapsedGameTime - lastFastFireActivated) fastFire = false; } else { delayToUse = LASER_DELAY_STANDARD; } if (SHOOTING_MODIFIER_DURATION < elapsedGameTime - lastBigLaserActivated) shootBigLasers = false; if (lastLaserShot == null || elapsedGameTime - lastLaserShot >= delayToUse) { Lasers newLaser = new Lasers(); if (shootBigLasers) newLaser.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.BIG_LASERS), Position); else newLaser.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.FRIENDLY_LASER), Position); newLaser.RotationAngle = this.RotationAngle; newLaser.AccelerateObject(Lasers.LASER_SPEED); newLaser.ObjectType = GAME_OBJECT_TYPE.FRIENDLY_LASER; lastLaserShot = elapsedGameTime; overSeeingGame.AddGameObject(newLaser); overSeeingGame.soundEffect.Play(); } }
/// <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)); } }
/// <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); } }
/// <summary> /// Creates a small ship. /// </summary> /// <param name="startingAngle">The starting angle.</param> /// <param name="spawnLocation">The spawn location.</param> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>EnemyShip.</returns> private static EnemyShip CreateSmallShip(float startingAngle, Vector2 spawnLocation, MajorLeagueGamingAsteroids overSeeingGame) { SmallEnemyShip smallShip = new SmallEnemyShip(startingAngle); smallShip.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.ENEMY_SHIP_SMALL), spawnLocation); return smallShip; }
/// <summary> /// Creates a slow mo power up. /// </summary> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>PowerUp.</returns> private static PowerUp CreateSlowMo(MajorLeagueGamingAsteroids overSeeingGame) { SlowMo slowMo = new SlowMo(); Vector2 spawnLocation = overSeeingGame.GetValidEnemySpawnLocation(); slowMo.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.SLOW_MO), spawnLocation); return slowMo; }
/// <summary> /// Creates a shoot faster power ups. /// </summary> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>PowerUp.</returns> private static PowerUp CreateShootFaster(MajorLeagueGamingAsteroids overSeeingGame) { ShootFaster slowMo = new ShootFaster(); Vector2 spawnLocation = overSeeingGame.GetValidEnemySpawnLocation(); slowMo.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.SHOOT_FAST), spawnLocation); return slowMo; }
/// <summary> /// Creates a big ship. /// </summary> /// <param name="startingAngle">The starting angle.</param> /// <param name="spawnLocation">The spawn location.</param> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>EnemyShip.</returns> private static EnemyShip CreateBigShip(float startingAngle, Vector2 spawnLocation, MajorLeagueGamingAsteroids overSeeingGame) { BigEnemyShip bigShip = new BigEnemyShip(startingAngle); bigShip.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.ENEMY_SHIP_BIG), spawnLocation); return bigShip; }
/// <summary> /// We know it is a very general name but it is implemented in other classes and is used /// in differents way. /// It is only named that way in order to be reusable and to lower the number of function that activates /// a action that does not depend on the event of a collision. /// </summary> /// <param name="elapsedGameTime">The elapsed game time.</param> /// <param name="overSeeingGame">The over seeing game.</param> public virtual void DoAction(TimeSpan elapsedGameTime, MajorLeagueGamingAsteroids overSeeingGame) { }
/// <summary> /// Creates a extra life power up. /// </summary> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>PowerUp.</returns> private static PowerUp CreateExtraLife(MajorLeagueGamingAsteroids overSeeingGame) { ExtraLife extraLife = new ExtraLife(); Vector2 spawnLocation = overSeeingGame.GetValidEnemySpawnLocation(); extraLife.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.EXTRA_LIFE), spawnLocation); return extraLife; }
/// <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) { }
/// <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> /// Finds out if a laser can be shot. If so, a new laser object is created and is shot. /// </summary> /// <param name="elapsedGameTime">The elapsed game time.</param> /// <param name="overSeeingGame">The over seeing game.</param> public override void ShootProjectile(TimeSpan elapsedGameTime, MajorLeagueGamingAsteroids overSeeingGame) { Lasers newLaser = new Lasers(); newLaser.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.UNFRIENDLY_LASER), Position); newLaser.RotationAngle = CalculateAngleToPlayer(); if (RandomManager.RandomTrueFalse()) { newLaser.RotationAngle += RandomManager.RandomAngleFromZeroToMany(MAXIMUM_INACCURACY); } else { newLaser.RotationAngle -= RandomManager.RandomAngleFromZeroToMany(MAXIMUM_INACCURACY); } newLaser.AccelerateObject(Lasers.LASER_SPEED); newLaser.ObjectType = GAME_OBJECT_TYPE.UNFRIENDLY_LASER; lastProjectileLaunch = elapsedGameTime; overSeeingGame.AddGameObject(newLaser); }
/// <summary> /// Creates a carrier ship. /// </summary> /// <param name="startingAngle">The starting angle.</param> /// <param name="spawnLocation">The spawn location.</param> /// <param name="overSeeingGame">The over seeing game.</param> /// <returns>EnemyShip.</returns> private static EnemyShip CreateCarrierShip(float startingAngle, Vector2 spawnLocation, MajorLeagueGamingAsteroids overSeeingGame) { CarrierEnemyShip carrierShip = new CarrierEnemyShip(startingAngle); carrierShip.Initialize(overSeeingGame.GetTexture(MajorLeagueGamingAsteroids.TextureType.ENEMY_SHIP_CARRIER), spawnLocation); return carrierShip; }