From 2e9134fba0b1a13ef07c986f9533a8a353571bb9 Mon Sep 17 00:00:00 2001 From: Joseph Dillon Date: Sun, 15 Apr 2012 19:25:32 -0400 Subject: [PATCH] added ghost display to renderer --- FieldLogic.cs | 1 + FieldRenderer.cs | 28 ++++++++++++++++++++++++---- InterleavedFieldManager.cs | 5 ++++- Program.cs | 1 + ResourceCommons.cs | 2 ++ Tetramino.cs | 22 +++++++++++++++------- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/FieldLogic.cs b/FieldLogic.cs index c9066c0..e707f2f 100644 --- a/FieldLogic.cs +++ b/FieldLogic.cs @@ -246,6 +246,7 @@ protected override void DoUpdate(FrameEventArgs e) { field[currentTetramino.x + x, currentTetramino.y + y, false].inUse = map[x, y]; field[currentTetramino.x + x, currentTetramino.y + y, false].color = currentTetramino.color; + field[currentTetramino.x + x, currentTetramino.y + y, false].ghost = false; } if (deferredLock) { diff --git a/FieldRenderer.cs b/FieldRenderer.cs index 228f0e3..d3235f8 100644 --- a/FieldRenderer.cs +++ b/FieldRenderer.cs @@ -45,6 +45,7 @@ public class Cell { public bool inUse = false; public TetraminoColor color = TetraminoColor.Cyan; + public bool ghost = false; } const string UI_FORMAT = "000000"; @@ -154,6 +155,7 @@ public void CopyCommit() { committedCells[x, y].inUse = shownCells[x, y].inUse; committedCells[x, y].color = shownCells[x, y].color; + committedCells[x, y].ghost = shownCells[x, y].ghost; } } @@ -189,6 +191,8 @@ protected override void DoDraw(FrameEventArgs e) DrawTetrion(); GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.Block); DrawBlock(); + GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.BlockGhost); + DrawGhostBlock(); DrawOther(); } @@ -221,11 +225,11 @@ internal void DrawBlock() ResourceCommons.Blocks[committedCells[x, y].color].Draw(); GL.PopMatrix(); } - if (shownCells[x, y].inUse) + if (shownCells[x, y].inUse && !shownCells[x, y].ghost) { - Vector3 point = Vector3.Add(new Vector3((float)x, (float)y, -1f), position); + Vector3 point = Vector3.Add(new Vector3((float)x, (float)y, -1f), position); GL.PushMatrix(); - GL.Translate(point); + GL.Translate(point); ResourceCommons.Blocks[shownCells[x, y].color].Draw(); GL.PopMatrix(); } @@ -233,6 +237,23 @@ internal void DrawBlock() GL.PopMatrix(); } + internal void DrawGhostBlock() + { + GL.PushMatrix(); + GL.Translate(Vector3.Add(position, tetrionBlock)); + for (int x = 0; x < width; x++) + for (int y = 0; y < height; y++) + if (shownCells[x, y].inUse && shownCells[x, y].ghost) + { + Vector3 point = Vector3.Add(new Vector3((float)x, (float)y, -1f), position); + GL.PushMatrix(); + GL.Translate(point); + ResourceCommons.Blocks[shownCells[x, y].color].Draw(); + GL.PopMatrix(); + } + GL.PopMatrix(); + } + internal void DrawOther() { if (IsGameOver) @@ -242,7 +263,6 @@ internal void DrawOther() GL.Translate(Vector3.Add(position, new Vector3(400f, 250f, 0f))); ResourceCommons.LiberationSans.Print("Game Over", QFontAlignment.Centre); QFont.End(); - GL.Disable(EnableCap.Blend); GL.PopMatrix(); } } diff --git a/InterleavedFieldManager.cs b/InterleavedFieldManager.cs index 6fe11e0..cb64e73 100644 --- a/InterleavedFieldManager.cs +++ b/InterleavedFieldManager.cs @@ -94,8 +94,11 @@ protected override void DoDraw(FrameEventArgs e) renderer[i].DrawTetrion(); GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.Block); for (int i = 0; i < (int)players; i++) - { renderer[i].DrawBlock(); + GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.BlockGhost); + for (int i = 0; i < (int)players; i++) + { + renderer[i].DrawGhostBlock(); renderer[i].DrawOther(); } } diff --git a/Program.cs b/Program.cs index d49faaa..11c90ac 100644 --- a/Program.cs +++ b/Program.cs @@ -89,6 +89,7 @@ protected override void OnRenderFrame(FrameEventArgs e) GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); + GL.Enable(EnableCap.Blend); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); diff --git a/ResourceCommons.cs b/ResourceCommons.cs index 1a0e2de..83974d9 100644 --- a/ResourceCommons.cs +++ b/ResourceCommons.cs @@ -52,6 +52,7 @@ static class ResourceCommons public static Texture TetrionTexture; public static Texture Block; + public static Texture BlockGhost; public static Dictionary Blocks = new Dictionary(); public static Dictionary BlockOverlays = new Dictionary(); public static MeshRenderer Tetrion; @@ -76,6 +77,7 @@ public static void Load() BlockOverlays.Add(TetraminoType.T, new Bitmap(Path.Combine(Path.Combine(Path.Combine(".", RESOURCE_DIR), TEXTURES_DIR), "T.png"))); LoadTexture(Path.Combine(Path.Combine(Path.Combine(".", RESOURCE_DIR), TEXTURES_DIR), "tetrion.png"), out TetrionTexture); LoadTexture(Path.Combine(Path.Combine(Path.Combine(".", RESOURCE_DIR), TEXTURES_DIR), "block.png"), out Block); + LoadTexture(Path.Combine(Path.Combine(Path.Combine(".", RESOURCE_DIR), TEXTURES_DIR), "blockGhost.png"), out BlockGhost); PanelBase = new Bitmap(Path.Combine(Path.Combine(Path.Combine(".", RESOURCE_DIR), TEXTURES_DIR), "panel.png")); using (Stream tmp = File.Open(Path.Combine(Path.Combine(Path.Combine(".", RESOURCE_DIR), MODELS_DIR), "blockCyan.xml"), FileMode.Open)) Blocks.Add(TetraminoColor.Cyan, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp))); diff --git a/Tetramino.cs b/Tetramino.cs index 75c981a..816f241 100644 --- a/Tetramino.cs +++ b/Tetramino.cs @@ -48,6 +48,7 @@ struct Tetramino public TetraminoRotation rotation; public int x; public int y; + public bool ghost; } class TetraminoIgnoreColorPosition : EqualityComparer @@ -91,7 +92,8 @@ class TetraminoManager color = TetraminoColor.Cyan, rotation = TetraminoRotation.Left, x = 3, - y = 18 + y = 18, + ghost = false } }, { @@ -102,7 +104,8 @@ class TetraminoManager color = TetraminoColor.Yellow, rotation = TetraminoRotation.Up, x = 4, - y = 18 + y = 18, + ghost = false } }, { @@ -113,7 +116,8 @@ class TetraminoManager color = TetraminoColor.Purple, rotation = TetraminoRotation.Right, x = 4, - y = 17 + y = 17, + ghost = false } }, { @@ -124,7 +128,8 @@ class TetraminoManager color = TetraminoColor.Green, rotation = TetraminoRotation.Right, x = 4, - y = 17 + y = 17, + ghost = false } }, { @@ -135,7 +140,8 @@ class TetraminoManager color = TetraminoColor.Red, rotation = TetraminoRotation.Right, x = 4, - y = 17 + y = 17, + ghost = false } }, { @@ -146,7 +152,8 @@ class TetraminoManager color = TetraminoColor.Orange, rotation = TetraminoRotation.Right, x = 4, - y = 17 + y = 17, + ghost = false } }, { @@ -157,7 +164,8 @@ class TetraminoManager color = TetraminoColor.Blue, rotation = TetraminoRotation.Right, x = 4, - y = 17 + y = 17, + ghost = false } } };