//Handles a click on the form, used for selecting a creature public void HandleClick(int X, int Y) { //Clicks on fullscreen are not being handled here if (!isFullscreen) { selectedCreature = null; foreach (SimulationObjects.Creature creature in Managers.CreatureManager.creatures) { if (Vector2.Distance(new Vector2( X * (float)((float)GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / (float)Program.mainForm1.Controls["PanelRender"].Width), Y * (float)((float)GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / (float)Program.mainForm1.Controls["PanelRender"].Height) ), creature.Location) <= (creature.Size / 2)) { selectedCreature = creature; } } } }
//The Update loop protected override void Update(GameTime gameTime) { if (isFullscreen) { //Handle mouseclick on fullscreen MouseState ms = Mouse.GetState(); if (ms.LeftButton == ButtonState.Pressed) { selectedCreature = null; foreach (SimulationObjects.Creature creature in Managers.CreatureManager.creatures) { if (Vector2.Distance(new Vector2(ms.X, ms.Y), creature.Location) <= (creature.Size / 2)) { selectedCreature = creature; } } } //Play/pause if (Keyboard.GetState().IsKeyDown(Keys.F2) && (wasf2down == false)) { wasf2down = true; PlayPause(); } if (Keyboard.GetState().IsKeyUp(Keys.F2)) { wasf2down = false; } //Switch back to windowed mode if (Keyboard.GetState().IsKeyDown(Keys.Escape) || Keyboard.GetState().IsKeyDown(Keys.F4)) { DisableFullscreen(); } } if (!isPaused) { //Update objects Managers.CreatureManager.UpdateAll(gameTime, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); Managers.FoodManager.UpdateAll(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); Managers.PoisonManager.UpdateAll(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); base.Update(gameTime); } }