public double DistanceFrom(GameObject otherGuy) { double deltaX = otherGuy.position.X - this.position.X; deltaX *= deltaX; double deltaY = otherGuy.position.Y - this.position.Y; deltaY *= deltaY; return Math.Sqrt(deltaX + deltaY); }
public bool CanSee(GameObject otherGuy) { return GetAngle(GetDirection(otherGuy), Vector2.UnitY) - rotation < VISION_FIELD && DistanceFrom(otherGuy) < VISION_LENGTH; }
public void MoveTowards(GameObject otherGuy) { Vector2 direction = GetDirection(otherGuy); this.position.X += direction.X * this.velocity; this.position.Y += direction.Y * this.velocity; this.rotation = GetAngle(direction, Vector2.UnitY); }
private Vector2 GetDirection(GameObject otherGuy) { Vector2 direction = new Vector2(otherGuy.position.X - this.position.X, otherGuy.position.Y - this.position.Y); direction.Normalize(); return direction; }
protected void CollideTop(GameObject problemTile) { this.Position.Y = problemTile.BottomRectangle.Bottom; this.Velocity.Y = 0; }