public void Draw(SpriteBatch spriteBatch) { // Draw the background blocks that are in the field of view int blockBaseX = camX / BLOCK_WIDTH; int blockBaseY = camY / BLOCK_HEIGHT; for (int y = 0; y <= Game.GAME_HEIGHT / BLOCK_HEIGHT; ++y) { for (int x = 0; x <= Game.GAME_WIDTH / BLOCK_WIDTH; ++x) { Rectangle blockPosition = new Rectangle((blockBaseX + x) * BLOCK_WIDTH - camX, y * BLOCK_HEIGHT, BLOCK_WIDTH, BLOCK_HEIGHT); spriteBatch.Draw(blockTexture[gameGrid[blockBaseY + y, blockBaseX + x]], blockPosition, Color.White); } } Rectangle camera = new Rectangle(camX, 0, Game.GAME_WIDTH, Game.GAME_HEIGHT); // Draw dem derps derpManager.Draw(spriteBatch, camera); // Draw the selected box over top int sx = selectedBox.X - blockBaseX; int sy = selectedBox.Y - blockBaseY; if (sx >= 0 && sx <= Game.GAME_WIDTH / BLOCK_WIDTH && sy >= 0 && sy <= Game.GAME_HEIGHT / BLOCK_HEIGHT) { Rectangle blockPosition = new Rectangle((blockBaseX + sx) * BLOCK_WIDTH - camX, sy * BLOCK_HEIGHT, BLOCK_WIDTH, BLOCK_HEIGHT); spriteBatch.Draw(selectorTexture[0], blockPosition, Color.White); } }
public void Draw(SpriteBatch spriteBatch) { // Draw the background blocks that are in the field of view int blockBaseX = camX / BLOCK_WIDTH; int blockBaseY = camY / BLOCK_HEIGHT; Rectangle blockPosition = new Rectangle(); for (int y = 0; y < Game.GAME_HEIGHT / BLOCK_HEIGHT; ++y) { for (int x = 0; x <= Game.GAME_WIDTH / BLOCK_WIDTH; ++x) { // Make sure this item exists in the Dictionary int offset = 0; char curGrid = gameGrid[blockBaseY + y, blockBaseX + x]; if (!blockPositionOffset.TryGetValue(curGrid, out offset)) { continue; } ; // Calculate the Position and Destination viewport size to draw blockPosition.X = (blockBaseX + x) * BLOCK_WIDTH - camX; blockPosition.Y = y * BLOCK_HEIGHT - offset; blockPosition.Width = BLOCK_WIDTH; blockPosition.Height = BLOCK_HEIGHT + offset; spriteBatch.Draw(blockTexture[curGrid], blockPosition, blockSrcOffset[curGrid], Color.White); } } Rectangle camera = new Rectangle(camX, 0, Game.GAME_WIDTH, Game.GAME_HEIGHT); // Draw dem derps derpManager.Draw(spriteBatch, camera); // Draw all Spawners for (int y = 0; y < height; ++y) { if (leftSpawners[y] != null) { // Check to see if we need to ghost a position if (Game.input.constructionState != 0 && leftSpawners[y].CheckMouseOver(camX + Game.input.MouseX(), Game.input.MouseY()) != -1) { leftSpawners[y].ghostingIndex = leftSpawners[y].CheckMouseOver(camX + Game.input.MouseX(), Game.input.MouseY()); } else { leftSpawners[y].ghostingIndex = -1; } // DEBUG: Do this only on the right side for debugging purposes // Check to see if we need to ghost a position if (Game.input.constructionState != 0 && rightSpawners[y].CheckMouseOver(camX + Game.input.MouseX(), Game.input.MouseY()) != -1) { rightSpawners[y].ghostingIndex = rightSpawners[y].CheckMouseOver(camX + Game.input.MouseX(), Game.input.MouseY()); } else { rightSpawners[y].ghostingIndex = -1; } leftSpawners[y].Draw(spriteBatch, camera); rightSpawners[y].Draw(spriteBatch, camera); } } // Draw the Selection Box, Ghost DNA or Delestroyer Box at the cursor's location int sx = selectedBox.X - blockBaseX; int sy = selectedBox.Y - blockBaseY; if (sx >= 0 && sx <= Game.GAME_WIDTH / BLOCK_WIDTH && sy >= 0 && sy <= Game.GAME_HEIGHT / BLOCK_HEIGHT && Game.input.mouseClear) { blockPosition.X = (blockBaseX + sx) * BLOCK_WIDTH - camX; blockPosition.Y = sy * BLOCK_HEIGHT; blockPosition.Width = BLOCK_WIDTH; blockPosition.Height = BLOCK_HEIGHT; // If we are currently just selecting if (Game.input.constructionState == 0) { spriteBatch.Draw(selectorTexture[0], blockPosition, Color.White); } // If we are currently deleting else if (Game.input.constructionState < 0) { spriteBatch.Draw(selectorTexture[1], blockPosition, Color.White); } // Otherwise we must be building, draw a transparent dna else { spriteBatch.Draw(Spawner.DNATexture[Game.input.constructionState - 1], blockPosition, Color.White * 0.5f); } } }