/// <summary> /// Updates each ship component and checks if player is close enough to interact with it /// </summary> /// <param name="component">Ship Object</param> /// <param name="gameTime">GameTime variable</param> private void UpdateShipComponent(ShipComponent component, GameTime gameTime) { component.Update(gameTime); Vector2 compPos = component.GetPosition(); float distance = Vector2.Distance(compPos, _player.GetPosition()); if (distance <= _player.interactRad) { _player.SetFocus(component); } }
public void Interact() { _previousState = _currentState; _currentState = Mouse.GetState(); if (_focus != null) { float distance = Vector2.Distance(_position, _focus.GetPosition()); if (distance > interactRad) { // If player is too far from the Interactable Object (ie. ShipComponent) // then cancel current action and reset focus to a null value to prevent it from being interacted again from a distance _focus.Cancel(); _focus = null; _fixProgress.SetActive(false); return; } BreakableComponent b = _focus as BreakableComponent; if (_currentState.LeftButton == ButtonState.Released && _previousState.LeftButton == ButtonState.Pressed) { if (b != null) { if (b.IsBroken()) { Item item = _inventory.items.Find(i => i.itemType == b.GetRequiredItem()); if (item == null) { return; } _fixProgress.SetActive(true); } } _focus.Interact(); } if (b != null) { _fixProgress.UpdateProgress(b.GetFixProgress()); } } }