public void UpdateGame() { Vec2 targetPos = Target.Pos; if (Vec2.Dist(targetPos, GetComponent <KRTransform>().Pos) == Range) { if (_currentFrame == 0) { _spot.enabled = true; Target.GetComponent <KRHealth>().OnDamageDone(AttackType, Strength); _currentFrame = AttackSpeed; } else { _spot.enabled = false; --_currentFrame; } } else { _krMovement.Move(targetPos); _currentFrame = AttackSpeed; _spot.enabled = false; } }
static void OnLeftClickUp(Vector3 mousePosition) { Vector3 worldPosition = WorldPosition(mousePosition); Vec2 modelPoint = Vec2.FromVector3(worldPosition); if (beginDrag.Dist(modelPoint) < 1) { if (OnDemand != null) { OnDemand(new SelectAction(modelPoint)); } } else { if (OnDemand != null) { Vec2 additionalPoint = Vec2.FromVector3( WorldPosition( new Vector3(mousePosition.x, Camera.main.WorldToScreenPoint(beginDrag.ToVector3()).y, mousePosition.z) ) ); OnDemand(new DragAction(beginDrag, modelPoint, additionalPoint)); } } }
private void DrawTree(IRectTreeNode node, DrawnParams drawTarget, DrawnParams drawActual) { if (node == null) { return; } if (!node.Children().Any()) { return; } var newDrawActual = drawTarget; if (drawns.TryGetValue(node, out var drawn)) { float spd = ClientSize.Width / 50f; newDrawActual = drawn.Approach(spd, 2 * spd, drawTarget); } drawns[node] = newDrawActual; int i = 0; foreach (var child in node.Children()) { var childDrawActual = ComputeChildDrawLocation(node, i, newDrawActual); var pen = Pens.Green; if (_hoveredNode == null && Vec2.Dist(childDrawActual.position, _viewMouse) < 10) { _hoveredNode = child; pen = Pens.Red; } _graphics.DrawLine( pen, newDrawActual.position.x, newDrawActual.position.y, childDrawActual.position.x, childDrawActual.position.y ); if (child.Children().Any()) { var childDrawTarget = ComputeChildDrawLocation(node, i, drawTarget); DrawTree(child, childDrawTarget, childDrawActual); } i++; } }
public override Type Execute() { if (_attack.Target == null) { IEnumerable <GameObject> gameObjects = KRFacade.Around(_krtransform.Pos, 6); foreach (var obj in gameObjects) { if (obj.GetComponent <KRTransform>().PlayerID != _krtransform.PlayerID) { _attack.Attack(obj); return(null); } } return(null); } if (_attack.Target.PlayerID == _krtransform.PlayerID) { _fsm.GetComponent <KRMovement>().Move(_attack.Target.Pos); return(typeof(MovementState)); } if (Vec2.Dist(_attack.Target.Pos, _krtransform.Pos) == _attack.Range) { _attack.UpdateGame(); } else { if (_krmovement != null) { if (_attack.Range == 1) { _krmovement.Follow(_attack.Target); return(typeof(MovementState)); } else { return(typeof(RangeState)); } } return(null); } return(GetType()); }
public override Type Execute() { int dist = Mathf.Abs(Vec2.Dist(_krtransform.Pos, _attack.Target.Pos)); if (dist > _attack.Range) { _krmovement.Move(_attack.Target.Pos); _krmovement.UpdateGame(); } else if (dist == _attack.Range) { return(null); } else { Vec2 nearPos = KRFacade.NearSquareAt(_krtransform.Pos, _attack.Target.Pos, _attack.Range); if (nearPos != null) { _krmovement.Move(nearPos); return(typeof(MovementState)); } } return(GetType()); }