Exemple #1
0
    /// <summary>
    /// 移动指定距离是否可通行
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="distanceX"></param>
    /// <param name="distanceY"></param>
    /// <returns></returns>
    public bool isPassableByDistance(float x, float y, DIRS dir, float distanceX, float distanceY)
    {
        Intersection.Polygon testPolygon = Intersection.polygonMove(this.colliderPolygon, x, y);        //this.currCollider();
//        Debug.Log(testPolygon.points[0].x);
//        Debug.Log(testPolygon.points[0].y);
        if (dir == DIRS.DOWN)
        {
            testPolygon = Intersection.polygonMove(testPolygon, 0, -distanceY);
        }
        if (dir == DIRS.LEFT)
        {
            testPolygon = Intersection.polygonMove(testPolygon, -distanceX, 0);
        }
        if (dir == DIRS.RIGHT)
        {
            testPolygon = Intersection.polygonMove(testPolygon, distanceX, 0);
        }
        if (dir == DIRS.UP)
        {
            testPolygon = Intersection.polygonMove(testPolygon, 0, distanceY);
        }
//        Debug.Log(testPolygon.points[0].x);
//        Debug.Log(testPolygon.points[0].y);
//        Debug.Log(string.Format("GameTemp.gameMap.isPassable(testPolygon, this) {0}, {1}, {2}, {3}, {4}, {5}",
//            GameTemp.gameMap.isPassable(testPolygon, this), testPolygon, this.currCollider(), distanceX, distanceY, dir));
        return(GameTemp.gameMap.isPassable(testPolygon, this) && GameTemp.gameMap.isPreOtherEventsPassable(testPolygon, this));
    }
Exemple #2
0
    public GameCharacterBase()
    {
        this.originalDirection = DIRS.DOWN;           // 原方向
        this.originalPattern   = 1;                   // 原图案
        this.animeCount        = 0;                   // 动画计数
        this.stopCount         = 0;                   // 停止计数
        this.locked            = false;               // 锁的标志
        this.prelockDirection  = DIRS.NONE;           // 被锁上前的方向
        this.loopAnimNames     = new List <string>(); // 循环的动画
        this.moveSucceed       = true;                // 移动成功的标志
        this.moveRoute         = null;
        this.moveByRouteIndex  = -1;
        this.moveWaitCount     = 0;

        this.lastHit = new List <GameCharacterBase>();


        List <Vector2> points = new List <Vector2>();

        points.Add(new Vector2(0, 0));
        points.Add(new Vector2(0, (Util.GRID_WIDTH - 1) / Util.PPU));
        points.Add(new Vector2((Util.GRID_WIDTH - 1) / Util.PPU, (Util.GRID_WIDTH - 1) / Util.PPU));
        points.Add(new Vector2((Util.GRID_WIDTH - 1) / Util.PPU, 0));
        this.colliderPolygon = new Intersection.Polygon(points);
    }
Exemple #3
0
    /// <summary>
    /// 向指定方向行走
    /// </summary>
    /// <param name="dir"></param>
    /// <returns></returns>
    public bool moveStraight(DIRS dir)
    {
//        if (dir == DIRS.LEFT || dir == DIRS.RIGHT) {
        this.direction = dir;
//        }
        this.isDirty = true;
        if (this.isPassable(this.x, this.y, dir))
        {
            float step = this.getStep();
            if (dir == DIRS.DOWN)
            {
                this.y -= step;
            }
            if (dir == DIRS.LEFT)
            {
                this.x -= step;
            }
            if (dir == DIRS.RIGHT)
            {
                this.x += step;
            }
            if (dir == DIRS.UP)
            {
                this.y += step;
            }
            this.increaseMove();
            return(true);
        }
        return(false);
    }
Exemple #4
0
    /// <summary>
    /// 向反向前进一格
    /// </summary>
    /// <returns><c>true</c>, if grid straight reverse was moved, <c>false</c> otherwise.</returns>
    /// <param name="currDir">Curr dir.</param>
    public bool moveGridStraightReverse(DIRS currDir)
    {
        DIRS reverseDir = getReverseDir(currDir);
        bool result     = moveGridStraight(reverseDir);

        this.direction = currDir;
        return(result);
    }
Exemple #5
0
 /// <summary>
 /// Sets the cell direction depending on the previous cell in the path
 /// </summary>
 /// <param name="lastCell">previous cell on the path, from where we'll get its position in order to set
 /// currents cell's position
 public void SetDirection(Cell lastCell)
 {
     if (transform.position.x > lastCell.transform.position.x && transform.position.y == lastCell.transform.position.y)
     {
         _direction = DIRS.RIGHT;
     }
     if (transform.position.x < lastCell.transform.position.x && transform.position.y == lastCell.transform.position.y)
     {
         _direction = DIRS.LEFT;
     }
     if (transform.position.y > lastCell.transform.position.y && transform.position.x == lastCell.transform.position.x)
     {
         _direction = DIRS.UP;
     }
     if (transform.position.y < lastCell.transform.position.y && transform.position.x == lastCell.transform.position.x)
     {
         _direction = DIRS.DOWN;
     }
 }
Exemple #6
0
    /// <summary>
    /// Sets the direction sprite of the cell depending on the dir given
    /// </summary>
    /// <param name="dir">direction to be activated
    public void SetDirectionLine(DIRS dir)
    {
        switch (dir)
        {
        case DIRS.LEFT:
            ActivateHorizontal();
            break;

        case DIRS.RIGHT:
            ActivateHorizontal();
            break;

        case DIRS.UP:
        case DIRS.DOWN:
            ActivateVertical();
            break;

        case DIRS.NONE:
            break;
        }
    }
Exemple #7
0
    /// <summary>
    /// 朝指定方向移动是否可通行
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="dir"></param>
    /// <returns></returns>
    private bool isPassable(float x, float y, DIRS dir)
    {
        float step = this.getStep();

        Intersection.Polygon testPolygon = Intersection.polygonMove(this.colliderPolygon, x, y);        //this.currCollider();
        if (dir == DIRS.DOWN)
        {
            testPolygon = Intersection.polygonMove(testPolygon, 0, -step);
        }
        if (dir == DIRS.LEFT)
        {
            testPolygon = Intersection.polygonMove(testPolygon, -step, 0);
        }
        if (dir == DIRS.RIGHT)
        {
            testPolygon = Intersection.polygonMove(testPolygon, step, 0);
        }
        if (dir == DIRS.UP)
        {
            testPolygon = Intersection.polygonMove(testPolygon, 0, step);
        }
        return(GameTemp.gameMap.isPassable(testPolygon, this) && GameTemp.gameMap.isPreOtherEventsPassable(testPolygon, this));
    }
Exemple #8
0
    /// <summary>
    /// 根据移动指令行走
    /// </summary>
    public virtual void moveByRoute()
    {
        if (this.isMoving())
        {
            return;
        }
        if (this.moveByRouteIndex < this.moveRoute.Count)
        {
            GameInterpreter.MoveRoute cmd = this.moveRoute[this.moveByRouteIndex];
            switch (cmd.code)
            {
            case GameInterpreter.MoveRoute.Cmd.ROUTE_END:
                this.processRouteEnd();
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_DOWN:
                this.moveGridStraight(DIRS.DOWN);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_LEFT:
                this.moveGridStraight(DIRS.LEFT);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_RIGHT:
                this.moveGridStraight(DIRS.RIGHT);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_UP:
                this.moveGridStraight(DIRS.UP);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_LOWER_L:
                //move_diagonal(4, 2)
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_LOWER_R:
                //move_diagonal(6, 2)
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_UPPER_L:
                //move_diagonal(4, 8)
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_UPPER_R:
                //move_diagonal(6, 8)
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_RANDOM:
                //move_random
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_TOWARD:
                this.moveTowards(int.Parse(cmd.args[0]));
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_AWAY:
                //move_away_from_player
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_FORWARD:
                this.moveForward();
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_MOVE_BACKWARD:
                this.moveBackward();
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_JUMP:
                //jump(params[0], params[1])
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_WAIT:
                this.moveWaitCount = int.Parse(cmd.args[0]);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_DOWN:
                this.direction = DIRS.DOWN;
                this.isDirty   = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_LEFT:
                this.direction = DIRS.LEFT;
                this.isDirty   = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_RIGHT:
                this.direction = DIRS.RIGHT;
                this.isDirty   = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_UP:
                this.direction = DIRS.UP;
                this.isDirty   = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_90D_R:
                //turn_right_90
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_90D_L:
                //turn_left_90
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_180D:
                //turn_180
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_90D_R_L:
                //turn_right_or_left_90
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_RANDOM:
                //turn_random
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_TOWARD:
                //turn_toward_player
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TURN_AWAY:
                //turn_away_from_player
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_SWITCH_ON:
                //$game_switches[params[0]] = true
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_SWITCH_OFF:
                //$game_switches[params[0]] = false
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_CHANGE_SPEED:
                this.moveSpeed = int.Parse(cmd.args[0]);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_CHANGE_FREQ:
                //@move_frequency = params[0]
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_WALK_ANIME_ON:
                this.walkAnime = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_WALK_ANIME_OFF:
                this.walkAnime = false;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_STEP_ANIME_ON:
                this.stepAnime = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_STEP_ANIME_OFF:
                this.stepAnime = false;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_DIR_FIX_ON:
                this.directionFix = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_DIR_FIX_OFF:
                this.directionFix = false;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_THROUGH_ON:
                this.through = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_THROUGH_OFF:
                this.through = false;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TRANSPARENT_ON:
                this.transparent = true;
                this.isDirty     = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_TRANSPARENT_OFF:
                this.transparent = false;
                this.isDirty     = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_CHANGE_GRAPHIC:
                this.characterName   = cmd.args[0];
                this.originalPattern = 1;
                this.isDirty         = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_CHANGE_OPACITY:
                this.opacity = int.Parse(cmd.args[0]);
                this.isDirty = true;
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_CHANGE_BLENDING:
                //@blend_type = params[0]
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_PLAY_SE:
                AudioManager.PlaySE(cmd.args[0]);
                break;

            case GameInterpreter.MoveRoute.Cmd.ROUTE_SCRIPT:
                //eval(params[0])
                break;
            }
        }
    }
Exemple #9
0
    /// <summary>
    /// 向指定角色移动
    /// </summary>
    /// <returns><c>true</c>, if towards was moved, <c>false</c> otherwise.</returns>
    /// <param name="charId">Char identifier.</param>
    public bool moveTowards(int charId)
    {
        GameCharacterBase character = GameTemp.gameMap.interpreter.getCharacter(charId);
        float             targetX   = character.realX;
        float             targetY   = character.realY;
        float             offsetX   = Mathf.Abs(targetX - this.realX);
        float             offsetY   = Mathf.Abs(targetY - this.realY);
        DIRS dir = DIRS.NONE;

        if (this.isPassable(this.realX, this.realY, DIRS.UP) &&
            this.isPassable(this.realX, this.realY, DIRS.DOWN) &&
            this.isPassable(this.realX, this.realY, DIRS.LEFT) &&
            this.isPassable(this.realX, this.realY, DIRS.RIGHT))
        {
            // 四面无障碍
            if (offsetX > offsetY)
            {
                if (this.realX < targetX)
                {
                    dir = DIRS.RIGHT;
                }
                else
                {
                    dir = DIRS.LEFT;
                }
            }
            else
            {
                if (this.realY < targetY)
                {
                    dir = DIRS.UP;
                }
                else
                {
                    dir = DIRS.DOWN;
                }
            }
        }
        else
        {
            if (offsetX > offsetY && (new System.Random()).Next(100) > 30)
            {
                if (this.realX < targetX)
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.RIGHT;
                    }
                    else
                    {
                        dir = DIRS.LEFT;
                    }
                }
                else
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.LEFT;
                    }
                    else
                    {
                        dir = DIRS.RIGHT;
                    }
                }
            }
            else
            {
                if (this.realY < targetY)
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.UP;
                    }
                    else
                    {
                        dir = DIRS.DOWN;
                    }
                }
                else
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.DOWN;
                    }
                    else
                    {
                        dir = DIRS.UP;
                    }
                }
            }
        }
        return(this.moveGridStraight(dir));
    }
Exemple #10
0
 /// <summary>
 /// 取反向
 /// </summary>
 /// <returns>The reverse dir.</returns>
 /// <param name="dir">Dir.</param>
 public static DIRS getReverseDir(DIRS dir)
 {
     return((DIRS)(10 - (int)dir));
 }
Exemple #11
0
    /// <summary>
    /// 向指定方向行走一格
    /// </summary>
    /// <param name="dir"></param>
    /// <returns></returns>
    public bool moveGridStraight(DIRS dir)
    {
        Debug.Log(string.Format("moveGridStraight {0}", dir));
        if (dir == DIRS.NONE)
        {
            return(true);
        }
        //if (dir == DIRS.LEFT || dir == DIRS.RIGHT) {
        this.direction = dir;
        //}
        this.isDirty = true;
        float step  = this.getStep();
        float stepX = 0f;
        float stepY = 0f;

        if (dir == DIRS.LEFT)
        {
            if (this.x < 0)
            {
                stepX = (this.getBaseStep() - Mathf.Abs(this.x) % this.getBaseStep()) % this.getBaseStep() + this.getBaseStep();
            }
            else
            {
                stepX = Mathf.Abs(this.x) % this.getBaseStep() + this.getBaseStep();
            }
        }
        if (dir == DIRS.RIGHT)
        {
            if (this.x < 0)
            {
                stepX = Mathf.Abs(this.x) % this.getBaseStep() + this.getBaseStep();
            }
            else
            {
                stepX = (this.getBaseStep() - Mathf.Abs(this.x) % this.getBaseStep()) % this.getBaseStep() + this.getBaseStep();
            }
        }
        if (dir == DIRS.DOWN)
        {
            if (this.y < 0)
            {
                stepY = (this.getBaseStep() - Mathf.Abs(this.y) % this.getBaseStep()) % this.getBaseStep() + this.getBaseStep();
            }
            else
            {
                stepY = Mathf.Abs(this.y) % this.getBaseStep() + this.getBaseStep();
            }
        }
        if (dir == DIRS.UP)
        {
            if (this.y < 0)
            {
                stepY = Mathf.Abs(this.y) % this.getBaseStep() + this.getBaseStep();
            }
            else
            {
                stepY = (this.getBaseStep() - Mathf.Abs(this.y) % this.getBaseStep()) % this.getBaseStep() + this.getBaseStep();
            }
        }
        if (stepX > this.getBaseStep())
        {
            stepX = this.getBaseStep();
        }
        if (stepY > this.getBaseStep())
        {
            stepY = this.getBaseStep();
        }
        while ((((dir == DIRS.UP || dir == DIRS.DOWN) && stepY > 0) || ((dir == DIRS.LEFT || dir == DIRS.RIGHT) && stepX > 0)) &&
               this.isPassableByDistance(this.x, this.y, dir, step, step))
        {
            if (dir == DIRS.DOWN)
            {
                this.y -= step;
                stepY  -= step;
            }
            if (dir == DIRS.LEFT)
            {
                this.x -= step;
                stepX  -= step;
            }
            if (dir == DIRS.RIGHT)
            {
                this.x += step;
                stepX  -= step;
            }
            if (dir == DIRS.UP)
            {
                this.y += step;
                stepY  -= step;
            }
            this.increaseMove();
        }
        return(true);
    }
Exemple #12
0
 /// <summary>
 /// Sets the direction to NONE, and fills a cell
 /// </summary>
 void Start()
 {
     _direction = DIRS.NONE;
     FillCell();
     _childs[(int)CellObjects.HORIZONTAL_HINT].GetComponent <SpriteRenderer>().sprite = _childs[(int)CellObjects.VERTICAL_HINT].GetComponent <SpriteRenderer>().sprite = LeatherManager.Instance.GetHintSprite();
 }
Exemple #13
0
 /// <summary>
 /// Sets the cell direction to default
 /// </summary>
 public void SetNoneDirection()
 {
     _direction = DIRS.NONE;
 }