public static List<GameObject> getAllObstacle(GameObject observer, Fish[] fishes, int fishAmount, BaseEnemy[] enemies, int enemyAmount, HydroBot bot, List<GameObject> exclude) { List<GameObject> obstacles = new List<GameObject>(); if (observer != bot) { obstacles.Add(bot); } for (int i = 0; i < enemyAmount; i++) { if (observer != enemies[i]) { obstacles.Add(enemies[i]); } } for (int i = 0; i < fishAmount; i++) { if (observer != fishes[i]) { obstacles.Add(fishes[i]); } } for (int i = 0; i < obstacles.Count; i++) { for (int j = 0; j < exclude.Count; j++) { if (obstacles[i] == exclude[j]) { obstacles.RemoveAt(i); } } } return obstacles; }
public static bool BotOverResearchFacility(HydroBot hydroBot, ResearchFacility researchFacility) { if (researchFacility == null) return false; if (hydroBot.BoundingSphere.Intersects(researchFacility.BoundingSphere)) { return true; } return false; }
public static Factory BotOverWhichFactory(HydroBot hydroBot, List<Factory> factories) { if (factories == null) return null; //BoundingSphere shipRealSphere; foreach (Factory factory in factories) { if (hydroBot.BoundingSphere.Intersects(factory.BoundingSphere)) { return factory; } } //cursor.SetNormalMouseImage(); return null; }
public static Vector3 calculatePlacingPosition(float radius, HydroBot bot, BaseEnemy[] enemies, int enemiesAmount, Fish[] fish, int fishAmount) { Random random = new Random(); BoundingSphere newSphere = new BoundingSphere(new Vector3(), radius); float X, Y = bot.Position.Y, Z; do { X = (float)random.NextDouble() * (2 * bot.Position.X + 50) - bot.Position.X - 25f; //X = bot.Position.X + (float)random.NextDouble() * 50f; Z = (float)random.NextDouble() * (2 * bot.Position.Z + 50) - bot.Position.Z - 25f; newSphere.Center = new Vector3(X, Y, Z); } while (IsSurfaceOccupied(newSphere, enemiesAmount, fishAmount, enemies, fish) || newSphere.Intersects(bot.BoundingSphere)); return new Vector3(X, Y, Z); }
public static ShipWreck BotOverWhichShipWreck(HydroBot hydroBot, List<ShipWreck> shipWrecks) { if (shipWrecks == null) return null; //BoundingSphere shipRealSphere; foreach (ShipWreck shipWreck in shipWrecks) { if (hydroBot.BoundingSphere.Intersects(shipWreck.BoundingSphere)) { return shipWreck; } } //cursor.SetNormalMouseImage(); return null; }
public static TreasureChest BotOverWhichChest(HydroBot hydroBot, List<TreasureChest> chests) { if (chests == null) return null; //BoundingSphere shipRealSphere; foreach (TreasureChest treasureChest in chests) { if (hydroBot.BoundingSphere.Intersects(treasureChest.BoundingSphere)) { return treasureChest; } } //cursor.SetNormalMouseImage(); return null; }
public static bool InShootingRange(HydroBot hydroBot, Cursor cursor, Camera gameCamera, float planeHeight) { Vector3 pointIntersect = IntersectPointWithPlane(cursor, gameCamera, planeHeight); Vector3 mouseDif = pointIntersect - hydroBot.Position; float distanceFromTank = mouseDif.Length(); if (distanceFromTank < GameConstants.BotShootingRange) return true; else return false; }
public virtual void Update(GameTime gameTime, BoundingFrustum cameraFrustum, SwimmingObject[] enemies, int enemiesSize, SwimmingObject[] fish, int fishSize, int changeDirection, HydroBot tank, List<DamageBullet> enemyBullet) { float lastForwardDir = ForwardDirection; float lastTurnAmount = turnAmount; EffectHelpers.GetEffectConfiguration(ref fogColor, ref ambientColor, ref diffuseColor, ref specularColor); if (isPoissoned == true) { if (accumulatedHealthLossFromPoison < maxHPLossFromPoisson) { health -= 0.1f; accumulatedHealthLossFromPoison += 0.1f; } else { isPoissoned = false; accumulatedHealthLossFromPoison = 0; } } Vector3 futurePosition = Position; //int barrier_move Random random = new Random(); //also try to change direction if we are stuck int rightLeft = random.Next(2); turnAmount = 0; if (stucked == true) { //ForwardDirection += MathHelper.PiOver4/2; if (lastTurnAmount == 0) { if (rightLeft == 0) turnAmount = 5; else turnAmount = -5; } else turnAmount = lastTurnAmount; } else if (changeDirection >= 99) { if (rightLeft == 0) turnAmount = 5; else turnAmount = -5; } float prevForwardDir = ForwardDirection; Vector3 prevFuturePosition = futurePosition; // try upto 10 times to change direction if there is collision //for (int i = 0; i < 4; i++) //{ ForwardDirection += turnAmount * GameConstants.TurnSpeed; Vector3 headingDirection = Vector3.Zero; headingDirection.X = (float)Math.Sin(ForwardDirection); headingDirection.Z = (float)Math.Cos(ForwardDirection); headingDirection.Normalize(); headingDirection *= GameConstants.FishSpeed; futurePosition = Position + headingDirection; if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesSize, tank) && Collision.isBarriersValidMove(this, futurePosition, fish, fishSize, tank)) { Position = futurePosition; BoundingSphere updatedSphere; updatedSphere = BoundingSphere; updatedSphere.Center.X = Position.X; updatedSphere.Center.Z = Position.Z; BoundingSphere = new BoundingSphere(updatedSphere.Center, updatedSphere.Radius); stucked = false; //break; } else { stucked = true; futurePosition = prevFuturePosition; } //normal shark model got deformed when turning if (!(Name == "shark") && !(Name == "Meiolania") && !(Name == "penguin")) { if (ForwardDirection - lastForwardDir > 0) { if (!clipPlayer.inRange(29, 31)) clipPlayer.switchRange(29, 31); } else if (ForwardDirection - lastForwardDir < 0) { if (!clipPlayer.inRange(40, 42)) clipPlayer.switchRange(40, 42); } else { if (!clipPlayer.inRange(1, 24)) clipPlayer.switchRange(1, 24); } } //} // if clip player has been initialized, update it if (clipPlayer != null && BoundingSphere.Intersects(cameraFrustum)) { qRotation = Quaternion.CreateFromAxisAngle( Vector3.Up, ForwardDirection); float scale = 1.0f; if (Name.Contains("dolphin") || Name.Contains("turtle")) scale = 0.5f; if (Name.Contains("manetee")) scale = 0.6f; if (Name.Contains("seal")) scale = 1.1f; if (Name.Contains("penguin")) scale = 2.0f; //if (isBigBoss) scale *= 2.0f; fishMatrix = Matrix.CreateScale(scale) * Matrix.CreateRotationY((float)MathHelper.Pi * 2) * Matrix.CreateFromQuaternion(qRotation) * Matrix.CreateTranslation(Position); clipPlayer.update(gameTime.ElapsedGameTime, true, fishMatrix); } if (PoseidonGame.playTime.TotalSeconds - lastHealthUpdateTime > healthChangeInterval) { double env_health = (double)HydroBot.currentEnvPoint / (double)HydroBot.maxEnvPoint; double env_deviation = 0; if ( env_health > 0.5) { if (this.health >= this.maxHealth) this.maxHealth += GameConstants.healthChangeValue; this.health += GameConstants.healthChangeValue; env_deviation = env_health - 0.5; } else if (env_health < 0.5) { //in dead sea, animal loses health twice faster if (PlayGameScene.currentLevel == 6 && HydroBot.gameMode == GameMode.MainGame) this.health -= 2 * GameConstants.healthChangeValue; else this.health -= GameConstants.healthChangeValue; env_deviation = 0.5 - env_health; } lastHealthUpdateTime = PoseidonGame.playTime.TotalSeconds; healthChangeInterval = GameConstants.maxHealthChangeInterval - env_deviation*10; //System.Diagnostics.Debug.WriteLine(healthChangeInterval); } }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, BoundingFrustum cameraFrustum, SwimmingObject[] enemies, int enemiesSize, SwimmingObject[] fish, int fishSize, int changeDirection, HydroBot tank, List<DamageBullet> enemyBullet) { EffectHelpers.GetEffectConfiguration(ref fogColor, ref ambientColor, ref diffuseColor, ref specularColor); if (lastPower != HydroBot.turtlePower) { float lastMaxHealth = maxHealth; maxHealth = GameConstants.TurtleStartingHealth * HydroBot.turtlePower; health += (maxHealth - lastMaxHealth); speedFactor = 1.5f + (HydroBot.turtlePower - 1) / 4; lastPower = HydroBot.turtlePower; } BaseEnemy potentialEnemy = lookForEnemy(enemies, enemiesSize); if (!isReturnBot && !isCasting && potentialEnemy != null) { // It is OK to cast? if (PoseidonGame.playTime.TotalSeconds - lastCast.TotalSeconds > coolDown.TotalSeconds)// && HydroBot.currentHitPoint < HydroBot.maxHitPoint) { isCasting = true; isReturnBot = false; isWandering = false; isChasing = false; isFighting = false; // For this case, I choose to set the forward direction statically rather than // facing different enemy since potentialEnemy may die, run away, etc Vector3 facingDirection = potentialEnemy.Position - Position; ForwardDirection = (float)Math.Atan2(facingDirection.X, facingDirection.Z); firstCast = true; startCasting = PoseidonGame.playTime; PoseidonGame.audio.frozenBreathe.Play(); } } if (isCasting == true) { // Casting timeout if (PoseidonGame.playTime.TotalSeconds - startCasting.TotalSeconds > standingTime.TotalSeconds) { isCasting = false; // Done casting isWandering = true; // Let the wander state do the wandering task, (and also lock enemy is potential enemy != null) lastCast = PoseidonGame.playTime; } // Effect during cast else { FrozenBreathe(enemies, enemiesSize, firstCast); firstCast = false; } RestoreNormalAnimation(); } Vector3 destination = tank.Position + new Vector3(AfterX, 0, AfterZ); if (isWandering == true) { // If the fish is far from the point after the bot's back or is the bot moving if (Vector3.Distance(tank.Position, Position) > HydroBot.controlRadius || (tank.isMoving() && Vector3.Distance(tank.Position, Position) > 50f)) { isWandering = false; isReturnBot = true; isChasing = false; isFighting = false; seekDestination(destination, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } else { currentTarget = potentialEnemy; if (currentTarget == null) // See no enemy randomWalk(changeDirection, enemies, enemiesSize, fish, fishSize, tank); else { // Hunt him down isWandering = false; isReturnBot = false; isChasing = true; isFighting = false; seekDestination(currentTarget.Position, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } } }// End wandering // If return is the current state else if (isReturnBot == true) { // If the fish is near the point after the bot's back, wander if (Vector3.Distance(destination, Position) < HydroBot.controlRadius * 0.5 && Vector3.Distance(tank.Position, Position) < HydroBot.controlRadius) { float test = Vector3.Distance(destination, Position); isWandering = true; isReturnBot = false; isChasing = false; isFighting = false; randomWalk(changeDirection, enemies, enemiesSize, fish, fishSize, tank); } else seekDestination(destination, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } // If the fish is chasing some enemy else if (isChasing == true) { if (Vector3.Distance(tank.Position, Position) > HydroBot.controlRadius * 1.25f) { // If too far, return to bot isWandering = false; isReturnBot = true; isChasing = false; isFighting = false; currentTarget = null; seekDestination(destination, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } else if (Vector3.Distance(Position, currentTarget.Position) < 5f + BoundingSphere.Radius + currentTarget.BoundingSphere.Radius) // Too close then attack { isWandering = false; isReturnBot = false; isChasing = false; isFighting = true; attack(); } else seekDestination(currentTarget.Position, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } // If fighting some enemy else if (isFighting == true) { // Enemy is down, return to bot if (currentTarget == null || currentTarget.health <= 0) { isWandering = false; isReturnBot = true; isChasing = false; isFighting = false; currentTarget = null; seekDestination(destination, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } else { // If the enemy ran away and the fish is not too far from bot if (Vector3.Distance(tank.Position, Position) >= HydroBot.controlRadius) { isWandering = false; isReturnBot = true; isChasing = false; isFighting = false; currentTarget = null; seekDestination(destination, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } // Or enemy ran away else if (Vector3.Distance(Position, currentTarget.Position) >= 10f + BoundingSphere.Radius + currentTarget.BoundingSphere.Radius) { isWandering = false; isReturnBot = false; isChasing = true; isFighting = false; seekDestination(currentTarget.Position, enemies, enemiesSize, fish, fishSize, tank, speedFactor); } else attack(); } } // if clip player has been initialized, update it if (clipPlayer != null || BoundingSphere.Intersects(cameraFrustum)) { qRotation = Quaternion.CreateFromAxisAngle( Vector3.Up, ForwardDirection); float scale = 0.7f; if (isBigBoss) scale *= 2.0f; fishMatrix = Matrix.CreateScale(scale) * Matrix.CreateRotationY((float)MathHelper.Pi * 2) * Matrix.CreateFromQuaternion(qRotation) * Matrix.CreateTranslation(Position); clipPlayer.update(gameTime.ElapsedGameTime, true, fishMatrix); } }
public void Update(GameTime gameTime, BoundingFrustum frustum, HydroBot tank, SwimmingObject[] enemies, int enemyAmount, SwimmingObject[] fishes, int fishAmount) { if (flock != null) { flock.Update(gameTime, tank, frustum, enemies, enemyAmount, fishes, fishAmount);//, cat); } else { SpawnFlock(gameMaxX, gameMaxZ, minValueX, maxValueX, minValueZ, maxValueZ); } }
public void randomWalk(int changeDirection, SwimmingObject[] enemies, int enemiesAmount, SwimmingObject[] fishes, int fishAmount, HydroBot hydroBot) { float lastForwardDir = ForwardDirection; float lastTurnAmount = turnAmount; Vector3 futurePosition = Position; //int barrier_move Random random = new Random(); //also try to change direction if we are stuck int rightLeft = random.Next(2); turnAmount = 0; if (stucked == true) { //ForwardDirection += MathHelper.PiOver4/2; if (lastTurnAmount == 0) { if (rightLeft == 0) turnAmount = 5; else turnAmount = -5; } else turnAmount = lastTurnAmount; } else if (changeDirection >= 99) { if (rightLeft == 0) turnAmount = 5; else turnAmount = -5; } Matrix orientationMatrix; // Vector3 speed; Vector3 movement = Vector3.Zero; movement.Z = 1; float prevForwardDir = ForwardDirection; Vector3 prevFuturePosition = futurePosition; // try upto 10 times to change direction is there is collision //for (int i = 0; i < 4; i++) //{ ForwardDirection += turnAmount * GameConstants.TurnSpeed; Vector3 headingDirection = Vector3.Zero; headingDirection.X = (float)Math.Sin(ForwardDirection); headingDirection.Z = (float)Math.Cos(ForwardDirection); headingDirection.Normalize(); headingDirection *= GameConstants.FishSpeed * speedFactor; futurePosition = Position + headingDirection; if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesAmount, hydroBot) && Collision.isBarriersValidMove(this, futurePosition, fishes, fishAmount, hydroBot)) { Position = futurePosition; BoundingSphere updatedSphere; updatedSphere = BoundingSphere; updatedSphere.Center.X = Position.X; updatedSphere.Center.Z = Position.Z; BoundingSphere = new BoundingSphere(updatedSphere.Center, updatedSphere.Radius); stucked = false; //break; } else { stucked = true; futurePosition = prevFuturePosition; } if (!(Name == "shark") && !(Name == "Meiolania") && !(Name == "penguin")) { if (ForwardDirection - lastForwardDir > 0) { if (!clipPlayer.inRange(29, 31)) clipPlayer.switchRange(29, 31); } else if (ForwardDirection - lastForwardDir < 0) { if (!clipPlayer.inRange(40, 42)) clipPlayer.switchRange(40, 42); } else { if (!clipPlayer.inRange(1, 24)) clipPlayer.switchRange(1, 24); } } //} }
public void ReleaseHunter(BoundingFrustum cameraFrustum, SwimmingObject[] enemies, ref int enemyAmount, SwimmingObject[] fishes, int fishAmount, HydroBot hydroBot) { if (!clipPlayer.inRange(31, 40)) clipPlayer.switchRange(31, 40); if (clipPlayer.donePlayingAnimation) { bool releaseOnRightSide; for (int i = 0; i < numHunterGeneratedAtOnce; i++) { enemies[enemyAmount] = new ShootingEnemy(); enemies[enemyAmount].Name = "Shooting Enemy"; enemies[enemyAmount].LoadContent(PoseidonGame.contentManager, "Models/EnemyModels/diver_green_ly"); enemies[enemyAmount].releasedFromSubmarine = true; ((BaseEnemy)enemies[enemyAmount]).Load(1, 25, 24); if (i % 2 == 0) releaseOnRightSide = true; else releaseOnRightSide = false; if (PlaceHunter(enemies[enemyAmount], hydroBot, (BaseEnemy[])enemies, enemyAmount, (Fish[])fishes, fishAmount, releaseOnRightSide)) { enemyAmount++; numHunterGenerated++; } else { enemies[enemyAmount] = null; break; } } if (!clipPlayer.inRange(11, 20)) clipPlayer.switchRange(11, 20); releasingHunter = false; } }
public static void updateProjectileHitBot(HydroBot hydroBot, List<DamageBullet> enemyBullets, GameMode gameMode, BaseEnemy[] enemies, int enemiesAmount, ParticleSystem explosionParticles, Camera gameCamera, Fish[] fishes, int fishAmount) { for (int i = 0; i < enemyBullets.Count; ) { if (enemyBullets[i].BoundingSphere.Intersects(hydroBot.BoundingSphere)) { if (!HydroBot.invincibleMode) { HydroBot.currentHitPoint -= enemyBullets[i].damage; if (gameMode == GameMode.MainGame || gameMode == GameMode.ShipWreck) PlayGameScene.healthLost += enemyBullets[i].damage; PoseidonGame.audio.botYell.Play(); Point point = new Point(); String point_string = "-" + enemyBullets[i].damage.ToString() + "HP"; point.LoadContent(PoseidonGame.contentManager, point_string, hydroBot.Position, Color.Red); if (gameMode == GameMode.ShipWreck) ShipWreckScene.points.Add(point); else if (gameMode == GameMode.MainGame) PlayGameScene.points.Add(point); else if (gameMode == GameMode.SurvivalMode) SurvivalGameScene.points.Add(point); } //when auto hipnotize mode is on //whoever hits the bot will be hipnotized if (HydroBot.autoHipnotizeMode) { if (enemyBullets[i].shooter != null && !enemyBullets[i].shooter.isHypnotise) CastSkill.useHypnotise(enemyBullets[i].shooter); } if (HydroBot.autoExplodeMode) { PoseidonGame.audio.Explo1.Play(); gameCamera.Shake(12.5f, .2f); CastSkill.UseThorHammer(hydroBot.Position, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, enemies, ref enemiesAmount, fishes, fishAmount, HydroBot.gameMode, true); } // add particle effect when certain kind of bullet hits if (enemyBullets[i] is Torpedo || enemyBullets[i] is ChasingBullet) { if (explosionParticles != null) { for (int k = 0; k < GameConstants.numExplosionParticles; k++) explosionParticles.AddParticle(enemyBullets[i].Position, Vector3.Zero); } PoseidonGame.audio.explosionSmall.Play(); } enemyBullets.RemoveAt(i); } else { i++; } } }
// Go straight protected virtual void goStraight(SwimmingObject[] enemies, int enemiesAmount, SwimmingObject[] fishes, int fishAmount, HydroBot hydroBot) { //Vector3 futurePosition = Position + speed * headingDirection; //if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesAmount, hydroBot) // && Collision.isBarriersValidMove(this, futurePosition, fishes, fishAmount, hydroBot)) //{ // Position = futurePosition; // //BoundingSphere.Center = Position; // BoundingSphere.Center.X += speed * headingDirection.X; // BoundingSphere.Center.Z += speed * headingDirection.Z; //} bool isCombatEnemy = (currentHuntingTarget.GetType().Name.Equals("CombatEnemy"))? true : false; float pullDistance = Vector3.Distance(currentHuntingTarget.Position, Position); float timeFactor = (isCombatEnemy)? 1.25f:1f; Vector3 futurePosition; if (pullDistance > (BoundingSphere.Radius + currentHuntingTarget.BoundingSphere.Radius) * timeFactor) { Vector3 pull = (currentHuntingTarget.Position - Position) * (1 / pullDistance); Vector3 totalPush = Vector3.Zero; int contenders = 0; for (int i = 0; i < enemiesAmount; i++) { if (enemies[i] != this) { Vector3 push = Position - enemies[i].Position; float distance = (Vector3.Distance(Position, enemies[i].Position)) - enemies[i].BoundingSphere.Radius; if (distance < BoundingSphere.Radius * 5) { contenders++; if (distance < 0.0001f) // prevent divide by 0 { distance = 0.0001f; } float weight = 1.1f / distance; // push away from big boss //if (enemies[i].isBigBoss) { // weight *= 1.5f; //} // If we stuck last time and this enemy is close by, get away from it if (((BaseEnemy)enemies[i]).currentHuntingTarget == currentHuntingTarget && distance < BoundingSphere.Radius * 3) { push *= 2; } totalPush += push * weight; } } } for (int i = 0; i < fishAmount; i++) { if (fishes[i] != currentHuntingTarget) { Vector3 push = Position - fishes[i].Position; float distance = (Vector3.Distance(Position, fishes[i].Position) - fishes[i].BoundingSphere.Radius) - BoundingSphere.Radius; if (distance < BoundingSphere.Radius * 4) { contenders++; if (distance < 0.0001f) // prevent divide by 0 { distance = 0.0001f; } float weight = 1 / distance; totalPush += push * weight; } } } pull *= Math.Max(1, 4 * contenders); pull += totalPush; pull.Normalize(); futurePosition = Position + (pull * speed * speedFactor); if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesAmount, hydroBot) && Collision.isBarriersValidMove(this, futurePosition, fishes, fishAmount, hydroBot)) { Position = futurePosition; BoundingSphere.Center.X += (pull * speed * speedFactor).X; BoundingSphere.Center.Z += (pull * speed * speedFactor).Z; lastForwardDirection = ForwardDirection; ForwardDirection = (float)Math.Atan2(pull.X, pull.Z); if (Math.Abs(lastForwardDirection - ForwardDirection) > 45f) { ForwardDirection = (lastForwardDirection + ForwardDirection) / 2 ; } } } }
public static void MouseOnWhichPowerPack(Cursor cursor, Camera gameCamera, List<Powerpack> powerPacks, ref Powerpack cursorOnPowerPack, ref Powerpack botOnPowerPack, HydroBot hydroBot) { bool foundBotOnPowerpack = false, foundCursorOnPowerpack = false; if (hydroBot == null) foundBotOnPowerpack = true; if (cursor == null) foundCursorOnPowerpack = true; BoundingSphere botPowerPackBoundingSphere = new BoundingSphere(); if (!foundBotOnPowerpack) botPowerPackBoundingSphere = new BoundingSphere(hydroBot.BoundingSphere.Center, 5); if (powerPacks == null) return; Ray cursorRay = new Ray(); if (cursor != null) cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Powerpack powerPack in powerPacks) { if (!foundBotOnPowerpack) { if (powerPack.BoundingSphere.Intersects(botPowerPackBoundingSphere)) { foundBotOnPowerpack = true; botOnPowerPack = powerPack; } } if (!foundCursorOnPowerpack) { if (RayIntersectsBoundingSphere(cursorRay, powerPack.BoundingSphere)) { foundCursorOnPowerpack = true; cursorOnPowerPack = powerPack; } } if (foundBotOnPowerpack && foundCursorOnPowerpack) return; } }
// Flee public void flee(SwimmingObject[] enemyList, int enemySize, SwimmingObject[] fishList, int fishSize, HydroBot hydroBot) { Vector2 tmp = new Vector2(fleeingDirection.X, fleeingDirection.Z); tmp.Normalize(); tmp *= 100f; // Somewhere faraway Vector3 fleeTarget = Position + new Vector3(tmp.X, 0, tmp.Y); seekDestination(fleeTarget, enemyList, enemySize, fishList, fishSize, hydroBot, speedFactor); }
public virtual void Update(SwimmingObject[] enemyList, ref int enemySize, SwimmingObject[] fishList, int fishSize, int changeDirection, HydroBot hydroBot, List<DamageBullet> enemyBullets, List<DamageBullet> alliesBullets, BoundingFrustum cameraFrustum, GameTime gameTime, GameMode gameMode) { }
public bool PlaceHunter(SwimmingObject newHunter, HydroBot hydroBot, BaseEnemy[] enemies, int enemyAmount, Fish[] fishes, int fishAmount, bool releaseOnRightSide) { Random random = new Random(); Vector3 movement = Vector3.Zero; movement.Z = 1; Matrix orientationMatrix = Matrix.CreateRotationY(ForwardDirection); Vector3 shootingDirection = Vector3.Transform(movement, orientationMatrix); Vector3 hunterPos; if (releaseOnRightSide) hunterPos = this.Position + AddingObjects.PerpendicularVector(shootingDirection) * 25; else hunterPos = this.Position - AddingObjects.PerpendicularVector(shootingDirection) * 25; if (!(AddingObjects.IsSurfaceOccupied(new BoundingSphere(hunterPos, newHunter.BoundingSphere.Radius), enemyAmount, fishAmount, enemies, fishes))) { newHunter.Position = hunterPos; newHunter.ForwardDirection = this.ForwardDirection; ((BaseEnemy)newHunter).currentHuntingTarget = hydroBot; ((BaseEnemy)newHunter).startChasingTime = PoseidonGame.playTime; ((BaseEnemy)newHunter).giveupTime = new TimeSpan(0, 0, 3); newHunter.BoundingSphere = new BoundingSphere(newHunter.Position, newHunter.BoundingSphere.Radius); return true; } else return false; }
protected override void makeAction(int changeDirection, SwimmingObject[] enemies, ref int enemiesAmount, SwimmingObject[] fishes, int fishAmount, List<DamageBullet> bullets, HydroBot hydroBot, BoundingFrustum cameraFrustum, GameTime gameTime) { if (releasingHunter) ReleaseHunter(cameraFrustum, enemies, ref enemiesAmount, fishes, fishAmount, hydroBot); if (configBits[0] == true) { randomWalk(changeDirection, enemies, enemiesAmount, fishes, fishAmount, hydroBot, speedFactor); return; } if (currentHuntingTarget != null) { calculateHeadingDirection(); } if (configBits[2] == true) { goStraight(enemies, enemiesAmount, fishes, fishAmount, hydroBot); } if (configBits[3] == true) { startChasingTime = PoseidonGame.playTime; if (currentHuntingTarget is BaseEnemy) { BaseEnemy tmp = (BaseEnemy)currentHuntingTarget; if (tmp.health <= 0) { currentHuntingTarget = null; justBeingShot = false; return; } } if (currentHuntingTarget is Fish) { Fish tmp = (Fish)currentHuntingTarget; if (tmp.health <= 0) { currentHuntingTarget = null; justBeingShot = false; } } if (PoseidonGame.playTime.TotalSeconds - timePrevPowerUsed > timeBetweenPowerUse) { bool powerUsed = false; powerupsType = random.Next(2); //only generate hunters while hunting hydrobot if (powerupsType == 0 && numHunterGenerated < GameConstants.NumEnemiesInSubmarine && currentHuntingTarget is HydroBot && this.BoundingSphere.Intersects(cameraFrustum)) { ReleaseHunter(cameraFrustum, enemies, ref enemiesAmount, fishes, fishAmount, hydroBot); releasingHunter = true; powerUsed = true; } else if (powerupsType == 1 && currentHuntingTarget is HydroBot) { ShootTorpedos(bullets, cameraFrustum); powerUsed = true; } if (powerUsed) timePrevPowerUsed = PoseidonGame.playTime.TotalSeconds; } else if (PoseidonGame.playTime.TotalSeconds - prevFire.TotalSeconds > timeBetweenFire && (Position - currentHuntingTarget.Position).Length() < GameConstants.TerminatorShootingRange) { //ChasingBullet(bullets, cameraFrustum, gameTime); // AddingObjects.placeChasingBullet(this, currentHuntingTarget, bullets, cameraFrustum); //AddingObjects.placeEnemyBullet(this, damage, bullets, 1, cameraFrustum, 20); ShootLaser(bullets, cameraFrustum); prevFire = PoseidonGame.playTime; } } }
public override void Update(SwimmingObject[] enemyList, ref int enemySize, SwimmingObject[] fishList, int fishSize, int changeDirection, HydroBot hydroBot, List<DamageBullet> enemyBullets, List<DamageBullet> alliesBullets, BoundingFrustum cameraFrustum, GameTime gameTime, GameMode gameMode) { EffectHelpers.GetEffectConfiguration(ref fogColor, ref ambientColor, ref diffuseColor, ref specularColor); if (BoundingSphere.Intersects(cameraFrustum)) { qRotation = Quaternion.CreateFromAxisAngle( Vector3.Up, ForwardDirection); enemyMatrix = Matrix.CreateScale(modelScale) * Matrix.CreateRotationY((float)MathHelper.Pi * 2) * Matrix.CreateFromQuaternion(qRotation) * Matrix.CreateTranslation(Position); clipPlayer.update(gameTime.ElapsedGameTime, true, enemyMatrix); } // do not delete this if (stunned) return; // Wear out slow if (speedFactor != 1) if (PoseidonGame.playTime.TotalSeconds - slowStart.TotalSeconds > slowDuration.TotalSeconds * HydroBot.turtlePower) speedFactor = 1; float buffFactor = HydroBot.currentEnergy / GameConstants.PlayerStartingEnergy / 2.0f * HydroBot.beltPower; buffFactor = MathHelper.Clamp(buffFactor, 1.0f, 1.6f); if (isHypnotise && PoseidonGame.playTime.TotalSeconds - startHypnotiseTime.TotalSeconds > GameConstants.timeHypnotiseLast * buffFactor) { wearOutHypnotise(); } if (!isHypnotise) { int perceptionID = perceptAndLock(hydroBot, fishList, fishSize); configAction(hydroBot, perceptionID, gameTime); makeAction(changeDirection, enemyList, ref enemySize, fishList, fishSize, enemyBullets, hydroBot, cameraFrustum, gameTime); } else { int perceptionID = perceptAndLock(hydroBot, enemyList, enemySize); configAction(hydroBot, perceptionID, gameTime); makeAction(changeDirection, enemyList, ref enemySize, fishList, fishSize, alliesBullets, hydroBot, cameraFrustum, gameTime); } }
// End---------------------------------------------------------- /// <summary> /// PROJECTILES FUNCTION /// </summary> /* scene --> 1-playgamescene, 2-shipwreckscene */ /* switch to use GameMode instead, look at the beginning of PoseidonGame for more details */ public static void updateDamageBulletVsBarriersCollision(List<DamageBullet> bullets, SwimmingObject[] barriers, ref int size, BoundingFrustum cameraFrustum, GameMode gameMode, GameTime gameTime, HydroBot hydroBot, BaseEnemy[] enemies, int enemiesAmount, Fish[] fishes, int fishAmount, Camera gameCamera, ParticleSystem explosionParticles) { BoundingSphere sphere; for (int i = 0; i < bullets.Count; i++) { //special handling for the skill combo FlyingHammer if (bullets[i] is FlyingHammer) { if (PoseidonGame.playTime.TotalSeconds - ((FlyingHammer)bullets[i]).timeShot > 1.25) { ((FlyingHammer)bullets[i]).explodeNow = true; PoseidonGame.audio.Explo1.Play(); gameCamera.Shake(25f, .4f); CastSkill.UseThorHammer(bullets[i].Position, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, enemies, ref enemiesAmount, fishes, fishAmount, HydroBot.gameMode, false); } } if (bullets[i] is FlyingHammer) { if (((FlyingHammer)bullets[i]).explodeNow) { bullets.RemoveAt(i--); continue; } } for (int j = 0; j < size; j++) { sphere = barriers[j].BoundingSphere; sphere.Radius *= GameConstants.EasyHitScale; //because Mutant Shark's easy hit sphere is too large if (barriers[j] is MutantShark) sphere.Radius *= 0.7f; if (bullets[i].BoundingSphere.Intersects(sphere)) { if (barriers[j] is Fish && barriers[j].BoundingSphere.Intersects(cameraFrustum)) { PoseidonGame.audio.animalYell.Play(); } if (barriers[j] is BaseEnemy) { //if (((BaseEnemy)barriers[j]).isHypnotise) if (bullets[i].shooter == barriers[j]) { continue; } else { if (bullets[i].shooter == null && !((BaseEnemy)barriers[j]).isHypnotise) { ((BaseEnemy)barriers[j]).justBeingShot = true; ((BaseEnemy)barriers[j]).startChasingTime = PoseidonGame.playTime; } } //special handling for the skill combo FlyingHammer if (bullets[i] is FlyingHammer) { PoseidonGame.audio.bodyHit.Play(); Vector3 oldPosition = barriers[j].Position; Vector3 pushVector = barriers[j].Position - bullets[i].Position; pushVector.Normalize(); ((BaseEnemy)barriers[j]).stunned = true; ((BaseEnemy)barriers[j]).stunnedStartTime = PoseidonGame.playTime.TotalSeconds; ((BaseEnemy)barriers[j]).Position += (pushVector * GameConstants.ThorPushFactor); barriers[j].Position.X = MathHelper.Clamp(barriers[j].Position.X, -hydroBot.MaxRangeX, hydroBot.MaxRangeX); barriers[j].Position.Z = MathHelper.Clamp(barriers[j].Position.Z, -hydroBot.MaxRangeZ, hydroBot.MaxRangeZ); barriers[j].BoundingSphere.Center = barriers[j].Position; if (Collision.isBarrierVsBarrierCollision(barriers[j], barriers[j].BoundingSphere, fishes, fishAmount) || Collision.isBarrierVsBarrierCollision(barriers[j], barriers[j].BoundingSphere, enemies, enemiesAmount)) { barriers[j].Position = oldPosition; barriers[j].BoundingSphere.Center = oldPosition; } } } // add particle effect when certain kind of bullet hits if (bullets[i] is Torpedo || bullets[i] is ChasingBullet) { if (explosionParticles != null) { for (int k = 0; k < GameConstants.numExplosionParticles; k++) explosionParticles.AddParticle(bullets[i].Position, Vector3.Zero); } PoseidonGame.audio.explosionSmall.Play(); } //whether or not to reduce health of the hit object bool reduceHealth = true; if (bullets[i] is HerculesBullet) { if (!((HerculesBullet)bullets[i]).piercingArrow) reduceHealth = true; else { bool enemyHitBefore = false; foreach (BaseEnemy hitEnemy in ((HerculesBullet)bullets[i]).hitEnemies) { if (hitEnemy == (BaseEnemy)barriers[j]) enemyHitBefore = true; } if (!enemyHitBefore) { reduceHealth = true; ((HerculesBullet)bullets[i]).hitEnemies.Add((BaseEnemy)barriers[j]); } else reduceHealth = false; } } else reduceHealth = true; if (reduceHealth) { barriers[j].health -= bullets[i].damage; if (barriers[j].BoundingSphere.Intersects(cameraFrustum)) { Point point = new Point(); String point_string = "-" + bullets[i].damage.ToString() + "HP"; point.LoadContent(PoseidonGame.contentManager, point_string, barriers[j].Position, Color.DarkRed); if (gameMode == GameMode.ShipWreck) ShipWreckScene.points.Add(point); else if (gameMode == GameMode.MainGame) PlayGameScene.points.Add(point); else if (gameMode == GameMode.SurvivalMode) SurvivalGameScene.points.Add(point); } } //remove the bullet that hits something if (bullets[i] is FlyingHammer) { //if (((FlyingHammer)bullets[i]).explodeNow) bullets.RemoveAt(i--); } //special handling for the skill combo Piercing arrow //pierce through enemies else if (bullets[i] is HerculesBullet) { if (!((HerculesBullet)bullets[i]).piercingArrow) bullets.RemoveAt(i--); } else bullets.RemoveAt(i--); break; } } } }
public static void MouseOnWhichTrash(Cursor cursor, Camera gameCamera, List<Trash> trashes,ref Trash cursorOnTrash,ref Trash botOnTrash, HydroBot hydroBot) { bool foundBotOnTrash = false, foundCursorOnTrash = false; if (hydroBot == null) foundBotOnTrash = true; BoundingSphere botTrashBoundingSphere = new BoundingSphere(); if (!foundBotOnTrash) botTrashBoundingSphere = new BoundingSphere(hydroBot.BoundingSphere.Center, 20); if (trashes == null) return; BoundingSphere trashRealSphere; Ray cursorRay = new Ray(); if (cursor != null) cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Trash trash in trashes) { trashRealSphere = trash.BoundingSphere; trashRealSphere.Center.Y = trash.Position.Y; trashRealSphere.Radius *= 5; if (!foundBotOnTrash) { if (trash.BoundingSphere.Intersects(botTrashBoundingSphere)) { foundBotOnTrash = true; botOnTrash = trash; } } if (!foundCursorOnTrash) { if (RayIntersectsBoundingSphere(cursorRay, trashRealSphere)) { foundCursorOnTrash = true; cursorOnTrash = trash; } } if (foundBotOnTrash && foundCursorOnTrash) return; } }
// End-------------------------------------------------------------- /// <summary> /// BOT COLLISION /// </summary> public static bool isBotValidMove(HydroBot hydroBot, Vector3 futurePosition, SwimmingObject[] enemies,int enemiesAmount, SwimmingObject[] fish, int fishAmount, HeightMapInfo heightMapInfo) { BoundingSphere futureBoundingSphere = hydroBot.BoundingSphere; futureBoundingSphere.Center.X = futurePosition.X; futureBoundingSphere.Center.Z = futurePosition.Z; //Don't allow off-terrain driving if (isOutOfMap(futurePosition, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, futureBoundingSphere)) { return false; } //in supersonice mode, you knock and you stun the enemies if (HydroBot.supersonicMode == true) { if (isBotVsBarrierCollision(futureBoundingSphere, fish, fishAmount)) return false; return true; } //else don't allow driving through an enemy if (isBotVsBarrierCollision(futureBoundingSphere, enemies, enemiesAmount)) { return false; } if (isBotVsBarrierCollision(futureBoundingSphere, fish, fishAmount)) { return false; } //if (heightMapInfo != null) //{ // if (heightMapInfo.GetHeight(futurePosition) >= -10) // return false; //} return true; }
public void ReactToMainCharacter(HydroBot tank, ref AIParameters AIparams) { if (tank != null) { //setting the the reactionLocation and reactionDistance here is //an optimization, many of the possible reactions use the distance //and location of theAnimal, so we might as well figure them out //only once ! Vector3 otherLocation = tank.Position; ClosestLocation(ref location, ref otherLocation, out reactionLocation); reactionDistance = Vector3.Distance(location, reactionLocation); //we only react if theAnimal is close enough that we can see it if (reactionDistance < AIparams.DetectionDistance) { fleeReaction.Update(tank, AIparams); if (fleeReaction.Reacted) { aiNewDir += fleeReaction.Reaction; aiNumSeen++; } } } }
public static void MouseOnWhichResource(Cursor cursor, Camera gameCamera, List<Resource> resources, ref Resource cursorOnResource, ref Resource botOnResource, HydroBot hydroBot) { bool foundBotOnResource = false, foundCursorOnResource = false; if (hydroBot == null) foundBotOnResource = true; if (cursor == null) foundCursorOnResource = true; BoundingSphere botPowerPackBoundingSphere = new BoundingSphere(); if (!foundBotOnResource) botPowerPackBoundingSphere = new BoundingSphere(hydroBot.BoundingSphere.Center, 5); if (resources == null) return; Ray cursorRay = new Ray(); if (cursor != null) cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Resource resource in resources) { if (!foundBotOnResource) { if (resource.BoundingSphere.Intersects(botPowerPackBoundingSphere)) { foundBotOnResource = true; botOnResource = resource; } } if (!foundCursorOnResource) { if (RayIntersectsBoundingSphere(cursorRay, resource.BoundingSphere)) { foundCursorOnResource = true; cursorOnResource = resource; } } if (foundBotOnResource && foundCursorOnResource) return; } }
public static void DrawObjectUnderStatus(SpriteBatch spriteBatch, Camera gameCamera, HydroBot hydroBot, GraphicsDevice graphicsDevice, List<Powerpack> powerPacks, List<Resource> resources, List<Trash> trashes, List<TreasureChest> chests, List<ShipWreck> shipWrecks, List<Factory> factories, ResearchFacility researchFacility) { if (!GameSettings.ShowLiveTip) return; //for highlighting obj under bot Powerpack powerPackPointedAt1 = null, botOnPowerPack1 = null; CursorManager.MouseOnWhichPowerPack(null, gameCamera, powerPacks, ref powerPackPointedAt1, ref botOnPowerPack1, hydroBot); string name = "", interaction = "", interaction2 = ""; Vector2 twoDPos = Vector2.Zero; if (botOnPowerPack1 != null) { Vector3 screenPos = graphicsDevice.Viewport.Project(botOnPowerPack1.Position, gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; if (botOnPowerPack1.powerType != PowerPackType.GoldenKey) name = "Power Pack"; else name = "Golden Key"; interaction = "Press Z to collect"; spriteBatch.DrawString(IngamePresentation.fishTalkFont, name, twoDPos, Color.Gold, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(name).X / 2, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); } else { Resource resourcePackPointedAt1 = null, botOnResource1 = null; CursorManager.MouseOnWhichResource(null, gameCamera, resources, ref resourcePackPointedAt1, ref botOnResource1, hydroBot); if (botOnResource1 != null) { Vector3 screenPos = graphicsDevice.Viewport.Project(botOnResource1.Position, gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; name = "Recycled Resource Box"; interaction = "Press Z to collect"; spriteBatch.DrawString(IngamePresentation.fishTalkFont, name, twoDPos, Color.Gold, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(name).X / 2, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); } else { TreasureChest botOverChest = CursorManager.BotOverWhichChest(hydroBot, chests); if (botOverChest != null) { Vector3 screenPos = graphicsDevice.Viewport.Project(botOverChest.Position, gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; name = "Treasure Chest"; interaction = "Double click to open"; spriteBatch.DrawString(IngamePresentation.fishTalkFont, name, twoDPos, Color.Gold, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(name).X / 2, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); } Trash trashPointedAt1 = null, botOnTrash1 = null; CursorManager.MouseOnWhichTrash(null, gameCamera, trashes, ref trashPointedAt1, ref botOnTrash1, hydroBot); if (botOnTrash1 != null) { Vector3 screenPos = graphicsDevice.Viewport.Project(botOnTrash1.Position, gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; if (botOnTrash1.trashType == TrashType.biodegradable) { name = "Biodegradable Waste"; interaction = "Press Z to collect"; } else if (botOnTrash1.trashType == TrashType.plastic) { name = "Plastic Waste"; interaction = "Press X to collect"; } else if (botOnTrash1.trashType == TrashType.radioactive) { name = "Radioactive Waste"; interaction = "Press C to collect"; } spriteBatch.DrawString(IngamePresentation.fishTalkFont, name, twoDPos, Color.Gold, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(name).X / 2, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); } else { ShipWreck botOverShipWreck = CursorManager.BotOverWhichShipWreck(hydroBot, shipWrecks); if (botOverShipWreck != null) { Vector3 screenPos = graphicsDevice.Viewport.Project(botOverShipWreck.Position, gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; name = "Old Shipwreck"; interaction = "Double click to enter"; spriteBatch.DrawString(IngamePresentation.fishTalkFont, name, twoDPos, Color.Gold, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(name).X / 2, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); } else { Factory botOverFactory = CursorManager.BotOverWhichFactory(hydroBot, factories); if (botOverFactory != null) { if (botOverFactory.factoryType == FactoryType.biodegradable) { name = "Biodegradable Waste Processing Plant"; } else if (botOverFactory.factoryType == FactoryType.plastic) { name = "Plastic Waste Processing Plant"; } else { name = "Radioactive Waste Processing Plant"; } interaction = "Double click to drop collected wastes"; interaction2 = "Shift + Click to open control panel"; Vector3 screenPos = graphicsDevice.Viewport.Project(botOverFactory.Position - new Vector3(0, 0, 20), gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; } if (CursorManager.BotOverResearchFacility(hydroBot, researchFacility)) { name = "Research Facility"; interaction = "Double click to drop collected objects"; interaction2 = "Shift + Click to open control panel"; Vector3 screenPos = graphicsDevice.Viewport.Project(researchFacility.Position - new Vector3(0, 0, 20), gameCamera.ProjectionMatrix, gameCamera.ViewMatrix, Matrix.Identity); twoDPos.X = screenPos.X; twoDPos.Y = screenPos.Y; } spriteBatch.DrawString(IngamePresentation.fishTalkFont, name, twoDPos, Color.Gold, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(name).X / 2, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); spriteBatch.DrawString(IngamePresentation.fishTalkFont, interaction2, twoDPos + new Vector2(0, IngamePresentation.fishTalkFont.MeasureString(name).Y / 2 + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction).Y + 5 + IngamePresentation.fishTalkFont.MeasureString(interaction2).Y/2) * IngamePresentation.textScaleFactor, Color.White, 0, new Vector2(IngamePresentation.fishTalkFont.MeasureString(interaction2).X / 2, IngamePresentation.fishTalkFont.MeasureString(interaction2).Y / 2), IngamePresentation.textScaleFactor, SpriteEffects.None, 0); } } } } }
// Go randomly is default move protected void randomWalk(int changeDirection, SwimmingObject[] enemies, int enemiesAmount, SwimmingObject[] fishes, int fishAmount, HydroBot hydroBot, float speedFactor) { float lastForwardDir = lastForwardDirection = ForwardDirection; float lastTurnAmount = turnAmount; Vector3 futurePosition = Position; //int barrier_move Random random = new Random(); //also try to change direction if we are stuck int rightLeft = random.Next(2); turnAmount = 0; if (stucked == true) { //ForwardDirection += MathHelper.PiOver4/2; if (lastTurnAmount == 0) { if (rightLeft == 0) turnAmount = 5; else turnAmount = -5; } else turnAmount = lastTurnAmount; } else if (changeDirection >= 99) { if (rightLeft == 0) turnAmount = 5; else turnAmount = -5; } float prevForwardDir = ForwardDirection; Vector3 prevFuturePosition = futurePosition; // try upto 10 times to change direction is there is collision //for (int i = 0; i < 4; i++) //{ ForwardDirection += turnAmount * GameConstants.TurnSpeed; Vector3 headingDirection = Vector3.Zero; headingDirection.X = (float)Math.Sin(ForwardDirection); headingDirection.Z = (float)Math.Cos(ForwardDirection); headingDirection.Normalize(); headingDirection *= GameConstants.EnemySpeed * speedFactor; futurePosition = Position + headingDirection; if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesAmount, hydroBot) && Collision.isBarriersValidMove(this, futurePosition, fishes, fishAmount, hydroBot)) { Position = futurePosition; BoundingSphere updatedSphere; updatedSphere = BoundingSphere; updatedSphere.Center.X += headingDirection.X;//Position.X; updatedSphere.Center.Z += headingDirection.Z;// Position.Z; BoundingSphere = new BoundingSphere(updatedSphere.Center, updatedSphere.Radius); stucked = false; //break; } else { stucked = true; futurePosition = prevFuturePosition; } //} }
// Helper private static bool isBarrierVsBotCollision(BoundingSphere vehicleBoundingSphere, HydroBot hydroBot) { if (vehicleBoundingSphere.Intersects(hydroBot.BoundingSphere)) return true; return false; }
// Go straight protected virtual void seekDestination(Vector3 destination, SwimmingObject[] enemies, int enemiesAmount, SwimmingObject[] fishes, int fishAmount, HydroBot hydroBot, float speedFactor) { //Vector3 futurePosition = Position + speed * headingDirection; //if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesAmount, hydroBot) // && Collision.isBarriersValidMove(this, futurePosition, fishes, fishAmount, hydroBot)) //{ // Position = futurePosition; // //BoundingSphere.Center = Position; // BoundingSphere.Center.X += speed * headingDirection.X; // BoundingSphere.Center.Z += speed * headingDirection.Z; //} float pullDistance = Vector3.Distance(destination, Position); // float timeFactor = (currentHuntingTarget.GetType().Name.Equals("CombatEnemy")) ? 1.25f : 1f; Vector3 futurePosition; if (pullDistance > (BoundingSphere.Radius + BoundingSphere.Radius)) { Vector3 pull = (destination - Position) * (1 / pullDistance); Vector3 totalPush = Vector3.Zero; int contenders = 0; for (int i = 0; i < enemiesAmount; i++) { if (enemies[i] != this) { Vector3 push = Position - enemies[i].Position; float distance = (Vector3.Distance(Position, enemies[i].Position)) - enemies[i].BoundingSphere.Radius; if (distance < BoundingSphere.Radius * 5) { contenders++; if (distance < 0.0001f) // prevent divide by 0 { distance = 0.0001f; } float weight = 1 / distance; totalPush += push * weight; } } } Vector3 hydrobotPush = Position - hydroBot.Position; float hydroDistance = (Vector3.Distance(Position, hydroBot.Position)) - hydroBot.BoundingSphere.Radius - BoundingSphere.Radius; if (hydroDistance < BoundingSphere.Radius * 5) { contenders++; if (hydroDistance < 0.0001f) // prevent divide by 0 { hydroDistance = 0.0001f; } float weight = 1 / hydroDistance; totalPush += hydrobotPush * weight; } for (int i = 0; i < fishAmount; i++) { if (fishes[i] != this) { Vector3 push = Position - fishes[i].Position; float distance = (Vector3.Distance(Position, fishes[i].Position) - fishes[i].BoundingSphere.Radius) - BoundingSphere.Radius; if (distance < BoundingSphere.Radius * 5) { contenders++; if (distance < 0.0001f) // prevent divide by 0 { distance = 0.0001f; } float weight = 1 / distance; totalPush += push * weight; } } } pull *= Math.Max(1, 4 * contenders); pull += totalPush; pull.Normalize(); // Speed factor stuff futurePosition = Position + (pull * GameConstants.FishSpeed * speedFactor); if (Collision.isBarriersValidMove(this, futurePosition, enemies, enemiesAmount, hydroBot) && Collision.isBarriersValidMove(this, futurePosition, fishes, fishAmount, hydroBot)) { Position = futurePosition; BoundingSphere.Center.X += (pull * GameConstants.FishSpeed * speedFactor).X; BoundingSphere.Center.Z += (pull * GameConstants.FishSpeed * speedFactor).Z; float lastForwardDir = ForwardDirection; ForwardDirection = (float)Math.Atan2(pull.X, pull.Z); PlaySteeringAnimation(lastForwardDir, ForwardDirection); } } }
public SurvivalGameScene(Game game, GraphicsDeviceManager graphic, ContentManager content, GraphicsDevice GraphicsDevice, SpriteBatch spriteBatch, Vector2 pausePosition, Rectangle pauseRect, Texture2D actionTexture, CutSceneDialog cutSceneDialog, Radar radar, Texture2D stunnedTexture) : base(game) { graphics = graphic; Content = content; GraphicDevice = GraphicsDevice; this.spriteBatch = spriteBatch; this.pausePosition = pausePosition; this.pauseRect = pauseRect; this.actionTexture = actionTexture; this.game = game; this.radar = radar; this.stunnedIconTexture = stunnedTexture; roundTime = TimeSpan.FromSeconds(2592000); random = new Random(); gameCamera = new Camera(GameMode.SurvivalMode); boundingSphere = new GameObject(); hydroBot = new HydroBot(GameConstants.MainGameMaxRangeX, GameConstants.MainGameMaxRangeZ, GameConstants.MainGameFloatHeight, GameMode.SurvivalMode); if (File.Exists("SurvivalMode")) { ObjectsToSerialize objectsToSerialize = new ObjectsToSerialize(); Serializer serializer = new Serializer(); string SavedFile = "SurvivalMode"; objectsToSerialize = serializer.DeSerializeObjects(SavedFile); hydroBot = objectsToSerialize.hydrobot; } //stop spinning the bar IngamePresentation.StopSpinning(); HydroBot.gamePlusLevel = 0; HydroBot.gameMode = GameMode.SurvivalMode; for (int index = 0; index < GameConstants.numberOfSkills; index++) { HydroBot.skills[index] = true; } skillTextures = new Texture2D[GameConstants.numberOfSkills]; bulletTypeTextures = new Texture2D[GameConstants.numBulletTypes]; // for the mouse or touch cursor = new Cursor(game, spriteBatch); //Components.Add(cursor); bubbles = new List<Bubble>(); points = new List<Point>(); //loading winning, losing textures winningTexture = IngamePresentation.winningTexture; losingTexture = IngamePresentation.losingTexture; scaredIconTexture = IngamePresentation.scaredIconTexture; isAncientKilled = false; // Instantiate the factory Button float buttonScale = 1.0f; if (game.Window.ClientBounds.Width <= 900) { buttonScale = 0.8f; // scale the factory panel icons a bit smaller in small window mode } factoryButtonPanel = new ButtonPanel(4, buttonScale); this.Load(); gameBoundary = new GameBoundary(); gameBoundary.LoadGraphicsContent(GraphicDevice); }