private void HandleCursor(InputHelper input) { Vector2 position = Camera.ConvertScreenToWorld(input.Cursor); if ((input.IsNewButtonPress(Buttons.A) || input.IsNewMouseButtonPress(MouseButtons.LeftButton)) && _fixedMouseJoint == null) { Fixture savedFixture = World.TestPoint(position); if (savedFixture != null) { Body body = savedFixture.Body; _fixedMouseJoint = new FixedMouseJoint(body, position); _fixedMouseJoint.MaxForce = 1000.0f * body.Mass; World.AddJoint(_fixedMouseJoint); body.Awake = true; } } if ((input.IsNewButtonRelease(Buttons.A) || input.IsNewMouseButtonRelease(MouseButtons.LeftButton)) && _fixedMouseJoint != null) { World.RemoveJoint(_fixedMouseJoint); _fixedMouseJoint = null; } if (_fixedMouseJoint != null) { _fixedMouseJoint.WorldAnchorB = position; } }
public void Update(GameTime gameTime) { World.Step(Math.Min((float)gameTime.ElapsedGameTime.TotalSeconds * _timeStepFactor, (1f / 30f))); _inputHelper.update(); _player.Update(gameTime); foreach (var gameObject in _objectList) { if (gameObject.UpForRemoval == false) { gameObject.Update(gameTime); } } Camera2D.Update(gameTime); KeyboardInput(); DestroyOldGameObjects(); RegisterGameObjects(); HandleEndConstraints(); _backgroundObjectsHandler.Update(gameTime); if (_endTimer.Elapsed.TotalSeconds > END_TIME) { EndGame(_winStatus); } if (mouseWatch.ElapsedMilliseconds > 1000) { mouseWatch.Restart(); var mouseState = Mouse.GetState(); //Vector2 mousePos = ConvertUnits.ToDisplayUnits(Camera2D.ConvertScreenToWorld(new Vector2(mouseState.X, mouseState.Y))); Vector2 mousePos = Camera2D.ConvertScreenToWorld(new Vector2(mouseState.X, mouseState.Y)); //Console.WriteLine("MousePos: " + mousePos); } }
public void HandleCursor(InputHelper input, World world, Camera2D camera) { if (input.IsNewMouseButtonPress(KeyBinds.PlayerShoot)) { _magicMissiles.Add(new MagicMissile(_screenManager, world, ObjectBody.Position, camera.ConvertScreenToWorld(input.Cursor), this, 1, 1, (Level)SourceLevel)); AttackTimeStamp = TimeSpan.Zero; CreatureState = CreatureState.Attack; } if (input.IsNewMouseButtonRelease(KeyBinds.PlayerShoot)) { _currColumn = 0; _currRow = 0; } }