/// <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; } }
public virtual void Release() { _isDead = true; for (int i = 0; i < _components.Count; i++) { _components[i].Release(); } _components.Clear(); SnakerNode node = _head; while (node != null) { // release node... node.Release(); node = node.NextNode; } _head = null; _tail = null; hitNode = null; enegy = 0; _ownerPlayer = null; _view = null; }
public void Release() { _id = 0; _nextNode = null; _owner = null; _view = null; }
public override void Release() { base.Release(); _aiType = 0; _curState = State.Wait; _owner = null; map = null; hitNode = null; }
public void Bind(SnakerNode model) { _model = model; Vector3 scale = new Vector3(1f, 1f, 1f); scale.x = _model.Radius * 2f / _render.sprite.texture.width; scale.y = _model.Radius * 2f / _render.sprite.texture.height; CachedTransform.localScale = scale; DoUpdate(0f); }
SnakerNodeView CreateNode(SnakerNode node) { GameObject prefab = Resources.Load <GameObject>(node.Data["Prefab"].StringValue); GameObject go = Instantiate <GameObject>(prefab); go.name = prefab.name; go.transform.SetParent(CachedTransform); SnakerNodeView result = go.EnsureComponent <SnakerNodeView>(); result.Bind(node); return(result); }
internal void AddNode(int count, Vector3 initPos) { if (IsDead) { return; } for (int i = 0; i < count; i++) { _ownerPlayer.snakerData.length++; SnakerNode node = new SnakerNode(); node.InitData(_data["Body"].IntValue, _ownerPlayer.snakerData.length, this, initPos); // add the new node to the previous pos of _tail. _tail.PrevNode.SetNextNode(node); node.SetNextNode(_tail); _tail.SetPrevNode(node); } }
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; } } }
public Snaker(PlayerData player, Vector3 initPos, float initSpeed = 0f) { _ownerPlayer = player; // load table _data = CSVTableLoader.GetTableContainer("Snaker").GetRow(player.snakerData.id.ToString()); _head = new SnakerHead(); _head.InitData(_data["Head"].IntValue, 0, this, initPos); _tail = new SnakerTail(); _tail.InitData(_data["Tail"].IntValue, 0, this, initPos); _head.SetNextNode(_tail); _tail.SetPrevNode(_head); _components = new List <SnakerComponent>(); if (_ownerPlayer.aiID > 0) { SnakerAI ai = new SnakerAI(this, _ownerPlayer.aiID); _components.Add(ai); } _isDead = false; // input _moveSpeed = initSpeed; _inputDirection = new Vector3(); _moveDirection = new Vector3(0f, 1f, 0f); enegy = 0; pre_length = -1; pre_count = 0; hitNode = null; // init snaker nodes AddNode(InitLength, initPos); }
public override void Unbind() { base.Unbind(); _model = null; }
public void SetNextNode(SnakerNode node) { _nextNode = node; }
public void SetPrevNode(SnakerNode node) { prevNode = node; }