protected bool hasRightWall2(cWorld world, float delta, out float wallLeftX) { wallLeftX = 0.0f; float predictedPosX = position.X + Bounds.dims.X + delta; Vector2f oldTopRight = new Vector2f(position.X + Bounds.dims.X, position.Y); Vector2f newTopRight = new Vector2f(predictedPosX, position.Y); Vector2f newBottomRight = new Vector2f(newTopRight.X, newTopRight.Y + Bounds.dims.Y - 2.0f); int tileEndX = world.ToMapPos(newTopRight).X + 1; int tileBeginX = Math.Min(world.ToMapPos(oldTopRight).X, tileEndX); int tileBeginY = world.ToMapPos(newTopRight).Y; int tileEndY = world.ToMapPos(newBottomRight).Y; // changed to handle right walking between walls when falling for (int tileIndexX = tileBeginX; tileIndexX < tileEndX; ++tileIndexX) { for (int tileIndexY = tileBeginY; tileIndexY <= tileEndY; ++tileIndexY) { //world.GetCurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = false; if (world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL) /*world.isRectOnWall()*/ { //world.GetCurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; wallLeftX = (int)(tileIndexX * Constants.TILE_SIZE); // + world.WorldBounds.topLeft.X return(true); } } } return(false); }
/// <summary> /// balról jobbra, alulról felfelé /// </summary> /// <param name="world"></param> /// <param name="delta"></param> /// <param name="wallRightX"></param> /// <returns></returns> protected bool hasLeftWall2(cWorld world, float delta, out float wallRightX) { wallRightX = 0.0f; float predictedPosX = position.X + delta; Vector2f oldTopLeft = new Vector2f(position.X, position.Y); Vector2f newTopLeft = new Vector2f(predictedPosX - 1, position.Y); Vector2f newBottomLeft = new Vector2f(newTopLeft.X, newTopLeft.Y + bounds.dims.Y - 2.0f); int tileEndX = world.ToMapPos(newTopLeft).X - 1; int tileBeginX = Math.Max(world.ToMapPos(oldTopLeft).X, tileEndX); int tileBeginY = world.ToMapPos(newBottomLeft).Y; int tileEndY = world.ToMapPos(newTopLeft).Y; for (int tileIndexX = tileBeginX; tileIndexX > tileEndX; --tileIndexX) { for (int tileIndexY = tileBeginY; tileIndexY >= tileEndY; --tileIndexY) { //world.GetCurrentLevel().GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = false; if (world.GetCurrentLevel().GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL) /*world.isRectOnWall()*/ { //world.GetCurrentLevel().GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; wallRightX = (int)(tileIndexX * Constants.TILE_SIZE + Constants.TILE_SIZE + world.WorldBounds.topLeft.X); return(true); } } } return(false); }
protected bool hasCeiling(cWorld world, float delta, out float bottomY) { bottomY = 0.0f; float predictedPosY = position.Y + delta; Vector2f oldTopLeft = new Vector2f(position.X, position.Y); Vector2f newTopLeft = new Vector2f(position.X, predictedPosY); Vector2f newTopRight = new Vector2f(newTopLeft.X + Bounds.dims.X - 2.0f, newTopLeft.Y); int endY = world.ToMapPos(oldTopLeft).Y; //mMap.GetMapTileYAtPoint(newBottomLeft.y); int begY = Math.Min(world.ToMapPos(newTopLeft).Y, endY); int dist = Math.Max(Math.Abs(endY - begY), 1); int tileIndexX; for (int tileIndexY = begY; tileIndexY <= endY; ++tileIndexY) { var topLeft = AppMath.Interpolate(newTopLeft, oldTopLeft, (float)Math.Abs(endY - tileIndexY) / dist); var topRight = new Vector2f(topLeft.X + Bounds.dims.X - 1, topLeft.Y); for (var checkedTile = topLeft; ; checkedTile.X += Constants.TILE_SIZE) { checkedTile.X = Math.Min(checkedTile.X, topRight.X); tileIndexX = world.ToMapPos(checkedTile).X; if (world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL) { bottomY = (((float)tileIndexY) * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y + Constants.TILE_SIZE); return(true); } if (checkedTile.X >= topRight.X) { break; } } } return(false); }
protected bool hasGround2(cWorld world, float delta, out float groundY) { groundY = 0.0f; float predictedPosY = position.Y + delta; Vector2f oldBottomRight = new Vector2f(position.X + bounds.halfDims.X, position.Y + bounds.dims.Y); Vector2f oldBottomLeft = new Vector2f(position.X, position.Y + bounds.dims.Y); Vector2f newBottomLeft = new Vector2f(oldBottomLeft.X, predictedPosY + bounds.dims.Y); Vector2f newBottomRight = new Vector2f(newBottomLeft.X + bounds.halfDims.X, newBottomLeft.Y); int tileEndX = world.ToMapPos(oldBottomLeft).X + 1; int tileBeginX = Math.Min(world.ToMapPos(oldBottomLeft).X, tileEndX); int tileBeginY = world.ToMapPos(oldBottomLeft).Y; int tileEndY = world.ToMapPos(newBottomLeft).Y; for (int tileIndexY = tileBeginY; tileIndexY <= tileEndY; ++tileIndexY) { for (int tileIndexX = tileBeginX; tileIndexX <= tileEndX; ++tileIndexX) { if (world.GetCurrentLevel().GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL) /*world.isRectOnWall()*/ { //world.GetCurrentLevel().GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; world.GetCurrentLevel().GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; groundY = (int)(tileIndexY * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y); return(true); } } } return(false); }
protected bool hasGround2(cWorld world, float delta, out float groundY) { groundY = 0.0f; float predictedPosY = position.Y + delta; Vector2f oldBottomRight = new Vector2f(position.X + Bounds.halfDims.X, position.Y + Bounds.dims.Y); Vector2f oldBottomLeft = new Vector2f(position.X, position.Y + Bounds.dims.Y); Vector2f newBottomLeft = new Vector2f(oldBottomLeft.X, predictedPosY + Bounds.dims.Y); Vector2f newBottomRight = new Vector2f(newBottomLeft.X + Bounds.halfDims.X, newBottomLeft.Y); // int tileBeginX = Math.Min(world.ToMapPos(oldBottomLeft).X, tileEndX); int tileBeginX = world.ToMapPos(oldBottomLeft).X - 1; int tileEndX = world.ToMapPos(newBottomRight).X + 1; int tileBeginY = world.ToMapPos(oldBottomLeft).Y - 1; int tileEndY = world.ToMapPos(newBottomLeft).Y + 1; if (this.velocity.X < 0.0f) { for (int tileIndexY = tileBeginY; tileIndexY <= tileEndY; ++tileIndexY) { for (int tileIndexX = tileBeginX; tileIndexX < tileEndX; ++tileIndexX) { if (tileCollision(tileIndexX, tileIndexY, out groundY)) { return(true); } } } } else { for (int tileIndexY = tileBeginY; tileIndexY <= tileEndY; ++tileIndexY) { for (int tileIndexX = tileEndX; tileIndexX > tileBeginX; --tileIndexX) { if (tileCollision(tileIndexX, tileIndexY, out groundY)) { return(true); } } } } //if (world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL) /*world.isRectOnWall()*/ /* * { * //world.GetCurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; * * world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; * groundY = (int)(tileIndexY * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y); * return true; * } */ return(false); }
protected bool hasGround(cWorld world, float delta, out float groundY) { /*var oldCenter = lastPosition; * var center = position;*/ groundY = 0.0f; float predictedPosY = position.Y + delta; /* * Vector2f up = new Vector2f(0, -1); * Vector2f bottom = new Vector2f(0, 1); * Vector2f left = new Vector2f(-1, 0); * Vector2f right = new Vector2f(1, 0);*/ Vector2f oldBottomLeft = new Vector2f(position.X, position.Y + Bounds.dims.Y); Vector2f newBottomLeft = new Vector2f(position.X, predictedPosY + Bounds.dims.Y); Vector2f newBottomRight = new Vector2f(newBottomLeft.X + Bounds.dims.X, newBottomLeft.Y); int endY = world.ToMapPos(newBottomLeft).Y; //mMap.GetMapTileYAtPoint(newBottomLeft.y); int begY = Math.Max(world.ToMapPos(oldBottomLeft).Y - 1, endY); int dist = Math.Max(Math.Abs(endY - begY), 1); int tileIndexX; for (int tileIndexY = begY; tileIndexY <= endY; ++tileIndexY) { var bottomLeft = AppMath.Interpolate(newBottomLeft, oldBottomLeft, (float)Math.Abs(endY - tileIndexY) / dist); var bottomRight = new Vector2f(bottomLeft.X + Bounds.dims.X - 1.0f, bottomLeft.Y); // -1, -2.0f for (var checkedTile = bottomLeft; ; checkedTile.X += Constants.TILE_SIZE) { checkedTile.X = Math.Min(checkedTile.X, bottomRight.X); tileIndexX = world.ToMapPos(checkedTile).X; //world.GetCurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true; groundY = (int)((float)tileIndexY * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y); TileType tile = world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type; if (tile == TileType.WALL) { isOnOnewWayPlatform = false; return(true); } else if (tile == TileType.ONEWAY_PLATFORM && position.Y <= groundY - Bounds.dims.Y) { isOnOnewWayPlatform = true; return(true); } if (checkedTile.X >= bottomRight.X) { /*if(isOnOnewWayPlatform) * return true;*/ break; } } } return(false); }