Esempio n. 1
0
 public void SetPosition(int x, int y)
 {
     this.x = x;
     this.y = y;
     if (dependentSprite != null)
     {
         dependentSprite.SetPosition(x, y);
     }
 }
Esempio n. 2
0
        void NavigateTick(object sender, TickEventArgs e)
        {
//			totalElapsed += e.TicksElapsed;

            if (totalElapsed < millisDelay)
            {
                return;
            }

            sprite.Invalidate();
            pixel_x += delta_x;
            pixel_y += delta_y;
            if (dest_pixel_x - pixel_x < 2)
            {
                pixel_x = dest_pixel_x;
            }
            if (dest_pixel_y - pixel_y < 2)
            {
                pixel_y = dest_pixel_y;
            }
            sprite.SetPosition(pixel_x, pixel_y);
            sprite.Invalidate();

            x = pixel_x << 2;
            y = pixel_y << 2;

            if (pixel_x == dest_pixel_x && pixel_y == dest_pixel_y)
            {
                startCurrentSegment = endCurrentSegment;
                navigatePath.RemoveAt(0);

                // if we're at the destination, remove the tick handler
                if (navigatePath.Count == 0)
                {
                    sprite.RunScript(AnimationType.WalkingToIdle);
                    Game.Instance.Tick -= NavigateTick;
                }
                else
                {
                    endCurrentSegment = navigatePath[0];

                    sprite.Face(ClassifyDirection(startCurrentSegment, endCurrentSegment));

                    dest_pixel_x = endCurrentSegment.X * 4 + 4;
                    dest_pixel_y = endCurrentSegment.Y * 4 + 4;

                    delta_x = dest_pixel_x - pixel_x;
                    delta_y = dest_pixel_y - pixel_y;
                }
            }
        }