diff --git a/EvoNet/Controls/EvoSimControl.cs b/EvoNet/Controls/EvoSimControl.cs
index 621f23d..f01cd45 100644
--- a/EvoNet/Controls/EvoSimControl.cs
+++ b/EvoNet/Controls/EvoSimControl.cs
@@ -180,5 +180,23 @@ protected override void Draw(GameTime gameTime)
simRenderer.Draw(gameTime, null);
base.Draw(gameTime);
}
+
+ private void InitializeComponent()
+ {
+ this.SuspendLayout();
+ //
+ // EvoSimControl
+ //
+ this.ResumeLayout(false);
+
+ }
+
+ public void EvoSimControl_MouseClick(object sender, MouseEventArgs e)
+ {
+ if (e.Button == MouseButtons.Left)
+ {
+ inputManager.OnMouseClick(GetMousePosition());
+ }
+ }
}
}
diff --git a/EvoNet/Controls/EvoSimControl.resx b/EvoNet/Controls/EvoSimControl.resx
new file mode 100644
index 0000000..e5858cc
--- /dev/null
+++ b/EvoNet/Controls/EvoSimControl.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ False
+
+
\ No newline at end of file
diff --git a/EvoNet/EvoNet.csproj b/EvoNet/EvoNet.csproj
index 32581d0..9cea38e 100644
--- a/EvoNet/EvoNet.csproj
+++ b/EvoNet/EvoNet.csproj
@@ -129,6 +129,9 @@
+
+ EvoSimControl.cs
+
MainForm.cs
diff --git a/EvoNet/Forms/MainForm.Designer.cs b/EvoNet/Forms/MainForm.Designer.cs
index a37fdd8..3060a3d 100644
--- a/EvoNet/Forms/MainForm.Designer.cs
+++ b/EvoNet/Forms/MainForm.Designer.cs
@@ -183,6 +183,7 @@ private void InitializeComponent()
this.evoSimControl1.Size = new System.Drawing.Size(697, 564);
this.evoSimControl1.TabIndex = 2;
this.evoSimControl1.Text = "evoSimControl1";
+ this.evoSimControl1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.evoSimControl1_MouseClick);
//
// NumberOfCreaturesAliveGraph
//
diff --git a/EvoNet/Forms/MainForm.cs b/EvoNet/Forms/MainForm.cs
index 5ea6f41..e6bed65 100644
--- a/EvoNet/Forms/MainForm.cs
+++ b/EvoNet/Forms/MainForm.cs
@@ -127,5 +127,10 @@ private void MainForm_Shown(object sender, EventArgs e)
{
networkRenderControl1.Simulation = evoSimControl1.sim;
}
+
+ private void evoSimControl1_MouseClick(object sender, MouseEventArgs e)
+ {
+ evoSimControl1.EvoSimControl_MouseClick(sender, e);
+ }
}
}
diff --git a/EvoNet/Input/InputManager.cs b/EvoNet/Input/InputManager.cs
index 5493596..8c0b6e1 100644
--- a/EvoNet/Input/InputManager.cs
+++ b/EvoNet/Input/InputManager.cs
@@ -1,4 +1,5 @@
using EvoNet.Configuration;
+using EvoNet.Objects;
using EvoNet.Providers;
using EvoNet.Rendering;
using EvoSim;
@@ -59,6 +60,26 @@ public override void Initialize(Simulation ingame)
scrollWheelValue = Mouse.GetState().ScrollWheelValue;
}
+ public void OnMouseClick(Vector2 mousePosition)
+ {
+ Vector2 mousePos = Vector2.Transform(mousePosition, Matrix.Invert(camera.Matrix));
+ float distanceSq = float.MaxValue;
+ Creature closestCreature = null;
+ foreach (Creature creature in simulation.CreatureManager.Creatures)
+ {
+ float distance = (creature.Pos.ToXNA() - mousePos).LengthSquared();
+ if (distance < distanceSq)
+ {
+ distanceSq = distance;
+ closestCreature = creature;
+ }
+ }
+ if (closestCreature != null)
+ {
+ simulation.CreatureManager.SelectedCreature = closestCreature;
+ }
+ }
+
protected override void Update(float gameTime)
{
KeyboardState keyboardState = Keyboard.GetState();