private void OnTouchMove(Event e) { if (Map != null && e is TouchEvent) { var te = (TouchEvent)e; if (te != null && te.Touches != null) { if (te.Touches.Length == 1) { Touch t = te.Touches[0]; LastMousePos.Set(t.ClientX, t.ClientY); Map.OnMove(t.ClientX, t.ClientY); } else if (te.Touches.Length == 2) { Touch t1 = te.Touches[0]; Touch t2 = te.Touches[1]; Vec2i t1Pos = new Vec2i(t1.ClientX, t1.ClientY); Vec2i t2Pos = new Vec2i(t2.ClientX, t2.ClientY); Vec2i mid = (t1Pos + t2Pos) / 2; double distance = Vec2i.Distance(t1Pos, t2Pos); double delta = LastPinchGestureDistance - distance; LastPinchGestureDistance = distance; Map.ZoomMap(mid.x, mid.y, delta * -ZOOM_SPEED); } if (te.Touches.Length > 1) { e.PreventDefault(); } } } }
private void OnTouchStart(Event e) { if (Map != null && e is TouchEvent) { var te = (TouchEvent)e; if (te != null && te.Touches != null) { if (te.Touches.Length == 1) { Touch t = te.Touches[0]; LastMousePos.Set(t.ClientX, t.ClientY); Map.OnPress(t.ClientX, t.ClientY); } else if (te.Touches.Length == 2) { Touch t1 = te.Touches[0]; Touch t2 = te.Touches[1]; Vec2i t1Pos = new Vec2i(t1.ClientX, t1.ClientY); Vec2i t2Pos = new Vec2i(t2.ClientX, t2.ClientY); double distance = Vec2i.Distance(t1Pos, t2Pos); LastPinchGestureDistance = distance; } } } }
public void DistanceIsCorrectlyCalculatedFromTwoVectors(int ax, int ay, int bx, int by) { Vec2i a = new Vec2i(ax, ay); Vec2i b = new Vec2i(bx, by); double distance = Math.Sqrt(Math.Pow((double)(bx - ax), 2.0) + Math.Pow((double)(by - ay), 2.0)); Assert.True(Vec2i.Distance(a, b) == distance && Vec2i.Distance(b, a) == distance); }
public void NullVectorParameterInDistanceOperatorCausesException() { Vec2i a = new Vec2i(1, 2); Assert.Throws <ArgumentNullException>(() => Vec2i.Distance(a, null)); Assert.Throws <ArgumentNullException>(() => Vec2i.Distance(null, a)); Assert.Throws <ArgumentNullException>(() => Vec2i.Distance(null, null)); }
/// <summary> /// Generates a new path from the current position to the specified end /// </summary> /// <param name="end">The target destination for this entity group</param> public void GenerateNewPath(Vec2i end) { int pathDist = (int)end.Distance(CurrentChunk); CurrentPosition = CurrentChunk.AsVector2(); /*if (pathDist < 32) * Path = WorldEventManager.Instance.PathFinder.GeneratePath(CurrentChunk, end); * else*/ Path = WorldEventManager.Instance.GeneratePath(CurrentChunk, end); EndChunk = end; CurrentPathIndex = 0; }
/// <summary> /// Searches for a target player that is within range and is in the line of sight. /// </summary> public void TargetSearch() { Enemy searchee = (Enemy)base.gameObject.GetComponent <Enemy>(); bool targetUpdated = false; if (searchee == null) { Debug.LogError("Aggro component needs an an enemy object."); return; } //If the enemy is close enough to the player, it saves the location it has seen the //player at and set the boolean that is has seen the player. Player player = Player.MainPlayer(); if (player != null && Vec2i.Distance(player.transform.position, transform.position) < aggroRange) { if ((searchee is IXRayVision && ((IXRayVision)searchee).HasVision) || CheckLine(transform.position, player.transform.position)) { // OnAggro. gameObject.SendMessage <IAggressive>("OnAggro", new object[] { player.gameObject }); //searchee.target = player.transform; targetUpdated = true; seenTarget = true; secondsSinceLastSeen = 0; } } //If the enemy can't see the player but has seen the player before. It checks how long //since the last time it has seen the player. If it has been too long, it sets the boolean //to false. if (seenTarget && !targetUpdated) { secondsSinceLastSeen += ((float)Time.deltaMs / 1000.0f); if (secondsSinceLastSeen > secondsBeforeGivesUp) { // OnDegggro //searchee.target = null; gameObject.SendMessage <IAggressive>("OnDeaggro"); seenTarget = false; } } return; }