// *********************** // // On Check handlers: // *********************** // // On target hit: bool OnCheck_IsTargetHit(CProjectile p) { // fill target coordinates: // there are 4 hit coordinates, each one is in the corner of projectile: int[] x = { 0, 0, 0, 0 }; int[] y = { 0, 0, 0, 0 }; x[0] = (int)((p.X + 3) / cellSize); x[1] = x[0]; x[2] = (int)((p.X + 4) / cellSize);; x[3] = x[2]; y[0] = (int)((p.Y + 3) / cellSize); y[1] = (int)((p.Y + 4) / cellSize); y[2] = y[0]; y[3] = y[1]; // Targets: IGameObject[] destroyable = new IGameObject[4]; // hit flag: bool object_hit = false; // Check targets on map: for (int i = 0; i < 4; i++) { // Getting object: var o = this.mapMain[x[i], y[i]]; // Check if it shoud be hit: if ((o != null) && (o != p.Owner) && (o != this.emptyArea) && !(o is CWater)) { // Enemies cant kill each other: if (!((o is CTankEnemy) && (p.Owner is CTankEnemy))) { if (!destroyable.Contains(o)) { // Detecting a hit: object_hit = true; p.Explode = true; if (!((p.Owner is CTankPlayer) && (o is CTankPlayer))) { // Hitting object: o.Hit(p); // Blowing up projectile: if ((o.Destroyed) && (o is CTankEnemy)) { (p.Owner as CTankPlayer).AddHit((o as CTank).TankID); } p.Explode = ((o as CTank != null) && (o as CTank).Invincible) ? false : true; //if ((o as CTank != null) && (o as CTank).Invincible) p.Explode = false; // Adding to targets: destroyable[i] = o; } } } } } ; return(object_hit); }