예제 #1
0
파일: Snake.java 프로젝트: smcreator/snakex
  public void move() {
    Vector2 nextDirection =
        Vector2.add(new Vector2(getHead().getX(), getHead().getY()), _direction);

    if (nextDirection.x < SNAKE_WIDTH * 2
        || nextDirection.x >= _mapWidth - SNAKE_WIDTH * 2
        || nextDirection.y < SNAKE_WIDTH * 2
        || nextDirection.y >= _mapHeight - SNAKE_WIDTH * 2) {
      turned();
      return;
    }

    if (_steps == 0) {
      turned();
    }

    _steps++;

    boolean isTurned = false;

    if (_steps >= SNAKE_WIDTH) {
      _steps = 0;
      isTurned = true;
    }
    _body.move(isTurned);
  }
예제 #2
0
파일: Snake.java 프로젝트: smcreator/snakex
  public float handleSceneTouch(TouchEvent pSceneTouchEvent) {
    Vector2 v =
        new Vector2(
            getHead().getX() - pSceneTouchEvent.getX(), getHead().getY() - pSceneTouchEvent.getY());

    float angle = v.getAngle();
    if ((0 <= angle && angle <= 45) || (315 < angle && angle < 360)) {
      setDirection(SnakeDirection.RIGHT);
    } else if (45 < angle && angle <= 135) {
      setDirection(SnakeDirection.UP);
    } else if (135 < angle && angle <= 225) {
      setDirection(SnakeDirection.LEFT);
    } else if (225 < angle && angle <= 315) {
      setDirection(SnakeDirection.DOWN);
    }
    return angle;
  }
예제 #3
0
파일: Snake.java 프로젝트: smcreator/snakex
  public boolean setDirection(final SnakeDirection pDirection) {
    Vector2 d = SnakeDirection.toVector(pDirection);
    if (_lastDirection == null || !Vector2.opposite(d, _lastDirection)) {
      _direction = d;
      return true;
    }

    return false;
  }