// ReSharper disable once UnusedMethodReturnValue.Global public List <AShip> Retrieve(List <AShip> returnObjects, AShip ship) { var index = GetIndex(ship); if (index != -1 && mNodes[0] != null) { mNodes[index].Retrieve(returnObjects, ship); } returnObjects.AddRange(mObjects); return(returnObjects); }
/// <summary> /// Inserts the object to the correct Node. /// </summary> public void Insert(AShip ship) { if (mNodes[0] != null) { var index = GetIndex(ship); if (index != -1) { mNodes[index].Insert(ship); return; } } mObjects.Add(ship); if (mObjects.Count > MaxObjects && mLevel < MaxLevels) { if (mNodes[0] == null) { Split(); } var i = 0; while (i < mObjects.Count) { var index = GetIndex(mObjects[i]); if (index != -1) { mNodes[index].Insert(mObjects[i]); mObjects.RemoveAt(i); } else { i++; } } } }
/// <summary> /// Returns the index of the node, where the Ship is. -1 if its between 2 nodes. /// </summary> private int GetIndex(AShip ship) { int index = -1; double verticalMidpoint = mBounds.X + (mBounds.Width / 2); double horizontalMidpoint = mBounds.Y + (mBounds.Height / 2); // Object can completely fit within the top quadrants bool topQuadrant = (ship.Position.Y < horizontalMidpoint && ship.Position.Y + ship.mShipTexture.Height < horizontalMidpoint); // Object can completely fit within the bottom quadrants bool bottomQuadrant = (ship.Position.Y > horizontalMidpoint); // Object can completely fit within the left quadrants if (ship.Position.X < verticalMidpoint && ship.Position.X + ship.mShipTexture.Width < verticalMidpoint) { if (topQuadrant) { index = 1; } else if (bottomQuadrant) { index = 2; } } // Object can completely fit within the right quadrants else if (ship.Position.X > verticalMidpoint) { if (topQuadrant) { index = 0; } else if (bottomQuadrant) { index = 3; } } return(index); }
public void Attack(AShip target) { CurrentBState = ShipBattleState.Attacking; TargetShip = target; }
public void Attack(AShip targetShip) { TargetShip = targetShip; CurrentBState = ShipBattleState.Attacking; }
public void Enter(AShip ship) { CurrentBState = ShipBattleState.Entering; TargetShip = ship; }
/// <summary> /// Compares two ships by their distance to the fleets main position. /// </summary> private int CompareShipsByDistance(AShip ship1, AShip ship2) { return(Vector2.Distance(Position, ship1.Position) > Vector2.Distance(Position, ship2.Position) ? 1 : 0); }
public void Enter(AShip targetShip) { TargetShip = targetShip; CurrentBState = ShipBattleState.Entering; }