Form1.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Drawing.Drawing2D;
  10. using CommonAI.RTS;
  11. using System.IO;
  12. namespace CommonTest
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. this.DoubleBuffered = true;
  19. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  20. InitializeComponent();
  21. GameWorld.global_font = this.Font;
  22. this.MouseWheel += new MouseEventHandler(form1_MouseWheel);
  23. this.mapmask = (Bitmap)Bitmap.FromFile(Application.StartupPath + "\\res\\MapData.png");
  24. }
  25. //---------------------------------------------------------------------------------------
  26. Bitmap mapmask;
  27. GameWorld world;
  28. GameUnit actor;
  29. private void Form1_Load(object sender, EventArgs e)
  30. {
  31. string path = "F:\\projects\\morefuntek\\Heros\\Client\\GameEditors\\SceneEditor\\Assets\\DGodWorld\\Data\\";
  32. XLSLoader xls = new XLSLoader();
  33. using (FileStream fs = new FileStream(path + "TriggerTemplate.xls.xml", FileMode.Open))
  34. {
  35. xls.LoadTriggerTemplate(fs);
  36. }
  37. using (FileStream fs = new FileStream(path + "UnitTemplate.xls.xml", FileMode.Open))
  38. {
  39. xls.LoadUnitTemplate(fs);
  40. }
  41. this.world = GameWorld.createLOL(mapmask);
  42. this.world.test_AddActor("Actor");
  43. }
  44. private void restart3CToolStripMenuItem_Click(object sender, EventArgs e)
  45. {
  46. this.world = GameWorld.create3C();
  47. this.world.test_AddActor("Actor");
  48. }
  49. private void restart4AToolStripMenuItem_Click(object sender, EventArgs e)
  50. {
  51. this.world = GameWorld.create4A();
  52. this.world.test_AddActor("Actor");
  53. }
  54. private void restartLOLToolStripMenuItem_Click(object sender, EventArgs e)
  55. {
  56. this.world = GameWorld.createLOL(mapmask);
  57. this.world.test_AddActor("Actor");
  58. }
  59. //---------------------------------------------------------------------------------------
  60. // timer 2 for render system
  61. private void timer2_Tick(object sender, EventArgs e)
  62. {
  63. world.setWindow(new RectangleF(0, 0, pictureBox1.Width, pictureBox1.Height));
  64. world.update();
  65. actor = world.getUnitByName("Actor");
  66. if (actor != null)
  67. {
  68. world.setCamera(actor.pos.x, actor.pos.y);
  69. }
  70. pictureBox1.Refresh();
  71. }
  72. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  73. {
  74. world.renderWorld(e.Graphics);
  75. world.renderHUD(e.Graphics, actor);
  76. }
  77. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  78. {
  79. float wx = world.screenToWorldX(e.X);
  80. float wy = world.screenToWorldY(e.Y);
  81. if (actor != null)
  82. {
  83. if (e.Button == MouseButtons.Left)
  84. {
  85. world.test_UnitMove(actor.ID, wx, wy);
  86. }
  87. else if (e.Button == MouseButtons.Right)
  88. {
  89. world.test_UnitSlip(actor.ID, wx, wy);
  90. }
  91. }
  92. }
  93. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  94. {
  95. float wx = world.screenToWorldX(e.X);
  96. float wy = world.screenToWorldY(e.Y);
  97. if (actor != null)
  98. {
  99. if (e.Button == MouseButtons.Left)
  100. {
  101. world.test_UnitMove(actor.ID, wx, wy);
  102. }
  103. }
  104. }
  105. private void Form1_KeyDown(object sender, KeyEventArgs e)
  106. {
  107. if (actor != null)
  108. {
  109. if (e.KeyCode >= Keys.D1 && e.KeyCode <= Keys.D9)
  110. {
  111. world.test_UnitAttack(actor.ID, 1 + (e.KeyCode - Keys.D1));
  112. }
  113. }
  114. }
  115. private void spawnUnitToolStripMenuItem_Click(object sender, EventArgs e)
  116. {
  117. for (int i = 0; i < 10; i++)
  118. {
  119. world.test_AddUnit("Enemy");
  120. }
  121. }
  122. private void spawnUnit100ToolStripMenuItem_Click(object sender, EventArgs e)
  123. {
  124. for (int i = 0; i < 100; i++)
  125. {
  126. world.test_AddUnit("Enemy");
  127. }
  128. }
  129. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  130. {
  131. for (int i = 0; i < 1000; i++)
  132. {
  133. world.test_AddUnit("Enemy");
  134. }
  135. }
  136. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  137. {
  138. for (int i = 0; i < 10000; i++)
  139. {
  140. world.test_AddUnit("Enemy");
  141. }
  142. }
  143. void form1_MouseWheel(object sender, MouseEventArgs e)
  144. {
  145. int d = RTSMath.getDirect(e.Delta) ;
  146. if (d > 0)
  147. {
  148. world.setCameraScale(world.getCameraScale() * 1.1f);
  149. }
  150. else if (d < 0)
  151. {
  152. world.setCameraScale(world.getCameraScale() / 1.1f);
  153. }
  154. }
  155. }
  156. }