Exemple #1
0
 //Knock out any enemy that you crash into
 public static void KnockOutEnemies(BoundingSphere boundingSphere, Vector3 Position, int MaxRangeX, int MaxRangeZ, BaseEnemy[] enemies, ref int enemiesAmount, SwimmingObject[] fishes, int fishAmount, AudioLibrary audio, GameMode gameMode)
 {
     for (int i = 0; i < enemiesAmount; i++)
     {
         if (boundingSphere.Intersects(enemies[i].BoundingSphere))
         {
             PoseidonGame.audio.bodyHit.Play();
             float healthiness = HydroBot.currentEnergy / GameConstants.PlayerStartingEnergy;
             if (healthiness > 1) healthiness = 1.0f;
             Vector3 oldPosition = enemies[i].Position;
             Vector3 pushVector = enemies[i].Position - Position;
             pushVector.Normalize();
             //can't stun a submarine
             if (!(enemies[i] is Submarine))
             {
                 enemies[i].stunned = true;
                 enemies[i].stunnedStartTime = PoseidonGame.playTime.TotalSeconds;
                 if (HydroBot.sonicHipnotiseMode)
                 {
                     enemies[i].setHypnotise();
                 }
             }
             enemies[i].Position += (pushVector * GameConstants.ThorPushFactor);
             enemies[i].Position.X = MathHelper.Clamp(enemies[i].Position.X, -MaxRangeX, MaxRangeX);
             enemies[i].Position.Z = MathHelper.Clamp(enemies[i].Position.Z, -MaxRangeZ, MaxRangeZ);
             enemies[i].BoundingSphere.Center = enemies[i].Position;
             if (Collision.isBarrierVsBarrierCollision(enemies[i], enemies[i].BoundingSphere, fishes, fishAmount)
                 || Collision.isBarrierVsBarrierCollision(enemies[i], enemies[i].BoundingSphere, enemies, enemiesAmount))
             {
                 enemies[i].Position = oldPosition;
                 enemies[i].BoundingSphere.Center = oldPosition;
             }
             int healthloss = (int)(GameConstants.HermesDamage * healthiness * HydroBot.speed * HydroBot.speedUp * HydroBot.sandalPower);
             enemies[i].health -= healthloss;
             //audio.Shooting.Play();
             //if (enemies[i].health <= 0)
             //{
             //    if (enemies[i].isBigBoss == true) PlayGameScene.isBossKilled = true;
             //    for (int k = i + 1; k < enemiesAmount; k++)
             //    {
             //        enemies[k - 1] = enemies[k];
             //    }
             //    enemies[--enemiesAmount] = null;
             //    i--;
             //}
             Point point = new Point();
             String point_string = "-" + healthloss.ToString() + "HP";
             point.LoadContent(PoseidonGame.contentManager, point_string, enemies[i].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);
         }
     }
 }
Exemple #2
0
        protected int perceptAndLock(HydroBot hydroBot, SwimmingObject[] enemyList, int enemySize)
        {
            if (!isHypnotise && Vector3.Distance(Position, hydroBot.Position) < perceptionRadius)
            {
                currentHuntingTarget = hydroBot;
                return perceptID[1];
            }
            else
            {
                if (currentHuntingTarget != null
                        && Vector3.Distance(Position, currentHuntingTarget.Position) < perceptionRadius) {
                    return perceptID[2];
                }

                for (int i = 0; i < enemySize; i++)
                {
                    if (this != enemyList[i] && Vector3.Distance(Position, enemyList[i].Position) < perceptionRadius) {
                        currentHuntingTarget = enemyList[i];
                        return perceptID[3];
                    }
                }
                return perceptID[0];
            }
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
 public BaseEnemy lookForEnemy(SwimmingObject[] enemies, int enemiesSize)
 {
     for (int i = 0; i < enemiesSize; i++)
         if (Vector3.Distance(Position, enemies[i].Position) < GameConstants.SideKick_Look_Radius)
             return (BaseEnemy)enemies[i];
     return null;
 }
Exemple #6
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;
                }
            //}
        }
Exemple #7
0
 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)
 {
 }
Exemple #8
0
        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;
        }
Exemple #9
0
        /// <summary>
        /// BARRIERS FUNCTIONS
        /// </summary>
        public static bool isBarriersValidMove(SwimmingObject obj, Vector3 futurePosition, SwimmingObject[] objects, int size, HydroBot hydroBot)
        {
            BoundingSphere futureBoundingSphere = obj.BoundingSphere;
            futureBoundingSphere.Center.X = futurePosition.X;
            futureBoundingSphere.Center.Z = futurePosition.Z;

            //don't let the living object to swim completely out of the screen reach
            if (isOutOfMap(futurePosition, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, futureBoundingSphere))
            {
                return false;
            }

            if (isBarrierVsBarrierCollision(obj, futureBoundingSphere, objects, size)) {
                return false;
            }

            if (isBarrierVsBotCollision(futureBoundingSphere, hydroBot)) {
                return false;
            }
            return true;
        }
Exemple #10
0
        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 (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 (enragedMode == true)
                {
                    RapidFire(bullets, cameraFrustum, gameTime);

                    if (PoseidonGame.playTime.TotalSeconds - timePrevPowerUsed > timeEnrageLast)
                        enragedMode = false;
                }
                else if (crazyMode == true)
                {
                    //don't really wanna see this move when capturing cinematic
                    if (PoseidonGame.capturingCinematic)
                    {
                        ChasingBullet(bullets, cameraFrustum, gameTime);
                        if (PoseidonGame.playTime.TotalSeconds - timePrevPowerUsed > timeChasingBulletLast)
                            crazyMode = false;
                    }
                    else
                    {
                        RapidFire2(bullets, cameraFrustum, gameTime);
                        if (PoseidonGame.playTime.TotalSeconds - timePrevPowerUsed > timeEnrageLast)
                            crazyMode = false;
                    }
                }
                else if (chasingBulletMode == true) {
                    ChasingBullet(bullets, cameraFrustum, gameTime);
                    if (PoseidonGame.playTime.TotalSeconds - timePrevPowerUsed > timeChasingBulletLast)
                        chasingBulletMode = false;
                }
                //only cast special skill when hunting hydrobot
                else if (PoseidonGame.playTime.TotalSeconds - timePrevPowerUsed > timeBetweenPowerUse && currentHuntingTarget is HydroBot)
                {
                    powerupsType = random.Next(3);
                    if (powerupsType == 0)
                        enragedMode = true;
                    else if (powerupsType == 1)
                        crazyMode = true;
                    else if (powerupsType == 2)
                    {
                        chasingBulletMode = true;
                    }
                    //PlayGameScene.audio.MinigunWindUp.Play();
                    timePrevPowerUsed = PoseidonGame.playTime.TotalSeconds;
                }
                else if (currentHuntingTarget != null)
                {
                    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);
                        prevFire = PoseidonGame.playTime;
                        justShot = true;
                    }
                }
            }
            if (justShot && BoundingSphere.Intersects(cameraFrustum))
            {
                Matrix orientationMatrix = Matrix.CreateRotationY(ForwardDirection);
                Vector3 movement = Vector3.Zero;
                movement.Z = 1;
                Vector3 shootingDirection = Vector3.Transform(movement, orientationMatrix);
                if (particleManager.explosionParticles != null)
                {
                    for (int k = 0; k < GameConstants.numExplosionSmallParticles; k++)
                        particleManager.explosionSmallParticles.AddParticle(Position + shootingDirection * 22, Vector3.Zero);
                }
                justShot = false;
            }
        }
Exemple #11
0
 // push enemy away
 public static void PushEnemy(Vector3 Position, int MaxRangeX, int MaxRangeZ, BaseEnemy enemy, SwimmingObject[] enemies, int enemiesAmount, SwimmingObject[] fishes, int fishAmount )
 {
     Vector3 oldPosition = enemy.Position;
     Vector3 pushVector = enemy.Position - Position;
     pushVector.Normalize();
     enemy.Position += (pushVector * GameConstants.ThorPushFactor);
     enemy.Position.X = MathHelper.Clamp(enemy.Position.X, -MaxRangeX, MaxRangeX);
     enemy.Position.Z = MathHelper.Clamp(enemy.Position.Z, -MaxRangeZ, MaxRangeZ);
     enemy.BoundingSphere.Center = enemy.Position;
     if (Collision.isBarrierVsBarrierCollision(enemy, enemy.BoundingSphere, fishes, fishAmount)
         || Collision.isBarrierVsBarrierCollision(enemy, enemy.BoundingSphere, enemies, enemiesAmount))
     {
         enemy.Position = oldPosition;
         enemy.BoundingSphere.Center = oldPosition;
     }
 }
Exemple #12
0
        public static void UseThorHammer(Vector3 Position, int MaxRangeX, int MaxRangeZ, BaseEnemy[] enemies, ref int enemiesAmount, SwimmingObject[] fishes, int fishAmount, GameMode gameMode, bool halfStrength)
        {
            HydroBot.distortingScreen = true;
            HydroBot.distortionStart = PoseidonGame.playTime.TotalSeconds;

            for (int i = 0; i < enemiesAmount; i++)
            {
                if (InThorRange(Position, enemies[i].Position)){
                    float healthiness = HydroBot.currentEnergy / GameConstants.PlayerStartingEnergy;
                    if (healthiness > 1) healthiness = 1.0f;
                    //you can't stun a submarine
                    if (!(enemies[i] is Submarine))
                    {
                        enemies[i].stunned = true;
                        enemies[i].stunnedStartTime = PoseidonGame.playTime.TotalSeconds;
                    }
                    float healthloss = (GameConstants.ThorDamage * healthiness * HydroBot.strength * HydroBot.strengthUp * HydroBot.hammerPower);
                    if (halfStrength) healthloss /= 2;
                    enemies[i].health -= healthloss;
                    PushEnemy(Position, MaxRangeX, MaxRangeZ, enemies[i], enemies, enemiesAmount, fishes, fishAmount);
                    //if (enemies[i].health <= 0)
                    //{
                    //    if (enemies[i].isBigBoss == true) PlayGameScene.isBossKilled = true;
                    //    for (int k = i + 1; k < enemiesAmount; k++) {
                    //        enemies[k - 1] = enemies[k];
                    //    }
                    //    enemies[--enemiesAmount] = null;
                    //    i--;
                    //}

                    Point point = new Point();
                    String point_string = "-" + ((int)healthloss).ToString() + "HP";
                    point.LoadContent(PoseidonGame.contentManager, point_string, enemies[i].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);
                }
            }
        }
Exemple #13
0
        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(0.1f) * Matrix.CreateRotationY((float)MathHelper.Pi * 2) *
                                    Matrix.CreateFromQuaternion(qRotation) *
                                    Matrix.CreateTranslation(Position);
                clipPlayer.update(gameTime.ElapsedGameTime, true, enemyMatrix);

            // Fleeing stuff
            if (isFleeing == true) {
                if (PoseidonGame.playTime.TotalSeconds - fleeingStart.TotalSeconds < fleeingDuration.TotalSeconds * HydroBot.seaCowPower)
                {
                    flee(enemyList, enemySize, fishList, fishSize, hydroBot);
                    return;
                }
                else {
                    isFleeing = false;
                }
                if (!clipPlayer.inRange(1, 30))
                    clipPlayer.switchRange(1, 30);
            }
            if (isPoissoned == true)
            {
                if (accumulatedHealthLossFromPoison < maxHPLossFromPoisson)
                {
                    health -= 0.1f;
                    accumulatedHealthLossFromPoison += 0.1f;
                }
                else
                {
                    isPoissoned = false;
                    accumulatedHealthLossFromPoison = 0;
                }
            }
            // Wear out slow
            if (speedFactor != 1)
                if (PoseidonGame.playTime.TotalSeconds - slowStart.TotalSeconds > slowDuration.TotalSeconds * HydroBot.turtlePower)
                    speedFactor = 1;

            // Stun stuff
            if (stunned)
            {
                if (!clipPlayer.inRange(1, 30))
                    clipPlayer.switchRange(1, 30);
                return;
            }

            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 && !isFleeing && !stunned)
            {
                int perceptionID = perceptAndLock(hydroBot, fishList, fishSize);
                configAction(hydroBot, perceptionID, gameTime);
                makeAction(changeDirection, enemyList, enemySize, fishList, fishSize, enemyBullets, hydroBot, cameraFrustum, gameTime, gameMode);
            }
            else
            {
                int perceptionID = perceptAndLock(hydroBot, enemyList, enemySize);
                configAction(hydroBot, perceptionID, gameTime);
                makeAction(changeDirection, enemyList, enemySize, fishList, fishSize, enemyBullets, hydroBot, cameraFrustum, gameTime, gameMode);
            }
        }
Exemple #14
0
        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);
            }
        }
Exemple #15
0
 // Helper
 public static bool isBarrierVsBarrierCollision(SwimmingObject enemy, BoundingSphere futureBoundingSphere, SwimmingObject[] objs, int size)
 {
     for (int curBarrier = 0; curBarrier < size; curBarrier++)
     {
         if (enemy.Equals(objs[curBarrier]))
             continue;
         if (futureBoundingSphere.Intersects(
             objs[curBarrier].BoundingSphere))
         {
             //System.Diagnostics.Debug.WriteLine("I am "+enemy.Name+" stuck with "+ objs[curBarrier].Name);
             return true;
         }
     }
     return false;
 }
Exemple #16
0
        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;
                }
            }
        }
Exemple #17
0
        public static void deleteSmallerThanZero(SwimmingObject[] objs, ref int size, BoundingFrustum cameraFrustum, GameMode gameMode, Cursor cursor, ParticleSystem explosionParticles)
        {
            for (int i = 0; i < size; i++) {
                if (objs[i].health <= 0 && objs[i].gaveExp == false) {
                    // Delete code is below this
                    // This snippet does not include deleting
                    if (objs[i] is SeaCow) {
                        HydroBot.hasSeaCow = false;
                        HydroBot.seaCowPower = 0;
                        HydroBot.iconActivated[IngamePresentation.seaCowIcon] = false;
                    }
                    if (objs[i] is SeaTurtle)
                    {
                        HydroBot.hasTurtle = false;
                        HydroBot.turtlePower = 0;
                        HydroBot.iconActivated[IngamePresentation.turtleIcon] = false;
                    }
                    if (objs[i] is SeaDolphin)
                    {
                        HydroBot.hasDolphin = false;
                        HydroBot.dolphinPower = 0;
                        HydroBot.iconActivated[IngamePresentation.dolphinIcon] = false;
                    }

                    if (objs[i].isBigBoss == true)
                    {
                        if (gameMode == GameMode.MainGame || gameMode == GameMode.ShipWreck)
                        {
                            PlayGameScene.isBossKilled = true;
                            PlayGameScene.numBossKills += 1;
                        }
                        else if (gameMode == GameMode.SurvivalMode && objs[i] is Fish)
                            SurvivalGameScene.isAncientKilled = true;
                    }
                    else
                    {
                        if (gameMode == GameMode.MainGame || gameMode == GameMode.ShipWreck)
                        {
                            PlayGameScene.numNormalKills += 1;
                        }
                    }
                    if (objs[i] is BaseEnemy) {
                        HydroBot.currentExperiencePts += objs[i].basicExperienceReward;
                        objs[i].gaveExp = true;
                        if (gameMode == GameMode.SurvivalMode)
                            SurvivalGameScene.score += objs[i].basicExperienceReward / 2;
                        if (objs[i].BoundingSphere.Intersects(cameraFrustum))
                        {
                            Point point = new Point();
                            String point_string = "+" + objs[i].basicExperienceReward.ToString() + "EXP";
                            point.LoadContent(PoseidonGame.contentManager, point_string, objs[i].Position, Color.LawnGreen);
                            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);
                        }

                        if (!objs[i].isBigBoss)
                        {
                            if (objs[i].BoundingSphere.Intersects(cameraFrustum))
                            {
                                if (objs[i] is GhostPirate)
                                    PoseidonGame.audio.skeletonDie.Play();
                                else PoseidonGame.audio.hunterYell.Play();
                            }
                        }
                        else
                        {
                            if (objs[i] is MutantShark)
                                PoseidonGame.audio.mutantSharkYell.Play();
                            else if (objs[i] is Terminator)
                                PoseidonGame.audio.terminatorYell.Play();
                            else if (objs[i] is Submarine)
                            {
                                PoseidonGame.audio.Explosion.Play();
                                if (explosionParticles != null)
                                {
                                    for (int k = 0; k < GameConstants.numExplosionParticles; k++)
                                        explosionParticles.AddParticle(objs[i].Position, Vector3.Zero);
                                }
                            }
                        }
                    }

                    if (objs[i] is Fish)
                    {
                        int envLoss;
                        envLoss = GameConstants.envLossForFishDeath;
                        HydroBot.currentEnvPoint -= envLoss;
                        if (objs[i].BoundingSphere.Intersects(cameraFrustum))
                        {
                            Point point = new Point();
                            String point_string = "-" + envLoss.ToString() + "ENV";
                            point.LoadContent(PoseidonGame.contentManager, point_string, objs[i].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);
                        }
                    }
                    if (objs[i] == cursor.targetToLock)
                    {
                        cursor.targetToLock = null;
                        //objs[i] = null;
                    }

                    //if we are playing the survival mode
                    //revive the dead enemy instead
                    if (gameMode != GameMode.SurvivalMode || objs[i] is Fish || (objs[i].releasedFromSubmarine))
                    {
                        objs[i] = null;
                        for (int k = i; k < size - 1; k++)
                        {
                            objs[k] = objs[k + 1];
                        }
                        objs[--size] = null;
                    }

                }
            }
        }
Exemple #18
0
        // 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);
        }
Exemple #19
0
        // 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;
        }
Exemple #20
0
        // 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 ;
                    }
                }
            }
        }
Exemple #21
0
 // Helper
 public static bool isBotVsBarrierCollision(BoundingSphere boundingSphere, SwimmingObject[] barrier, int size)
 {
     for (int i = 0; i < size; i++)
     {
         if (boundingSphere.Intersects(barrier[i].BoundingSphere))
         {
             return true;
         }
     }
     return false;
 }
Exemple #22
0
 /// <summary>
 /// Handles input for Windows.
 /// </summary>
 private void UpdateWindowsInput(GraphicsDevice graphicDevice, Camera gameCamera, BoundingFrustum frustum)
 {
     if (targetToLock == null)
     {
         MouseState mouseState = Mouse.GetState();
         position.X = mouseState.X;
         position.Y = mouseState.Y;
     }
     else
     {
         Vector3 screenPos = graphicDevice.Viewport.Project(targetToLock.Position, gameCamera.ProjectionMatrix,
             gameCamera.ViewMatrix, Matrix.Identity);
         position.X = screenPos.X;
         position.Y = screenPos.Y;
         //release lock if enemy is out of camera frustum
         if (!targetToLock.BoundingSphere.Intersects(frustum)) targetToLock = null;
     }
 }
Exemple #23
0
        // 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;
                    }
                }
            }
        }
Exemple #24
0
        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);
                    }
                }
            //}
        }
Exemple #25
0
        public static void updateHealingBulletVsBarrierCollision(List<HealthBullet> bullets, SwimmingObject[] barriers, int size, BoundingFrustum cameraFrustum, GameMode gameMode)
        {
            BoundingSphere sphere;
            for (int i = 0; i < bullets.Count; i++) {
                for (int j = 0; j < size; j++) {
                    sphere = barriers[j].BoundingSphere;
                    sphere.Radius *= GameConstants.EasyHitScale;
                    if (bullets[i].BoundingSphere.Intersects(sphere))
                    {
                        //fulfill the task of healing fish
                        if (PlayGameScene.currentLevel == 0 && PlayGameScene.levelObjectiveState == 7)
                        {
                            PlayGameScene.levelObjectiveState = 8;
                            PlayGameScene.newLevelObjAvailable = true;
                        }
                        if (barriers[j].BoundingSphere.Intersects(cameraFrustum))
                            PoseidonGame.audio.animalHappy.Play();

                        if (barriers[j].health < barriers[j].maxHealth ) {
                            float amountHealed = Math.Min(bullets[i].healthAmount, barriers[j].maxHealth - barriers[j].health);

                            barriers[j].health += amountHealed;
                            if (barriers[j].health > barriers[j].maxHealth) barriers[j].health = barriers[j].maxHealth;

                            int expReward = (int)(((double)amountHealed / (double)GameConstants.HealingAmount) * barriers[j].basicExperienceReward);
                            if (PoseidonGame.gamePlus)
                            {
                                expReward += (int)(((double)amountHealed / (double)GameConstants.HealingAmount) * HydroBot.gamePlusLevel * 5);
                            }
                            //int envReward = (int) (((double)bullets[i].healthAmount / (double)GameConstants.HealingAmount) * GameConstants.BasicEnvGainForHealingFish);
                            int goodWillReward = (int)(((double)amountHealed / (double)GameConstants.HealingAmount) * GameConstants.GoodWillPointGainForHealing);

                            HydroBot.currentExperiencePts += expReward;
                            //HydroBot.currentEnvPoint += envReward;

                            //update good will point
                            HydroBot.IncreaseGoodWillPoint(goodWillReward);

                            if (HydroBot.gameMode == GameMode.SurvivalMode)
                                SurvivalGameScene.score += expReward / 2;

                            Point point = new Point();
                            //String point_string = "+" + envReward.ToString() + "ENV\n+"+expReward.ToString()+"EXP";
                            String point_string = "+" + expReward.ToString() + "EXP";
                            point.LoadContent(PoseidonGame.contentManager, point_string, barriers[j].Position, Color.LawnGreen);
                            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);
                        }
                        bullets.RemoveAt(i--);
                        break;
                    }
                }
            }
        }
Exemple #26
0
        public void FrozenBreathe(SwimmingObject[] enemies, int enemiesSize, bool firstCast)
        {
            Matrix orientationMatrix = Matrix.CreateRotationY(ForwardDirection);
            Vector3 movement = Vector3.Zero;
            movement.Z = 1;
            Vector3 observerDirection = Vector3.Transform(movement, orientationMatrix);

            for (int i = 0; i < enemiesSize; i++) {
                Vector3 otherDirection = enemies[i].Position - Position;
                if (Behavior.isInSight(observerDirection, Position, otherDirection, enemies[i].Position, MathHelper.PiOver4,
                    70f * (float)((PoseidonGame.playTime.TotalMilliseconds - startCasting.TotalMilliseconds) / standingTime.TotalMilliseconds)))
                {
                //if (Vector3.Distance(enemies[i].Position, Position) < 60f) {
                    if (firstCast)
                        enemies[i].health -= frozenBreathDamage * HydroBot.turtlePower;
                    enemies[i].speedFactor = 0.5f;
                    enemies[i].slowStart = PoseidonGame.playTime;
                }
            }

            if (particleManager.frozenBreathParticles != null)
            {
                for (int k = 0; k < GameConstants.numFrozenBreathParticlesPerUpdate; k++)
                    particleManager.frozenBreathParticles.AddParticle(Position + Vector3.Transform(new Vector3(0, 0, 1), orientationMatrix) * 10, Vector3.Zero, ForwardDirection, MathHelper.PiOver4);
            }
            //numTimeReleaseFrozenBreath += 1;
        }
Exemple #27
0
 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;
     }
 }
Exemple #28
0
        // 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);
                }
            }
        }
Exemple #29
0
        // Execute the actions .. scene -> 1=playgamescene, 2=shipwreckscene
        protected virtual void makeAction(int changeDirection, SwimmingObject[] enemies, int enemiesAmount, SwimmingObject[] fishes, int fishAmount, List<DamageBullet> bullets, HydroBot hydroBot, BoundingFrustum cameraFrustum, GameTime gameTime, GameMode gameMode)
        {
            if (configBits[0] == true)
            {
                // swimming w/o attacking
                if (!clipPlayer.inRange(1, 30) && !configBits[3])
                    clipPlayer.switchRange(1, 30);
                randomWalk(changeDirection, enemies, enemiesAmount, fishes, fishAmount, hydroBot, speedFactor);
                return;
            }
            if (currentHuntingTarget != null)
            {
                calculateHeadingDirection();
                calculateFutureBoundingSphere();
            }
            if (configBits[2] == true)
            {
                // swimming w/o attacking
                if (!clipPlayer.inRange(1, 30) && !configBits[3])
                    clipPlayer.switchRange(1, 30);
                goStraight(enemies, enemiesAmount, fishes, fishAmount, hydroBot);
            }
            if (configBits[3] == true)
            {
                startChasingTime = PoseidonGame.playTime;

                if (currentHuntingTarget is Fish)
                {
                    Fish tmp = (Fish)currentHuntingTarget;
                    if (tmp.health <= 0)
                    {
                        currentHuntingTarget = null;
                        justBeingShot = false;
                        return;
                    }
                }

                if (currentHuntingTarget is BaseEnemy)
                {
                    BaseEnemy tmp = (BaseEnemy)currentHuntingTarget;
                    if (tmp.health <= 0)
                    {
                        currentHuntingTarget = null;
                        justBeingShot = false;
                        return;
                    }
                }

                if (PoseidonGame.playTime.TotalSeconds - prevFire.TotalSeconds > timeBetweenFire / speedFactor)
                {
                    if (!clipPlayer.inRange(31, 60))
                        clipPlayer.switchRange(31, 60);
                    if (currentHuntingTarget.GetType().Name.Equals("HydroBot"))
                    {
                        if (!(HydroBot.invincibleMode || HydroBot.supersonicMode))
                        {
                            HydroBot.currentHitPoint -= damage;

                            Point point = new Point();
                            String point_string = "-" + 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);

                            PoseidonGame.audio.botYell.Play();
                            PlayGameScene.healthLost += damage;
                        }
                        if (HydroBot.autoHipnotizeMode)
                        {
                            setHypnotise();
                        }
                        if (HydroBot.autoExplodeMode)
                        {
                            PoseidonGame.audio.Explo1.Play();
                            if (gameMode == GameMode.MainGame)
                                PlayGameScene.gameCamera.Shake(12.5f, .2f);
                            else if (gameMode == GameMode.ShipWreck)
                                ShipWreckScene.gameCamera.Shake(12.5f, .2f);
                            else if (gameMode == GameMode.SurvivalMode)
                                SurvivalGameScene.gameCamera.Shake(12.5f, .2f);

                            CastSkill.UseThorHammer(hydroBot.Position, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, (BaseEnemy[])enemies, ref enemiesAmount, fishes, fishAmount, HydroBot.gameMode, true);
                        }
                    }
                    if (currentHuntingTarget is SwimmingObject)
                    {
                        ((SwimmingObject)currentHuntingTarget).health -= damage;
                        if (currentHuntingTarget.BoundingSphere.Intersects(cameraFrustum))
                        {
                            if (currentHuntingTarget is Fish)
                                PoseidonGame.audio.animalYell.Play();
                            Point point = new Point();
                            String point_string = "-" + damage.ToString() + "HP";
                            point.LoadContent(PoseidonGame.contentManager, point_string, currentHuntingTarget.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);
                        }
                    }
                    prevFire = PoseidonGame.playTime;

                    if (this.BoundingSphere.Intersects(cameraFrustum))
                        PoseidonGame.audio.slashSound.Play();
                }
            }
        }