public void Release() { _id = 0; _nextNode = null; _owner = null; _view = null; }
/// <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); }
public SnakerAI(Snaker owner) : base(owner) { _aiType = 0; _curState = State.Wait; _curFrame = 0; curStateEndFrame = 0; }
public SnakerAI(Snaker owner, int aiType) : base(owner) { _aiType = aiType; _curState = State.Wait; _curFrame = 0; curStateEndFrame = 0; _curTarget = null; }
public void SetFocusSnaker(int playerId) { _focusPlayerId = playerId; if (_focusPlayerId <= 0) { _focusSnaker = null; } }
void OnSnakerDead(Snaker snaker, object killer) { if (_focusPlayerId == snaker.PlayerID) { _focusPlayerId = 0; SyncGameCamera(); } }
public void InitData(int id, int index, Snaker owner, Vector3 initPos) { _id = id; _index = index; _owner = owner; _data = CSVTableLoader.GetTableContainer("SnakerNode").GetRow(_id.ToString()); _radius = _data["Radius"].IntValue; _prePosition = _position = initPos; }
private void AddSnaker(Snaker snaker) { if (_snakerList.ContainsKey(snaker.PlayerID)) { this.LogError("You are trying to add a duplicated snaker " + snaker.PlayerID.ToString()); } else { _snakerList[snaker.PlayerID] = snaker; } }
internal Snaker CreateSnaker(PlayerData data, Vector3 pos, float speed = 0f) { if (data == null) { return(null); } Snaker snaker = new Snaker(data, pos, speed); // Debuger.Log("BattleEngine", "CreateSnaker: {0}", data.playerID); tobeAddSnakerList.Add(snaker); return(snaker); }
public override void Unbind() { base.Unbind(); _model = null; DestroyNode(_head); DestroyNode(_tail); for (int i = 0; i < _nodeList.Count; i++) { DestroyNode(_nodeList[i]); } _nodeList.Clear(); }
/// <summary> /// Snaker src collides to food. /// </summary> public static bool HitTest(Snaker src, Food food) { if (src == null || food == null || src.IsDead || food.IsReleased) { return(false); } float distance = Vector3.Distance(src.Head.Position, food.Position); if (distance <= src.Head.Radius + food.Radius) { return(true); } return(false); }
public void Bind(Snaker model) { _model = model; _nodeList.Clear(); _head = CreateNode(_model.Head); _head.CachedTransform.SetParent(CachedTransform); _tail = CreateNode(_model.Tail); _tail.CachedTransform.SetParent(CachedTransform); SyncNodeList(); DoUpdate(0f); }
protected bool CheckNextHitSnaker(Vector3 nextPos, ref Vector3 outValue) { outValue.x = outValue.y = outValue.z = 0f; foreach (var kvs in BattleEngine.Instance.SnakerList) { if (kvs.Value != _owner) { if (Snaker.HitTest(_owner, kvs.Value, ref hitNode)) { outValue = nextPos - hitNode.Position; return(true); } } } return(false); }
private SnakerActor CreateSnaker(Snaker snaker) { if (snaker == null) { return(null); } GameObject prefab = Resources.Load <GameObject>(snaker.Data["Prefab"].StringValue); GameObject go = Instantiate <GameObject>(prefab); go.name = prefab.name + "_" + snaker.PlayerID.ToString(); go.transform.SetParent(Root); SnakerActor view = go.EnsureComponent <SnakerActor>(); view.Bind(snaker); return(view); }
public void InputVKey(int vkey, float arg, int playerId) { if (!_isRunning) { return; } Snaker snaker = GetSnakerByID(playerId); if (snaker != null) { snaker.InputKey(vkey, arg); } else { HandleOtherInput(vkey, arg, playerId); } }
void LateUpdate() { if (BattleEngine.Instance.isRunning) { if (_focusSnaker == null && _focusPlayerId > 0) { _focusSnaker = BattleEngine.Instance.GetSnakerByID(_focusPlayerId); } if (_focusSnaker != null) { Vector3 pos = BattleView.Instance.EntityToViewPos(_focusSnaker.Head.Position); if (_tran.localPosition != pos) { Vector3 targetPos = _tran.localPosition; targetPos.x = pos.x; targetPos.y = pos.y; _tran.localPosition = ClampPosition(targetPos); //_tran.localPosition = Vector3.MoveTowards(_tran.localPosition, targetPos, Time.deltaTime * moveSmooth); } } } }
void OnDestroy() { current = null; _focusSnaker = null; }
public void Reset() { _focusPlayerId = 0; _focusSnaker = null; }
public SnakerComponent(Snaker owner) { _owner = owner; }
public virtual void Release() { _owner = null; }
public bool EnableRevive() { Snaker snaker = BattleEngine.Instance.GetSnakerByID(_mainPlayerId); return(snaker != null && snaker.IsDead); }
public void OnSnakerDead(Snaker snaker, object killer) { Context.Game.OnPlayerDie(snaker.PlayerID); EventManager.Instance.SendEvent <Snaker, object>("OnSnakerDead", snaker, killer); }