Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added ghost display to renderer

  • Loading branch information...
commit 2e9134fba0b1a13ef07c986f9533a8a353571bb9 1 parent 9a308e7
Joseph Dillon authored
View
1  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)
{
View
28 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();
}
}
View
5 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();
}
}
View
1  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);
View
2  ResourceCommons.cs
@@ -52,6 +52,7 @@ static class ResourceCommons
public static Texture TetrionTexture;
public static Texture Block;
+ public static Texture BlockGhost;
public static Dictionary<TetraminoColor, MeshRenderer> Blocks = new Dictionary<TetraminoColor, MeshRenderer>();
public static Dictionary<TetraminoType, Bitmap> BlockOverlays = new Dictionary<TetraminoType, Bitmap>();
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)));
View
22 Tetramino.cs
@@ -48,6 +48,7 @@ struct Tetramino
public TetraminoRotation rotation;
public int x;
public int y;
+ public bool ghost;
}
class TetraminoIgnoreColorPosition : EqualityComparer<Tetramino>
@@ -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
}
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.