public void Add_Should() { var point1 = new PointI(1, 1, 1); var point123 = new PointI(1, 2, 3); Assert.AreEqual(new PointI(2, 3, 4), point1.Add(point123)); Assert.AreEqual(point1.Add(point123), point123.Add(point1)); }
public Chunk <Block> Generate(Chunk <Block> source) { for (var x = 0; x < Chunk <Block> .XLength; x++) { for (var z = 0; z < Chunk <Block> .ZLength; z++) { for (var y = 0; y < Chunk <Block> .YLength - 3; y++) { var point = new PointI(x, y, z).AsPointB(); if (source[point.Add(new PointB(0, 3, 0))] == null) { break; } var block = DeterminateOre(point, source.Position); if (block != null) { source[point] = block; } } } } return(source); }
/// <summary> /// Draw scene. /// </summary> protected override void Draw() { // clear screen Gfx.ClearScreen(Color.Cornflower); // draw scene on texture once if (!_wasDrawn) { // set render target Gfx.RenderTarget = _targetTexture; // draw background dirt var backgroundSize = new PointI(_dirtImage.Width * 2, _dirtImage.Height * 2); for (int i = 0; i < Gfx.WindowSize.X / backgroundSize.X + 1; ++i) { for (int j = 0; j < Gfx.WindowSize.Y / backgroundSize.Y + 1; ++j) { Gfx.DrawImage(_dirtImage, new PointF(i, j).Multiply(backgroundSize), backgroundSize, BlendModes.Opaque); } } // draw sprites foreach (var sprite in _sprites) { Gfx.DrawSprite(sprite); } // clear render target Gfx.RenderTarget = null; _wasDrawn = true; // allow reading pixels from texture _targetTexture.PrepareReadingBuffer(); } // draw render target on screen, with larger size so we'll only see parts of it float screenScale = 1.5f; if (!_paused) { _cameraOffset = new PointF(-150 + (float)Math.Sin(Game.ElapsedTime / 2f) * 150f, -150 + (float)Math.Cos(Game.ElapsedTime / 2f) * 150f); } var size = Gfx.WindowSize.Multiply(screenScale); Gfx.DrawImage(_targetTexture, _cameraOffset, size); // draw minimap var mapSize = new PointI((int)(150 * 1.333f), 150); var mapPosition = Gfx.WindowSize.Substract(mapSize.Add(10)); Gfx.DrawRectangle(new RectangleI(mapPosition.X - 5, mapPosition.Y - 5, mapSize.X + 10, mapSize.Y + 10), Color.Black, true); Gfx.DrawImage(_targetTexture, mapPosition, mapSize); // title and text Gfx.DrawText(_fontBig, "Render To Texture", new PointF(80, 120), Color.White, Color.Black, 1, 42); Gfx.DrawText(_font, "This scene demonstrates drawing to texture.\n" + "First we draw to texture, then we draw it on screen,\n" + "and finally we use the same texture as a minimap at the corner.\n" + "- Press S to save image to file.\n" + "- Press P to pause camera movement.\n" + "- Press Escape to exit.", new PointF(80, 210), Color.White, Color.Black, 1, 22); // write FPS and other info Gfx.DrawText(_font, "FPS: " + Diagnostics.FpsCount.ToString(), new PointF(10, 10), Color.White, Color.Black, 1, 22); // write pixel we point on // enable reading pixels PointI pixelPosition = Input.CursorPosition.Substract(_cameraOffset).Divide(screenScale); Color pixel = _targetTexture.GetPixel(pixelPosition); Gfx.DrawText(_font, "Pixel Color: " + pixel.ToString(true), new PointF(10, Gfx.RenderableSize.Y - 40), Color.White, Color.Black, 1, 22); // draw cursor Gfx.DrawImage(_cursor, Input.CursorPosition, new PointI(42, 42)); }