/// <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> /// 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> /// 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> /// 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); } }