/// <summary> /// Check what a projectile hit. The possibilities are: /// Nothing hit, Hit enemy, Hit self, hit own/enemy's crate. /// </summary> /// <param name="projectile">The projectile for which to /// perform the check.</param> /// <returns>A result inidicating what, if anything, was hit</returns> private HitCheckResult CheckHit(Projectile projectile) { HitCheckResult hitRes = HitCheckResult.Nothing; // Build a sphere around a projectile Vector3 center = new Vector3(projectile.ProjectilePosition, 0); BoundingSphere sphere = new BoundingSphere(center, Math.Max(projectile.ProjectileTexture.Width / 2, projectile.ProjectileTexture.Height / 2)); // Check Self-Hit - create a bounding box around self Vector3 min = new Vector3(catapultPosition, 0); Vector3 max = new Vector3(catapultPosition + new Vector2(animations["Fire"].FrameSize.X, animations["Fire"].FrameSize.Y), 0); BoundingBox selfBox = new BoundingBox(min, max); // Check enemy - create a bounding box around the enemy min = new Vector3(enemy.Catapult.Position, 0); max = new Vector3(enemy.Catapult.Position + new Vector2(animations["Fire"].FrameSize.X, animations["Fire"].FrameSize.Y), 0); BoundingBox enemyBox = new BoundingBox(min, max); // Check self-crate - Create bounding box around own crate min = new Vector3(crate.Position, 0); max = new Vector3(crate.Position + new Vector2(crate.Width, crate.Height), 0); BoundingBox selfCrateBox = new BoundingBox(min, max); // Check enemy-crate - Create bounding box around enemy crate min = new Vector3(enemy.Catapult.crate.Position, 0); max = new Vector3(enemy.Catapult.crate.Position + new Vector2(enemy.Catapult.crate.Width, enemy.Catapult.crate.Height), 0); BoundingBox enemyCrateBox = new BoundingBox(min, max); // Check self hit if (sphere.Intersects(selfBox) && currentState != CatapultState.HitKill) { AudioManager.PlaySound("catapultExplosion"); // Launch hit animation sequence on self UpdateHealth(self, sphere, selfBox); if (self.Health <= 0) { Hit(true); enemy.Score++; } hitRes = HitCheckResult.SelfCatapult; } // Check if enemy was hit else if (sphere.Intersects(enemyBox) && enemy.Catapult.CurrentState != CatapultState.HitKill && enemy.Catapult.CurrentState != CatapultState.Reset) { AudioManager.PlaySound("catapultExplosion"); // Launch enemy hit animaton UpdateHealth(enemy, sphere, enemyBox); if (enemy.Health <= 0) { enemy.Catapult.Hit(true); self.Score++; } hitRes = HitCheckResult.EnemyCatapult; currentState = CatapultState.Reset; } // Check if own crate was hit else if (sphere.Intersects(selfCrateBox)) { hitRes = HitCheckResult.SelfCrate; } // Check if enemy crate was hit else if (sphere.Intersects(enemyCrateBox)) { hitRes = HitCheckResult.EnemyCrate; } return(hitRes); }
/// <summary> /// Check what a projectile hit. The possibilities are: /// Nothing hit, Hit enemy, Hit self, hit own/enemy's crate. /// </summary> /// <param name="projectile">The projectile for which to /// perform the check.</param> /// <returns>A result inidicating what, if anything, was hit</returns> private HitCheckResult CheckHit(Projectile projectile) { HitCheckResult hitRes = HitCheckResult.Nothing; // Build a sphere around a projectile Vector3 center = new Vector3(projectile.ProjectilePosition, 0); BoundingSphere sphere = new BoundingSphere(center, Math.Max(projectile.ProjectileTexture.Width / 2, projectile.ProjectileTexture.Height / 2)); // Check Self-Hit - create a bounding box around self Vector3 min = new Vector3(catapultPosition, 0); Vector3 max = new Vector3(catapultPosition + new Vector2(animations["Fire"].FrameSize.X, animations["Fire"].FrameSize.Y), 0); BoundingBox selfBox = new BoundingBox(min, max); // Check enemy - create a bounding box around the enemy min = new Vector3(enemy.Catapult.Position, 0); max = new Vector3(enemy.Catapult.Position + new Vector2(animations["Fire"].FrameSize.X, animations["Fire"].FrameSize.Y), 0); BoundingBox enemyBox = new BoundingBox(min, max); // Check self-crate - Create bounding box around own crate min = new Vector3(crate.Position, 0); max = new Vector3(crate.Position + new Vector2(crate.Width, crate.Height), 0); BoundingBox selfCrateBox = new BoundingBox(min, max); // Check enemy-crate - Create bounding box around enemy crate min = new Vector3(enemy.Catapult.crate.Position, 0); max = new Vector3(enemy.Catapult.crate.Position + new Vector2(enemy.Catapult.crate.Width, enemy.Catapult.crate.Height), 0); BoundingBox enemyCrateBox = new BoundingBox(min, max); // Check self hit if (sphere.Intersects(selfBox) && currentState != CatapultState.HitKill) { AudioManager.PlaySound("catapultExplosion"); // Launch hit animation sequence on self UpdateHealth(self, sphere, selfBox); if (self.Health <= 0) { Hit(true); enemy.Score++; } hitRes = HitCheckResult.SelfCatapult; } // Check if enemy was hit else if (sphere.Intersects(enemyBox) && enemy.Catapult.CurrentState != CatapultState.HitKill && enemy.Catapult.CurrentState != CatapultState.Reset) { AudioManager.PlaySound("catapultExplosion"); // Launch enemy hit animaton UpdateHealth(enemy, sphere, enemyBox); if (enemy.Health <= 0) { enemy.Catapult.Hit(true); if (self.IsActive) { self.Score++; if (App.g_isTwoHumanPlayers) { Dictionary <string, object> scoreProperties = new Dictionary <string, object>(); if (GlobalContext.PlayerIsFirstOnAppWarp) { GlobalContext.tableProperties["Player1Score"] = self.Score; scoreProperties.Add("Player1Score", self.Score); } else { scoreProperties.Add("Player2Score", self.Score); GlobalContext.tableProperties["Player2Score"] = self.Score; } WarpClient.GetInstance().UpdateRoomProperties(GlobalContext.GameRoomId, scoreProperties, null); } } } hitRes = HitCheckResult.EnemyCatapult; currentState = CatapultState.Reset; } // Check if own crate was hit else if (sphere.Intersects(selfCrateBox)) { hitRes = HitCheckResult.SelfCrate; } // Check if enemy crate was hit else if (sphere.Intersects(enemyCrateBox)) { hitRes = HitCheckResult.EnemyCrate; } return(hitRes); }