public override void DrawOverlay(IBatchRenderer sbatch) { int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; if (_wrapMode == GameWrapMode.Donut || _wrapMode == GameWrapMode.Reflect) { var fextx = extensionX * TILE_WIDTH; var fexty = extensionY * TILE_WIDTH; var rn = new FRectangle(-fextx, -fexty, Owner.MapFullBounds.Width + 2 * fextx, fexty); var re = new FRectangle(Owner.MapFullBounds.Width, -fexty, fextx, Owner.MapFullBounds.Height + 2 * fexty); var rs = new FRectangle(-fextx, Owner.MapFullBounds.Height, Owner.MapFullBounds.Width + 2 * fextx, fexty); var rw = new FRectangle(-fextx, -fexty, fextx, Owner.MapFullBounds.Height + 2 * fexty); sbatch.DrawStretched(Textures.TexPixel, rn, FlatColors.Clouds); sbatch.DrawStretched(Textures.TexPixel, re, FlatColors.Clouds); sbatch.DrawStretched(Textures.TexPixel, rs, FlatColors.Clouds); sbatch.DrawStretched(Textures.TexPixel, rw, FlatColors.Clouds); FlatRenderHelper.DrawForegroundDropShadow(sbatch, Owner.MapFullBounds, GDConstants.TILE_WIDTH / 2f, GDConstants.TILE_WIDTH / 2f); sbatch.DrawRectangle(Owner.MapFullBounds, Color.White, 3f); } }
private bool IsCellActive(FractionDifficulty d, int idx) { bool active; if (solvedPerc[d] < 0.5f) { active = idx < FloatMath.Ceiling(solvedPerc[d] * 15); } else { active = idx <= FloatMath.Floor(solvedPerc[d] * 15); } if (FlickerTime > COLLAPSE_TIME) { return(active); } else { if (active) { return(FloatMath.GetRandom() < (0.5f + FloatMath.FunctionEaseInOutCubic(FlickerTime / COLLAPSE_TIME) / 2f)); } else { return(FloatMath.GetRandom() < (0.5f - FloatMath.FunctionEaseInOutCubic(FlickerTime / COLLAPSE_TIME) / 2f)); } } }
private void DrawSimple(IBatchRenderer sbatch) { int offX = TILE_WIDTH * (int)(Owner.MapOffsetX / TILE_WIDTH); int offY = TILE_WIDTH * (int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; int countX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedWidth / TILE_WIDTH); int countY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedHeight / TILE_WIDTH); sbatch.DrawStretched( Textures.TexPixel, new FRectangle( -extensionX * TILE_WIDTH - offX, -extensionY * TILE_WIDTH - offY, (countX + 2 * extensionX) * TILE_WIDTH, (countY + 2 * extensionY) * TILE_WIDTH), FlatColors.Background); if (GridLineAlpha >= 1) { for (int x = -extensionX; x < countX + extensionX; x++) { for (int y = -extensionY; y < countY + extensionY; y++) { sbatch.DrawStretched(Textures.TexTileBorder, new FRectangle(x * TILE_WIDTH - offX, y * TILE_WIDTH - offY, TILE_WIDTH, TILE_WIDTH), Color.White * GridLineAlpha); } } } }
public GDCellularBackground(GDGameScreen scrn, LevelBlueprint lvl) : base(scrn) { tileCountX = FloatMath.Ceiling(lvl.LevelWidth / 64f) + 2 * MAX_EXTENSION_X; tileCountY = FloatMath.Ceiling(lvl.LevelHeight / 64f) + 2 * MAX_EXTENSION_Y; wrapMode = scrn.WrapMode; _grid = new GridCellMembership[tileCountX, tileCountY]; Initialize(); }
private void DrawColoredNormal(IBatchRenderer sbatch) { sbatch.FillRectangle(VAdapter.VirtualTotalBoundingBox, FlatColors.Background); int offX = (int)(Owner.MapOffsetX / TILE_WIDTH); int offY = (int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; int countX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedWidth / TILE_WIDTH); int countY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedHeight / TILE_WIDTH); for (int x = -extensionX; x < countX + extensionX; x++) { for (int y = -extensionY; y < countY + extensionY; y++) { var color = FlatColors.Background; var rx = x - offX; var ry = y - offY; float perc; if (_tileValues.TryGetValue(100000 * rx + ry, out perc)) { color = ColorMath.Blend(FlatColors.Background, FlatColors.BackgroundGreen, (((int)(perc * GRADIENT_RESOLUTION) * 1f) / GRADIENT_RESOLUTION) * BackgroundPercentageOverride); } sbatch.DrawStretched( Textures.TexPixel, new FRectangle( rx * GDConstants.TILE_WIDTH, ry * GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), color); if (GridLineAlpha > 0) { sbatch.DrawStretched( Textures.TexTileBorder, new FRectangle( rx * GDConstants.TILE_WIDTH, ry * GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), Color.White * GridLineAlpha); } } } }
public override void Draw(IBatchRenderer sbatch) { int offX = TILE_WIDTH * (int)(Owner.MapOffsetX / TILE_WIDTH); int offY = TILE_WIDTH * (int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; int countX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedWidth / TILE_WIDTH); int countY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedHeight / TILE_WIDTH); if (MainGame.Inst.Profile.EffectsEnabled) { for (int x = -(extensionX + 1); x < countX + extensionX; x++) { for (int y = -(extensionY + 1); y < countY + extensionY; y++) { int cx = ARRAY_EXTEND + x; int cy = ARRAY_EXTEND + y; var color = FlatColors.Background; if (cx >= 0 && cy >= 0 && cx < CELL_W && cy < CELL_H) { var c = _cells[cx, cy]; if (c.Power > 0) { color = ColorMath.Blend(FlatColors.Background, FlatColors.BackgroundGreen, FloatMath.FunctionEaseInOutCubic(c.Power)); } } sbatch.DrawStretched(Textures.TexPixel, new FRectangle(x * GDConstants.TILE_WIDTH - offX, y * GDConstants.TILE_WIDTH - offY, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), color); sbatch.DrawStretched(Textures.TexTileBorder, new FRectangle(x * GDConstants.TILE_WIDTH - offX, y * GDConstants.TILE_WIDTH - offY, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), Color.White); } } } else { var r = new FRectangle(-extensionX * TILE_WIDTH - offX, -extensionY * TILE_WIDTH - offY, (countX + 2 * extensionX) * TILE_WIDTH, (countY + 2 * extensionY) * TILE_WIDTH); sbatch.DrawStretched(Textures.TexPixel, r, FlatColors.Background); for (int x = -extensionX; x < countX + extensionX; x++) { for (int y = -extensionY; y < countY + extensionY; y++) { sbatch.DrawStretched(Textures.TexTileBorder, new FRectangle(x * TILE_WIDTH - offX, y * TILE_WIDTH - offY, TILE_WIDTH, TILE_WIDTH), Color.White); } } } }
public override void Draw(IBatchRenderer sbatch) { int offX = TILE_WIDTH * (int)(Owner.MapOffsetX / TILE_WIDTH); int offY = TILE_WIDTH * (int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; int countX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedWidth / TILE_WIDTH); int countY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedHeight / TILE_WIDTH); var r = new FRectangle(-extensionX * TILE_WIDTH - offX, -extensionY * TILE_WIDTH - offY, (countX + 2 * extensionX) * TILE_WIDTH, (countY + 2 * extensionY) * TILE_WIDTH); sbatch.DrawStretched(Textures.TexPixel, r, FlatColors.Background); }
public override void Draw(IBatchRenderer sbatch) { int offX = TILE_WIDTH * (int)(Owner.MapOffsetX / TILE_WIDTH); int offY = TILE_WIDTH * (int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; int countX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedWidth / TILE_WIDTH); int countY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedHeight / TILE_WIDTH); var r = new FRectangle(-extensionX * TILE_WIDTH - offX, -extensionY * TILE_WIDTH - offY, (countX + 2 * extensionX) * TILE_WIDTH, (countY + 2 * extensionY) * TILE_WIDTH); sbatch.DrawStretched(Textures.TexPixel, r, FlatColors.Background); if (_animationTime < ANIMATION_DURATION + 0.5f) { foreach (var e in _elements) { if (_animationTime < e.StartTime) { continue; } sbatch.DrawCentered(Textures.TexPixel, e.Center, (_animationTime - e.StartTime) * e.Speed, 2, FlatColors.BackgroundHighlight, e.Rotation); } } else { for (int x = -extensionX; x < countX + extensionX; x++) { sbatch.DrawCentered(Textures.TexPixel, new FPoint(x * TILE_WIDTH, r.CenterY), 2, r.Height, FlatColors.BackgroundHighlight); } for (int y = -extensionY; y < countY + extensionY; y++) { sbatch.DrawCentered(Textures.TexPixel, new FPoint(r.CenterX, y * TILE_WIDTH), r.Width, 2, FlatColors.BackgroundHighlight); } } }
public override void DrawOverlay(IBatchRenderer sbatch) { if (wrapMode == GameWrapMode.Donut || wrapMode == GameWrapMode.Reflect) { int real_extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int real_extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; var fextx = real_extensionX * TILE_WIDTH; var fexty = real_extensionY * TILE_WIDTH; var rn = new FRectangle(-fextx, -fexty, Owner.MapFullBounds.Width + 2 * fextx, fexty); var re = new FRectangle(Owner.MapFullBounds.Width, -fexty, fextx, Owner.MapFullBounds.Height + 2 * fexty); var rs = new FRectangle(-fextx, Owner.MapFullBounds.Height, Owner.MapFullBounds.Width + 2 * fextx, fexty); var rw = new FRectangle(-fextx, -fexty, fextx, Owner.MapFullBounds.Height + 2 * fexty); sbatch.DrawStretched(Textures.TexPixel, rn, FlatColors.Clouds); sbatch.DrawStretched(Textures.TexPixel, re, FlatColors.Clouds); sbatch.DrawStretched(Textures.TexPixel, rs, FlatColors.Clouds); sbatch.DrawStretched(Textures.TexPixel, rw, FlatColors.Clouds); FlatRenderHelper.DrawForegroundDropShadow(sbatch, Owner.MapFullBounds, GDConstants.TILE_WIDTH / 2f, GDConstants.TILE_WIDTH / 2f); for (int ox = 0; ox < Owner.MapFullBounds.Width / TILE_WIDTH; ox++) { var px = ox * TILE_WIDTH + TILE_WIDTH / 2f; sbatch.DrawCentered(Textures.TexDotLine, new FPoint(px, 0), 3f, TILE_WIDTH, Color.White, FloatMath.RAD_POS_090); sbatch.DrawCentered(Textures.TexDotLine, new FPoint(px, Owner.MapFullBounds.Height), 3f, TILE_WIDTH, Color.White, FloatMath.RAD_POS_090); } for (int oy = 0; oy < Owner.MapFullBounds.Height / TILE_WIDTH; oy++) { var py = oy * TILE_WIDTH + TILE_WIDTH / 2f; sbatch.DrawCentered(Textures.TexDotLine, new FPoint(0, py), 3f, TILE_WIDTH, Color.White, FloatMath.RAD_POS_000); sbatch.DrawCentered(Textures.TexDotLine, new FPoint(Owner.MapFullBounds.Width, py), 3f, TILE_WIDTH, Color.White, FloatMath.RAD_POS_000); } } }
public void RegisterBlockedLine(FPoint start, FPoint end) { var delta = end - start; var angle = delta.ToAngle(); if ((angle + FloatMath.RAD_POS_045) % FloatMath.RAD_POS_180 < FloatMath.RAD_POS_090) { // HORZ if (start.X > end.X) { var tmp = start; start = end; end = tmp; } int firstX = FloatMath.Ceiling((start.X - 8f) / GDConstants.TILE_WIDTH); int lastX = FloatMath.Floor((end.X + 8f) / GDConstants.TILE_WIDTH); int lastoy = FloatMath.Round((start.Y + (end.Y - start.Y) * ((firstX * GDConstants.TILE_WIDTH - start.X) / (end.X - start.X))) / GDConstants.TILE_WIDTH); for (int ox = firstX + 1; ox <= lastX; ox++) { var oy = FloatMath.Round((start.Y + (end.Y - start.Y) * ((ox * GDConstants.TILE_WIDTH - start.X) / (end.X - start.X))) / GDConstants.TILE_WIDTH); if (oy != lastoy) { BlockSegmentVert(ox + MAX_EXTENSION_X - 1, lastoy + MAX_EXTENSION_Y, oy + MAX_EXTENSION_Y); } BlockSegmentHorz(oy + MAX_EXTENSION_Y, ox - 1 + MAX_EXTENSION_X, ox + MAX_EXTENSION_X); lastoy = oy; } } else { // VERT if (start.Y > end.Y) { var tmp = start; start = end; end = tmp; } int firstY = FloatMath.Ceiling((start.Y - 8f) / GDConstants.TILE_WIDTH); int lastY = FloatMath.Floor((end.Y + 8f) / GDConstants.TILE_WIDTH); int lastox = FloatMath.Round((start.X + (end.X - start.X) * ((firstY * GDConstants.TILE_WIDTH - start.Y) / (end.Y - start.Y))) / GDConstants.TILE_WIDTH); for (int oy = firstY + 1; oy <= lastY; oy++) { var ox = FloatMath.Round((start.X + (end.X - start.X) * ((oy * GDConstants.TILE_WIDTH - start.Y) / (end.Y - start.Y))) / GDConstants.TILE_WIDTH); if (ox != lastox) { BlockSegmentHorz(oy + MAX_EXTENSION_Y - 1, lastox + MAX_EXTENSION_X, ox + MAX_EXTENSION_X); } BlockSegmentVert(ox + MAX_EXTENSION_X, oy - 1 + MAX_EXTENSION_Y, oy + MAX_EXTENSION_Y); lastox = ox; } } }
public override void Draw(IBatchRenderer sbatch) { int ioffX = -(int)(Owner.MapOffsetX / TILE_WIDTH); int ioffY = -(int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = MathHelper.Min(MAX_EXTENSION_X, FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH)); int extensionY = MathHelper.Min(MAX_EXTENSION_Y, FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH)); int countX = FloatMath.Ceiling(VAdapter.VirtualTotalWidth / TILE_WIDTH) + 1; int countY = FloatMath.Ceiling(VAdapter.VirtualTotalHeight / TILE_WIDTH) + 1; for (int ox = ioffX - extensionX; ox < ioffX + countX + extensionX; ox++) { for (int oy = ioffY - extensionY; oy < ioffY + countY + extensionY; oy++) { var x = ox + MAX_EXTENSION_X; // real coords -> array coords var y = oy + MAX_EXTENSION_Y; if (x < 0) { continue; } if (y < 0) { continue; } if (x >= tileCountX) { continue; } if (y >= tileCountY) { continue; } var color = GetGridColor(x, y); var rect = new FRectangle(ox * TILE_WIDTH, oy * TILE_WIDTH, TILE_WIDTH, TILE_WIDTH); sbatch.DrawStretched(Textures.TexPixel, rect, color); sbatch.DrawStretched(Textures.TexTileBorder, rect, Color.White); #if DEBUG if (DebugSettings.Get("DebugBackground")) { var tx = rect.X + 8; var ty = rect.Y + 8; sbatch.DrawString( Textures.DebugFontSmall, string.Format("({4}|{5})\n{0,2}: {1:000}\n[{2}]{3}", _grid[x, y].Fraction?.ToString() ?? "##", _grid[x, y].PowerCurr * 100, _grid[x, y].SourceDistance, _grid[x, y].IsNeutralDraining ? "D" : "", ox, oy), new FPoint(tx, ty), _grid[x, y].Fraction?.Color ?? Color.Black); if (_grid[x, y].SpawnSource != null) { SimpleRenderHelper.DrawCross(sbatch, rect, _grid[x, y].SpawnSource.Fraction.Color * 0.5f, 2); } var v4tl = new Vector2(+5, +5); var v4tr = new Vector2(-5, +5); var v4br = new Vector2(-5, -5); var v4bl = new Vector2(+5, -5); if (_grid[x, y].BlockNorth) { sbatch.DrawLine(rect.TopLeft + v4tl, rect.TopRight + v4tr, Color.Yellow * 0.6f, 4); } if (_grid[x, y].BlockEast) { sbatch.DrawLine(rect.TopRight + v4tr, rect.BottomRight + v4br, Color.Yellow * 0.6f, 4); } if (_grid[x, y].BlockSouth) { sbatch.DrawLine(rect.BottomRight + v4br, rect.BottomLeft + v4bl, Color.Yellow * 0.6f, 4); } if (_grid[x, y].BlockWest) { sbatch.DrawLine(rect.BottomLeft + v4bl, rect.TopLeft + v4tl, Color.Yellow * 0.6f, 4); } } #endif } } }
private void DrawColoredPartitions(IBatchRenderer sbatch) { sbatch.FillRectangle(VAdapter.VirtualTotalBoundingBox.RelativeTo(Owner.MapOffset), FlatColors.Background); if (FloatMath.IsEpsilonOne(BackgroundPercentageOverride)) { foreach (var pt in partitions) { sbatch.DrawStretched(Textures.TexPixel, pt.Item2, pt.Item1); } } else { foreach (var pt in partitions) { var color = ColorMath.Blend(FlatColors.Background, pt.Item1, BackgroundPercentageOverride); sbatch.DrawStretched(Textures.TexPixel, pt.Item2, color); } } if (GridLineAlpha > 0) { int offX = (int)(Owner.MapOffsetX / TILE_WIDTH); int offY = (int)(Owner.MapOffsetY / TILE_WIDTH); int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH) + 2; int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH) + 2; int countX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedWidth / TILE_WIDTH); int countY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedHeight / TILE_WIDTH); for (int x = -extensionX; x < countX + extensionX; x++) { for (int y = -extensionY; y < countY + extensionY; y++) { var rx = x - offX; var ry = y - offY; sbatch.DrawStretched( Textures.TexTileBorder, new FRectangle( rx * GDConstants.TILE_WIDTH, ry * GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), Color.White * GridLineAlpha); } } } #if DEBUG if (DebugSettings.Get("DebugBackground")) { foreach (var pt in partitions) { sbatch.FillRectangle(pt.Item2.AsDeflated(GDConstants.TILE_WIDTH / 6, GDConstants.TILE_WIDTH / 6), Color.Blue * 0.1f); sbatch.DrawRectangle(pt.Item2.AsDeflated(GDConstants.TILE_WIDTH / 6, GDConstants.TILE_WIDTH / 6), Color.Blue, Owner.PixelWidth); } } #endif }
public Rectangle CeilOutwards() { return(new Rectangle((int)X, (int)Y, FloatMath.Ceiling(Width), FloatMath.Ceiling(Height))); }