/// <summary> /// Snaker src collides to other. /// </summary> public static bool HitTest(Snaker src, Snaker other, ref SnakerNode hitNode, bool ignoreTeam = false) { hitNode = null; if (src == null || other == null || src.IsDead || other.IsDead) { return(false); } if (ignoreTeam || src.TeamID != other.TeamID) { SnakerNode node = other.Head.NextNode; // start from Head's next node while (node != null) { if (node.IsKeyNode()) { float distance = Vector3.Distance(src.Head.Position, node.Position); if (distance <= src.Head.Radius + node.Radius) { hitNode = node; return(true); } } node = node.NextNode; } } return(false); }
protected virtual void Blast() { Framework.Random random = BattleEngine.Instance.Context.Random; SnakerNode node = _head; while (node != null) { if (node.IsKeyNode()) { node.Blast(); float blastChange = node.Data["Blast Chance"].FloatValue; int foodID = node.Data["Blast Food"].IntValue; if (foodID > 0 && blastChange > 0f && random.Value() < blastChange) { Rect bound = BattleEngine.Instance.Map.BoundRect; float radius = node.Radius; Vector2 pos = new Vector2(); pos.x = node.Position.x + random.Range(-radius, radius); pos.y = node.Position.y + random.Range(-radius, radius); if (bound.Contains(pos)) { BattleEngine.Instance.CreateFoodAt(foodID, pos.ToVector3()); } } } node = node.NextNode; } }
void SyncNodeList() { if (_nodeList.Count != _model.GetKeyNodeCount()) { SnakerNode node = _model.Head.NextNode; while (node != null) { if (node != _model.Tail && node.View == null && node.IsKeyNode()) { SnakerNodeView _node = CreateNode(node); _node.CachedTransform.SetParent(CachedTransform); node.View = _node; _nodeList.Add(_node); } node = node.NextNode; } } }