Ejemplo n.º 1
0
        public void Move_multiples(int direction, int multiples)
        {
            if (multiples <= 0)
            {
                multiples = 1;
            }
            Vector2f v = Field2D.GetDirection(direction);

            Move(v.X() * multiples, v.Y() * multiples);
        }
Ejemplo n.º 2
0
        public override void OnLoad()
        {
            this.startX = original.GetX();
            this.startY = original.GetY();
            float dx = endX - startX;
            float dy = endY - startY;

            this.vx  = dx / speed;
            this.vy  = 1 / speed * (dy - 1.0f / 2.0f * gravity * speed * speed);
            this.dir = Field2D.GetDirection(MathUtils.Atan2(endX - startX, endY
                                                            - startY));
        }
Ejemplo n.º 3
0
        public override void Update(long elapsedTime)
        {
            if (timer.Action(elapsedTime))
            {
                isMoving = MoveState();

                if (tiles == null || findPath == null)
                {
                    return;
                }
                if (IsComplete())
                {
                    return;
                }

                lock (findPath)
                {
                    if (endX == startX && endY == startY)
                    {
                        if (findPath != null)
                        {
                            if (findPath.Count > 1)
                            {
                                Vector2f moveStart = findPath[0];
                                Vector2f moveEnd   = findPath[1];
                                startX    = tiles.TilesToPixelsX(moveStart.X());
                                startY    = tiles.TilesToPixelsY(moveStart.Y());
                                endX      = moveEnd.X() * tiles.GetTileWidth();
                                endY      = moveEnd.Y() * tiles.GetTileHeight();
                                moveX     = moveEnd.X() - moveStart.X();
                                moveY     = moveEnd.Y() - moveStart.Y();
                                direction = Field2D.GetDirection(moveX, moveY);
                                findPath.RemoveAt(0);
                            }
                            else
                            {
                                findPath.Clear();
                            }
                        }
                    }
                    switch (direction)
                    {
                    case Field2D.TUP:
                        startY -= speed;
                        if (startY < endY)
                        {
                            startY = endY;
                        }
                        break;

                    case Field2D.TDOWN:
                        startY += speed;
                        if (startY > endY)
                        {
                            startY = endY;
                        }
                        break;

                    case Field2D.TLEFT:
                        startX -= speed;
                        if (startX < endX)
                        {
                            startX = endX;
                        }
                        break;

                    case Field2D.TRIGHT:
                        startX += speed;
                        if (startX > endX)
                        {
                            startX = endX;
                        }
                        break;

                    case Field2D.UP:
                        startX += speed;
                        startY -= speed;
                        if (startX > endX)
                        {
                            startX = endX;
                        }
                        if (startY < endY)
                        {
                            startY = endY;
                        }
                        break;

                    case Field2D.DOWN:
                        startX -= speed;
                        startY += speed;
                        if (startX < endX)
                        {
                            startX = endX;
                        }
                        if (startY > endY)
                        {
                            startY = endY;
                        }
                        break;

                    case Field2D.LEFT:
                        startX -= speed;
                        startY -= speed;
                        if (startX < endX)
                        {
                            startX = endX;
                        }
                        if (startY < endY)
                        {
                            startY = endY;
                        }
                        break;

                    case Field2D.RIGHT:
                        startX += speed;
                        startY += speed;
                        if (startX > endX)
                        {
                            startX = endX;
                        }
                        if (startY > endY)
                        {
                            startY = endY;
                        }
                        break;
                    }

                    Vector2f tile = tiles.GetTileCollision(this, startX, startY);

                    if (tile != null)
                    {
                        int sx = tiles.TilesToPixelsX(tile.x);
                        int sy = tiles.TilesToPixelsY(tile.y);
                        if (sx > 0)
                        {
                            sx = sx - GetWidth();
                        }
                        else if (sx < 0)
                        {
                            sx = tiles.TilesToPixelsX(tile.x);
                        }
                        if (sy > 0)
                        {
                            sy = sy - GetHeight();
                        }
                        else if (sy < 0)
                        {
                            sy = tiles.TilesToPixelsY(tile.y);
                        }
                    }
                    else
                    {
                        SetLocation(startX, startY);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public Vector2f GetDirectionValue()
 {
     return(Field2D.GetDirection(GetDirection()));
 }
Ejemplo n.º 5
0
 public int GetDirection()
 {
     return(Field2D.GetDirection(end.X() - start.X(), end.Y() - start.Y(), Config.EMPTY));
 }