PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Forms/Play.Graphics.cs

http://github.com/Concliff/Maze
C# | 227 lines | 159 code | 30 blank | 38 comment | 27 complexity | 2d30701c1010a90dfccd3e4183f5921a MD5 | raw file
  1. using Maze.Classes;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.Collections.Generic;
  5. namespace Maze.Forms
  6. {
  7. partial class Play
  8. {
  9. void RightPanelPB_Paint(object sender, PaintEventArgs e)
  10. {
  11. if (!this.playStarted)
  12. return;
  13. // Total game time
  14. e.Graphics.DrawString("Time: " + (this.gameTime.ElapsedMilliseconds / 1000).ToString(), new Font("Arial", 14), new SolidBrush(Color.White), 10, 30);
  15. // Ooze drops count to collect.
  16. e.Graphics.DrawString("Drops x " + Map.Instance.DropsRemain.ToString(),
  17. new Font("Arial", 14), new SolidBrush(Color.White), 10, 50);
  18. // Game Scores.
  19. e.Graphics.DrawString("Total scores: " + Player.Score, new Font("Arial", 12), new SolidBrush(Color.White), 10, 70);
  20. }
  21. void LeftPanelPB_Paint(object sender, PaintEventArgs e)
  22. {
  23. if (!this.playStarted)
  24. return;
  25. // Calcs Ooze energy percentage
  26. int playerOozePercent = Player.OozeEnergy * 100 / Slug.MaxOozeEnergy;
  27. Brush emptyBrush = new SolidBrush(Color.Black);
  28. Brush filledBrush = new SolidBrush(Color.Green);
  29. Rectangle oozeBar = new Rectangle(20, 100, 100, 30);
  30. Rectangle oozeAmount = new Rectangle(20, 100, 100 * playerOozePercent / 100, 30);
  31. // Draw green and black rectanges to show current Energy level.
  32. e.Graphics.FillRectangle(emptyBrush, oozeBar);
  33. e.Graphics.FillRectangle(filledBrush, oozeAmount);
  34. e.Graphics.DrawString(Player.OozeEnergy.ToString(), new Font("Arial", 14), new SolidBrush(Color.White), 50, 105);
  35. }
  36. void CellPB_Paint(object sender, PaintEventArgs e)
  37. {
  38. // Only when game is started
  39. if (this.playStarted)
  40. RebuildGraphMap(e.Graphics);
  41. }
  42. private void pbAuraIcons_Paint(object sender, PaintEventArgs e)
  43. {
  44. EffectHolder holder = (EffectHolder)((PictureBox)sender).Tag;
  45. int durationInSeconds = holder.Duration / 1000;
  46. // Draw Aura Timer
  47. // Skip if duration == -1 (One-tact effect)
  48. if (holder.EffectInfo.Duration == -1)
  49. return;
  50. // Alignment centre
  51. int x;
  52. if ((durationInSeconds) / 10 > 0)
  53. x = 9;
  54. else
  55. x = 15;
  56. e.Graphics.DrawString(durationInSeconds.ToString(), new Font("Arial", 16), new SolidBrush(Color.White), x, 50);
  57. }
  58. private void SpellBarPB_Paint(object sender, PaintEventArgs e)
  59. {
  60. SpellBarPictureBox paintedSpellPB = (SpellBarPictureBox)sender;
  61. // Draw spell keyboard digits
  62. // Draw bigger white digits and smaller red one simulating text shadow effect.
  63. e.Graphics.DrawString(paintedSpellPB.SpellNumber.ToString(), new Font("Arial", 14, FontStyle.Bold), new SolidBrush(Color.White), 35, -2);
  64. e.Graphics.DrawString(paintedSpellPB.SpellNumber.ToString(), new Font("Arial", 12, FontStyle.Bold), new SolidBrush(Color.Red), 36, 0);
  65. }
  66. private void Play_Paint(object sender, PaintEventArgs e)
  67. {
  68. //RebuildGraphMap();
  69. }
  70. private void pbMenuItems_MouseEnter(object sender, System.EventArgs e)
  71. {
  72. PictureBox SenderPB = (PictureBox)sender;
  73. Graphics g;
  74. g = SenderPB.CreateGraphics();
  75. g.DrawString(SenderPB.Name, this.fontMenu, this.brushMenuSelected, 0, 0);
  76. }
  77. private void pbMenuItems_MouseLeave(object sender, System.EventArgs e)
  78. {
  79. PictureBox SenderPB = (PictureBox)sender;
  80. Graphics g;
  81. g = SenderPB.CreateGraphics();
  82. g.DrawString(SenderPB.Name, this.fontMenu, this.brushMenuUnselected, 0, 0);
  83. }
  84. private void pbMenuItems_Paint(object sender, PaintEventArgs e)
  85. {
  86. PictureBox senderPB = (PictureBox)sender;
  87. e.Graphics.DrawString(senderPB.Name, this.fontMenu, this.brushMenuUnselected, 0, 0);
  88. }
  89. /// <summary>
  90. /// RePaint PlayForm map pictures.
  91. /// Include images of the player, blocks and objects on a block
  92. /// </summary>
  93. private void RebuildGraphMap(Graphics gCellBP)
  94. {
  95. GridLocation PBLocation = new GridLocation();
  96. Cell Block = new Cell();
  97. List<Maze.Classes.Object> objectsOnMap = new List<Maze.Classes.Object>();
  98. // CellGraph
  99. for (int i = 0; i < GlobalConstants.GRIDMAP_WIDTH; ++i)
  100. for (int j = 0; j < GlobalConstants.GRIDMAP_HEIGHT; ++j)
  101. {
  102. // Calculated location point for every block
  103. int x, y;
  104. x = /*CellPB.Location.X*/ +(i - 1) * GlobalConstants.CELL_WIDTH - (Player.Position.X - 25);
  105. y = /*CellPB.Location.Y*/ +(j - 1) * GlobalConstants.CELL_HEIGHT - (Player.Position.Y - 25);
  106. PBLocation.X = Player.Position.Location.X + i - GlobalConstants.GRIDMAP_WIDTH / 2;
  107. PBLocation.Y = Player.Position.Location.Y + j - GlobalConstants.GRIDMAP_HEIGHT / 2;
  108. PBLocation.Z = Player.Position.Location.Z;
  109. PBLocation.Level = Player.Position.Location.Level;
  110. Block = Map.Instance.GetCell(PBLocation);
  111. // Draw Grid Cell image
  112. gCellBP.DrawImage(PictureManager.GetPictureByType(Block.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);
  113. // Draw Start Block
  114. if (Block.HasAttribute(CellAttributes.IsStart))
  115. {
  116. gCellBP.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
  117. }
  118. // Draw Finish Block
  119. if (Block.HasAttribute(CellAttributes.IsFinish))
  120. {
  121. gCellBP.DrawImage(PictureManager.FinishImage, x + 5, y + 5, 40, 40);
  122. }
  123. // Include all objects in this grid
  124. objectsOnMap.AddRange(ObjectContainer.Instance.GetObjects(Block.Location));
  125. }
  126. /* Draw Visible Objects
  127. * Order:
  128. * 1. Slime
  129. * 2. GridObjects
  130. * 3. Units
  131. * 4. Slug
  132. */
  133. Image objectImage;
  134. for (int j = 0; j < 4; ++j)
  135. for (int i = 0; i < objectsOnMap.Count; ++i)
  136. {
  137. // Default NULL
  138. objectImage = null;
  139. switch (j)
  140. {
  141. case 0:
  142. // Slime
  143. if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject &&
  144. ((GridObject)objectsOnMap[i]).GridObjectType == GridObjectTypes.Slime)
  145. {
  146. objectImage = PictureManager.SlimeImage;
  147. }
  148. else
  149. continue;
  150. break;
  151. case 1:
  152. // GridObjects
  153. if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject)
  154. {
  155. GridObject gridObject = (GridObject)objectsOnMap[i];
  156. if (gridObject.GridObjectType == GridObjectTypes.Slime)
  157. continue;
  158. objectImage = PictureManager.GetGridObjectImage(gridObject);
  159. }
  160. else
  161. continue;
  162. break;
  163. case 2:
  164. // Units
  165. if (objectsOnMap[i].ObjectType == ObjectTypes.Unit)
  166. {
  167. Unit unit = (Unit)objectsOnMap[i];
  168. // Check Smoke Cloud
  169. // Draw objects with 'Smoke Cloud' effect if Slug also has it and vice versa
  170. if (!(Player.HasEffectType(EffectTypes.SmokeCloud) ^ unit.HasEffectType(EffectTypes.SmokeCloud)))
  171. objectImage = PictureManager.GetUnitImage(unit);
  172. }
  173. else
  174. continue;
  175. break;
  176. case 3:
  177. // Slug
  178. if (objectsOnMap[i].ObjectType == ObjectTypes.Slug)
  179. objectImage = PictureManager.GetSlugImage((Slug)objectsOnMap[i]);
  180. else
  181. continue;
  182. break;
  183. }
  184. if (objectImage == null)
  185. continue;
  186. // Determine object image coords
  187. // relative to the object position on Cell and Player (as a center of the GridMap)
  188. int xCoord = this.pbGridMap.Size.Width / 2 - ((Player.Position.Location.X - objectsOnMap[i].Position.Location.X) *
  189. GlobalConstants.CELL_WIDTH + Player.Position.X - objectsOnMap[i].Position.X) - objectImage.Size.Width / 2;
  190. int yCoord = this.pbGridMap.Size.Height / 2 - ((Player.Position.Location.Y - objectsOnMap[i].Position.Location.Y) *
  191. GlobalConstants.CELL_HEIGHT + Player.Position.Y - objectsOnMap[i].Position.Y) - objectImage.Size.Height / 2;
  192. gCellBP.DrawImage(objectImage, xCoord, yCoord,
  193. objectImage.Size.Width, objectImage.Size.Height);
  194. }
  195. }
  196. }
  197. }