예제 #1
0
        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);
        }
예제 #2
0
 public bool CanSee(GameObject otherGuy)
 {
     return GetAngle(GetDirection(otherGuy), Vector2.UnitY) - rotation < VISION_FIELD
         && DistanceFrom(otherGuy) < VISION_LENGTH;
 }
예제 #3
0
        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);
        }
예제 #4
0
 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;
 }
예제 #5
0
 protected void CollideTop(GameObject problemTile)
 {
     this.Position.Y = problemTile.BottomRectangle.Bottom;
     this.Velocity.Y = 0;
 }