Skip to content

Commit

Permalink
added ghost display to renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Dillon committed Apr 15, 2012
1 parent 9a308e7 commit 2e9134f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
1 change: 1 addition & 0 deletions FieldLogic.cs
Expand Up @@ -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].inUse = map[x, y];
field[currentTetramino.x + x, currentTetramino.y + y, false].color = currentTetramino.color; field[currentTetramino.x + x, currentTetramino.y + y, false].color = currentTetramino.color;
field[currentTetramino.x + x, currentTetramino.y + y, false].ghost = false;
} }
if (deferredLock) if (deferredLock)
{ {
Expand Down
28 changes: 24 additions & 4 deletions FieldRenderer.cs
Expand Up @@ -45,6 +45,7 @@ public class Cell
{ {
public bool inUse = false; public bool inUse = false;
public TetraminoColor color = TetraminoColor.Cyan; public TetraminoColor color = TetraminoColor.Cyan;
public bool ghost = false;
} }


const string UI_FORMAT = "000000"; const string UI_FORMAT = "000000";
Expand Down Expand Up @@ -154,6 +155,7 @@ public void CopyCommit()
{ {
committedCells[x, y].inUse = shownCells[x, y].inUse; committedCells[x, y].inUse = shownCells[x, y].inUse;
committedCells[x, y].color = shownCells[x, y].color; committedCells[x, y].color = shownCells[x, y].color;
committedCells[x, y].ghost = shownCells[x, y].ghost;
} }
} }


Expand Down Expand Up @@ -189,6 +191,8 @@ protected override void DoDraw(FrameEventArgs e)
DrawTetrion(); DrawTetrion();
GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.Block); GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.Block);
DrawBlock(); DrawBlock();
GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.BlockGhost);
DrawGhostBlock();
DrawOther(); DrawOther();
} }


Expand Down Expand Up @@ -221,18 +225,35 @@ internal void DrawBlock()
ResourceCommons.Blocks[committedCells[x, y].color].Draw(); ResourceCommons.Blocks[committedCells[x, y].color].Draw();
GL.PopMatrix(); 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.PushMatrix();
GL.Translate(point); GL.Translate(point);
ResourceCommons.Blocks[shownCells[x, y].color].Draw(); ResourceCommons.Blocks[shownCells[x, y].color].Draw();
GL.PopMatrix(); GL.PopMatrix();
} }
} }
GL.PopMatrix(); 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() internal void DrawOther()
{ {
if (IsGameOver) if (IsGameOver)
Expand All @@ -242,7 +263,6 @@ internal void DrawOther()
GL.Translate(Vector3.Add(position, new Vector3(400f, 250f, 0f))); GL.Translate(Vector3.Add(position, new Vector3(400f, 250f, 0f)));
ResourceCommons.LiberationSans.Print("Game Over", QFontAlignment.Centre); ResourceCommons.LiberationSans.Print("Game Over", QFontAlignment.Centre);
QFont.End(); QFont.End();
GL.Disable(EnableCap.Blend);
GL.PopMatrix(); GL.PopMatrix();
} }
} }
Expand Down
5 changes: 4 additions & 1 deletion InterleavedFieldManager.cs
Expand Up @@ -94,8 +94,11 @@ protected override void DoDraw(FrameEventArgs e)
renderer[i].DrawTetrion(); renderer[i].DrawTetrion();
GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.Block); GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.Block);
for (int i = 0; i < (int)players; i++) for (int i = 0; i < (int)players; i++)
{
renderer[i].DrawBlock(); renderer[i].DrawBlock();
GL.BindTexture(TextureTarget.Texture2D, ResourceCommons.BlockGhost);
for (int i = 0; i < (int)players; i++)
{
renderer[i].DrawGhostBlock();
renderer[i].DrawOther(); renderer[i].DrawOther();
} }
} }
Expand Down
1 change: 1 addition & 0 deletions Program.cs
Expand Up @@ -89,6 +89,7 @@ protected override void OnRenderFrame(FrameEventArgs e)
GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.CullFace);
GL.Enable(EnableCap.Blend);


GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


Expand Down
2 changes: 2 additions & 0 deletions ResourceCommons.cs
Expand Up @@ -52,6 +52,7 @@ static class ResourceCommons


public static Texture TetrionTexture; public static Texture TetrionTexture;
public static Texture Block; public static Texture Block;
public static Texture BlockGhost;
public static Dictionary<TetraminoColor, MeshRenderer> Blocks = new Dictionary<TetraminoColor, MeshRenderer>(); public static Dictionary<TetraminoColor, MeshRenderer> Blocks = new Dictionary<TetraminoColor, MeshRenderer>();
public static Dictionary<TetraminoType, Bitmap> BlockOverlays = new Dictionary<TetraminoType, Bitmap>(); public static Dictionary<TetraminoType, Bitmap> BlockOverlays = new Dictionary<TetraminoType, Bitmap>();
public static MeshRenderer Tetrion; public static MeshRenderer Tetrion;
Expand All @@ -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"))); 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), "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), "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")); 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)) 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))); Blocks.Add(TetraminoColor.Cyan, new MeshRenderer((Mesh)modelSerializer.Deserialize(tmp)));
Expand Down
22 changes: 15 additions & 7 deletions Tetramino.cs
Expand Up @@ -48,6 +48,7 @@ struct Tetramino
public TetraminoRotation rotation; public TetraminoRotation rotation;
public int x; public int x;
public int y; public int y;
public bool ghost;
} }


class TetraminoIgnoreColorPosition : EqualityComparer<Tetramino> class TetraminoIgnoreColorPosition : EqualityComparer<Tetramino>
Expand Down Expand Up @@ -91,7 +92,8 @@ class TetraminoManager
color = TetraminoColor.Cyan, color = TetraminoColor.Cyan,
rotation = TetraminoRotation.Left, rotation = TetraminoRotation.Left,
x = 3, x = 3,
y = 18 y = 18,
ghost = false
} }
}, },
{ {
Expand All @@ -102,7 +104,8 @@ class TetraminoManager
color = TetraminoColor.Yellow, color = TetraminoColor.Yellow,
rotation = TetraminoRotation.Up, rotation = TetraminoRotation.Up,
x = 4, x = 4,
y = 18 y = 18,
ghost = false
} }
}, },
{ {
Expand All @@ -113,7 +116,8 @@ class TetraminoManager
color = TetraminoColor.Purple, color = TetraminoColor.Purple,
rotation = TetraminoRotation.Right, rotation = TetraminoRotation.Right,
x = 4, x = 4,
y = 17 y = 17,
ghost = false
} }
}, },
{ {
Expand All @@ -124,7 +128,8 @@ class TetraminoManager
color = TetraminoColor.Green, color = TetraminoColor.Green,
rotation = TetraminoRotation.Right, rotation = TetraminoRotation.Right,
x = 4, x = 4,
y = 17 y = 17,
ghost = false
} }
}, },
{ {
Expand All @@ -135,7 +140,8 @@ class TetraminoManager
color = TetraminoColor.Red, color = TetraminoColor.Red,
rotation = TetraminoRotation.Right, rotation = TetraminoRotation.Right,
x = 4, x = 4,
y = 17 y = 17,
ghost = false
} }
}, },
{ {
Expand All @@ -146,7 +152,8 @@ class TetraminoManager
color = TetraminoColor.Orange, color = TetraminoColor.Orange,
rotation = TetraminoRotation.Right, rotation = TetraminoRotation.Right,
x = 4, x = 4,
y = 17 y = 17,
ghost = false
} }
}, },
{ {
Expand All @@ -157,7 +164,8 @@ class TetraminoManager
color = TetraminoColor.Blue, color = TetraminoColor.Blue,
rotation = TetraminoRotation.Right, rotation = TetraminoRotation.Right,
x = 4, x = 4,
y = 17 y = 17,
ghost = false
} }
} }
}; };
Expand Down

0 comments on commit 2e9134f

Please sign in to comment.