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
Original file line number Diff line number Diff line change
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].color = currentTetramino.color;
field[currentTetramino.x + x, currentTetramino.y + y, false].ghost = false;
}
if (deferredLock)
{
Expand Down
28 changes: 24 additions & 4 deletions FieldRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -221,18 +225,35 @@ 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();
}
}
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)
Expand All @@ -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();
}
}
Expand Down
5 changes: 4 additions & 1 deletion InterleavedFieldManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
1 change: 1 addition & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions ResourceCommons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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")));
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)));
Expand Down
22 changes: 15 additions & 7 deletions Tetramino.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct Tetramino
public TetraminoRotation rotation;
public int x;
public int y;
public bool ghost;
}

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

0 comments on commit 2e9134f

Please sign in to comment.