/// <summary> /// Returns the cached value for the MapCell at (x, y). /// Assumes this value is actually contained in the cache /// and may have undesired behavior if not (anything from /// array bounds exceptions to just returning wrong data). /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public MapCellType Get(int x, int y) { return(cache[ Numerical.Mod(x - xMin + xStartIndex, cacheWidth), Numerical.Mod(y - yMin + yStartIndex, cacheHeight) ]); }
public virtual void Draw(GameTime gameTime) { spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); float maxdepth = ((squaresWideToDraw + 1) + ((squaresTallToDraw + 1) * Tile.TileWidth)) * 10; //converts pixels to steps int leftX = Numerical.intDivide(Camera.Location.X, Tile.TileStepX); int topY = Numerical.intDivide(Camera.Location.Y, Tile.TileStepY); //if the sum is now odd, we will get weird errors, so just move over a little //we will fix the inelegance with more offset if (Numerical.Mod(leftX + topY, 2) == 1) { leftX--; } int firstX = (leftX + topY) / 2 - 1; int firstY = (leftX - topY) / 2; int offsetX = Camera.Location.X - (firstX + firstY) * Tile.TileStepX; int offsetY = Camera.Location.Y - (firstX - firstY) * Tile.TileStepY; drawTileMapCells(maxdepth, firstX, firstY, offsetX, offsetY); drawInGameObjects(maxdepth, firstX, firstY, offsetX, offsetY); spriteBatch.End(); }
private void addRightColumn() { //set up the new right column, which replaces the old left column for (int y = 0; y < cacheHeight; y++) { cache[xStartIndex, Numerical.Mod(y + yStartIndex, cacheHeight)] = map.MakeMapCell(xMin + cacheWidth, y + yMin); } //updates the minimum xMin++; //fixes the indexing xStartIndex = Numerical.Mod(xStartIndex + 1, cacheWidth); }
private void addLeftColumn() { //allows for the next left column xMin--; //fixes the indexing xStartIndex = Numerical.Mod(xStartIndex - 1, cacheWidth); //fix the new left column for (int y = 0; y < cacheHeight; y++) { cache[xStartIndex, Numerical.Mod(y + yStartIndex, cacheHeight)] = map.MakeMapCell(xMin, y + yMin); } }
private void addBottomRow() { //set up the new bottom row, which replaces the old top row for (int x = 0; x < cacheWidth; x++) { cache[Numerical.Mod(x + xStartIndex, cacheWidth), yStartIndex] = map.MakeMapCell(x + xMin, yMin + cacheHeight); } //updates the minimum yMin++; //fixes the indexing yStartIndex = Numerical.Mod(yStartIndex + 1, cacheHeight); }
private void addTopRow() { //allows for a new top row yMin--; //fixes the indexing so that the old data is still indexed correctly yStartIndex = Numerical.Mod(yStartIndex - 1, cacheHeight); //now fix the new top row for (int x = 0; x < cacheWidth; x++) { cache[Numerical.Mod(x + xStartIndex, cacheWidth), yStartIndex] = map.MakeMapCell(x + xMin, yMin); } }