public override void Attack(GameObject source, Vector3 contactPoint, float AttackArg1, float AttackArg2, float AttackArg3, float AttackArg4, Collider collider, GameObject effect, GameObject effect2) { //float explosionRadius, float explosionPower, float upwardForce, float explosionDirectDamge Collider[] colliders = Physics.OverlapSphere(contactPoint, AttackArg1); Debug.Log("Number of colliders " + colliders.Length); try{ foreach (Collider hit in colliders) { IExplodable explodableObject = hit.GetComponent <IExplodable>(); Debug.Log("Tag: " + hit.tag); if (explodableObject != null && !explodableObject.HasExploded()) { Debug.Log("explodable collider"); explodableObject.TakeExplosion(AttackArg2, contactPoint, AttackArg1, AttackArg3, AttackArg4); } else if (string.Compare(hit.tag, "Enemy") == 0) { IExplodable explodableObject2 = hit.transform.parent.parent.parent.parent.GetComponent <IExplodable>(); if (explodableObject2 != null && !explodableObject2.HasExploded()) { explodableObject2.TakeExplosion(AttackArg2, contactPoint, AttackArg1, AttackArg3, AttackArg4); } } } }catch (NullReferenceException e) {} Destroy(Instantiate(effect.gameObject, source.transform.position, Quaternion.identity) as GameObject, 2f); //Destroy(source); source.SetActive(false); }
public void Explode() { Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, explosionRange); for (int i = 0; i < colliders.Length; i++) { IExplodable explodable = colliders[i].gameObject.GetComponent <IExplodable>(); if (explodable != null) { try { explodable.ActivateFromExplosion(); } catch { } } CirclePlayer2D playerScript = colliders[i].gameObject.GetComponent <CirclePlayer2D>(); if (playerScript != null) { try { playerScript.JumpReaction((Vector2)transform.position); } catch { } } } AnimateExplosion(); }
public GameState NextState(GameState state, Position position) { if (MoveLegal(state, position)) { GameState newState = state.Copy(Width, Height); newState.Fields[FieldIndex(position.x, position.y)] = (FieldState)newState.CurrentPlayer; if (state.Fields[FieldIndex(position.x, position.y)] == FieldState.Hidden) { int hiddenCount = state.CountHiddenFields(); int randValue = rand.Next(0, hiddenCount); // TODO: Improve on this method IExplodable currentBomb = null; if (randValue < state.BigBombsRemaining) { currentBomb = bigBomb; newState.BigBombsRemaining--; } else if (randValue < state.BigBombsRemaining + state.PlusBombsRemaining) { currentBomb = plusBomb; newState.PlusBombsRemaining--; } if (currentBomb != null) { foreach (var exploded in currentBomb.Explode(position, Width, Height)) { newState.Fields[FieldIndex(exploded.x, exploded.y)] = newState.Fields[FieldIndex(exploded.x, exploded.y)] != FieldState.Hidden ? FieldState.None : FieldState.Hidden; } } } newState.CurrentPlayer = newState.CurrentPlayer == PlayerType.Noughts ? PlayerType.Crosses : PlayerType.Noughts; return(newState); } throw new IllegalMoveException(); }
/// <summary> /// Create a command object. /// </summary> /// <param name="agent">The agent whos data will be passed to explosion spawned instances and then remove from the map.</param> /// <param name="explodable">The explodable object that will be exploded. Usually, set to the agent if it implements the interface.</param> /// <returns></returns> public static ICommand Create(IAgent agent, IExplodable explodable) { return(new ExplodeAgent { agent = agent, explodable = explodable }); }
public void TestIsFatherBomb() { IMineFactory mineCreator = new MineCreator(); IExplodable fatherBomb = mineCreator.CreateMine(MinePower.Five); // Should return 'Father Bomb' bool isFatherBomb = fatherBomb is FatherBomb; Assert.IsTrue(isFatherBomb); }
public void TestIsLandMine() { IMineFactory mineCreator = new MineCreator(); IExplodable landMine = mineCreator.CreateMine(MinePower.Two); // Should return 'Land Mine' bool isLandMine = landMine is LandMine; Assert.IsTrue(isLandMine); }
public void TestIsNavelMine() { IMineFactory mineCreator = new MineCreator(); IExplodable navelMine = mineCreator.CreateMine(MinePower.Three); // Should return 'Navel Mine' bool isNavelMine = navelMine is NavelMine; Assert.IsTrue(isNavelMine); }
public void Explode(IExplodable Target) { if (Target is Order == false) { throw new ArgumentException(); } this.Order = Target as Order; ExplodeContent(); }
public void CreateMineShouldReturnProperMines() { IMineFactory mineCreator = new MineCreator(); IExplodable lumpetByCreator = mineCreator.CreateMine(MinePower.One); // Should return 'Lumpet Mine' IExplodable nuclearByCreator = mineCreator.CreateMine(MinePower.Four); // Should return 'Nuclear Mine'; bool isLumpet = lumpetByCreator is LimpetMine; bool isNuclear = nuclearByCreator is NuclearMine; Assert.IsTrue(isLumpet && isNuclear); }
//collider is switched to a trigger upon explosion void OnTriggerEnter2D(Collider2D col) { //if any IExplodables are caught in the blast radius, call their Explode methods IExplodable explodable = col.GetComponent(typeof(IExplodable)) as IExplodable; if (explodable != null) { explodable.Explode(); } }
public void Explode(IExplodable Target) { if(Target is Order == false) { throw new ArgumentException(); } this.Order = Target as Order; ExplodeContent(); }
public void Explode(IExplodable Target) { if (Target is Element == false) { throw new ArgumentException(); } this.Target = Target as Element; ExplodeContent(); GetContent(); }
//collider starts off as solid void OnCollisionEnter2D(Collision2D col) { //if the grenade collides with something explodable, start exploding IExplodable explodable = col.gameObject.GetComponent(typeof(IExplodable)) as IExplodable; if (explodable != null) { Explode(); explodable.Explode(); } }
public static void CreateExplosion(Vector3 pos, float explosionRadius, float damage, TeamTypes explosionBy) { Collider[] cols = Physics.OverlapSphere(pos, explosionRadius); foreach (Collider col in cols) { IExplodable explodable = col.GetComponent <IExplodable>(); if (explodable != null) { explodable.OnExpload(pos, explosionRadius, damage); } } }
public void Explode(IExplodable Target) { if(Target is Element == false) { throw new ArgumentException(); } this.Target = Target as Element; ExplodeContent(); GetContent(); }
private void collidePixelByRange(IExplodable i_Collidable) { Color[] sourcePixels = getPixelsData(i_Collidable); for (int y = m_IntersectionRectangle.Top; y < m_IntersectionRectangle.Bottom; y++) { for (int x = m_IntersectionRectangle.Left; x < m_IntersectionRectangle.Right; x++) { if (!isTransparent(m_Collidable.Pixels, x, y, m_Collidable.Bounds) && !isTransparent(sourcePixels, x, y, i_Collidable.Bounds)) { m_IntersectionPoints.Add(new Point(x, y)); } } } transpaerntIntersectionPoints(i_Collidable.ExplosionRange); }
/// <summary> /// Creates a mine based on the given MinePower. /// </summary> /// <param name="power">Accepts MinePower enumeration.</param> /// <returns>Returns an instance of the IMine interface for the current mine power.</returns> public override IExplodable CreateMine(MinePower power) { IExplodable mineToReturn = null; if (this.createdMines.ContainsKey(power)) { mineToReturn = this.createdMines[power]; } else { switch (power) { case MinePower.One: mineToReturn = new LimpetMine(); break; case MinePower.Two: mineToReturn = new LandMine(); break; case MinePower.Three: mineToReturn = new NavelMine(); break; case MinePower.Four: mineToReturn = new NuclearMine(); break; case MinePower.Five: mineToReturn = new FatherBomb(); break; default: throw new ArgumentException(string.Format("Mine with power: {0}, does not exists YET!", power)); } this.createdMines.Add(power, mineToReturn); } return(mineToReturn); }
void OnCollisionEnter(Collision collision) { Vector3 explosionPoint; if (string.Compare(collision.collider.tag, "Wall") != 0) { IDamageable damageableObject = collision.collider.GetComponent <IDamageable>(); explosionPoint = collision.GetContact(0).point; Collider[] colliders = Physics.OverlapSphere(explosionPoint, 5f); Debug.Log("Number of colliders " + colliders.Length); try{ foreach (Collider hit in colliders) { IExplodable explodableObject = hit.GetComponent <IExplodable>(); Debug.Log("Tag: " + hit.tag); if (explodableObject != null && !explodableObject.HasExploded()) { Debug.Log("explodable collider"); explodableObject.TakeExplosion(400f, explosionPoint, 8f, 10f, 10f); } else if (string.Compare(hit.tag, "Enemy") == 0) { IExplodable explodableObject2 = hit.transform.parent.parent.parent.parent.GetComponent <IExplodable>(); if (explodableObject2 != null && !explodableObject2.HasExploded()) { explodableObject2.TakeExplosion(400f, explosionPoint, 8f, 10f, 10f); } } } }catch (NullReferenceException e) {} Destroy(Instantiate(explosionEffect.gameObject, transform.position, Quaternion.identity) as GameObject, 2f); Destroy(gameObject); } }
public void SetMine(IExplodable mine) { this.currentMine = mine; }
public ExplosionManager(GameField gameField) { currentMine = null; currentPosition = null; this.gameField = gameField; }
public void CreateMineWithInvaludPowerShouldThrowExeption() { IMineFactory mineCreator = new MineCreator(); IExplodable lumpetByCreator = mineCreator.CreateMine(new MinePower()); // Hack the mine system }
public static void Remove(IExplodable explodable) { Explodables.Remove(explodable); }
public static void Add(IExplodable explodable) { Explodables.Add(explodable); }