protected void checkWrap() { // wrap around left/right if (tileX == 0 && direction == Game1.LEFT) { x = Game1.TILE_SIZE * 20; tileX = Map.CoordinateToTile((int)x); } if (tileX >= 19 && direction == Game1.RIGHT) { x = 0; tileX = Map.CoordinateToTile((int)x); } // TODO: top right wrap tunnel lets you move on top of wall }
public void Update() { switch (direction) { case -1: //this represents staying in place break; case Game1.UP: y -= speed; break; case Game1.LEFT: x -= speed; break; case Game1.RIGHT: x += speed; break; case Game1.DOWN: y += speed; break; } //if it passes an intersection, it will snap back to the intersection, change its direction and move in that direction the amount of lost distance int distanceFromLastTile = DistanceFromLastTile(); if (distanceFromLastTile > Game1.TILE_SIZE || direction == -1) { switch (direction) { case -1: //this represents staying in place break; case Game1.UP: y = Map.TileToCoordinate(tileY - 1); break; case Game1.LEFT: x = Map.TileToCoordinate(tileX - 1); break; case Game1.RIGHT: x = Map.TileToCoordinate(tileX + 1); break; case Game1.DOWN: y = Map.TileToCoordinate(tileY + 1); break; } if (direction != -1) { //update tileX and tileY so we can use them at the next intersection tileX = Map.CoordinateToTile((int)x); tileY = Map.CoordinateToTile((int)y); } bool wasMoving = direction != -1; //this is only used to make it not do anything with turnDistance direction = NextDirection(); if (wasMoving) { float turnDistance = distanceFromLastTile - Game1.TILE_SIZE; //this is the amount of distance left over it should travel in this frame in the new direction switch (direction) { case -1: //this represents staying in place break; case Game1.UP: y -= turnDistance; break; case Game1.LEFT: x -= turnDistance; break; case Game1.RIGHT: x += turnDistance; break; case Game1.DOWN: y += turnDistance; break; } } } checkWrap(); //update position of destRect destRect.X = (int)x - Game1.TILE_SIZE / 2; destRect.Y = (int)y - Game1.TILE_SIZE / 2; }