/// <summary> /// Drop an object into the interacting object /// </summary> /// <param name="interactingObject"></param> private void DropObject(GameObject interactingObject) { LevelManager.Instance.PickedObject = null; pickedObject = null; StateManager.Instance.SetState( "item_picked", 0); StateManager.Instance.SetState( LevelManager.Instance.PickedObjectState, 100 ); List<State> checkedStates = new List<State>(); foreach (string s in interactingObject.interaction.dropper.drops) checkedStates.Add( new State( (s + "_picked"), 100 ) ); if( ( interactingObject.interaction.dropper.trigger.Equals( Dropper.ANY ) && StateManager.Instance.AnyTrue( checkedStates ) ) || ( interactingObject.interaction.dropper.trigger.Equals( Dropper.ALL ) && StateManager.Instance.AllTrue( checkedStates ) ) ) { #region Tutorial if (interactingObject.interaction.text == "Bin" && StateManager.Instance.GetState("tutorial_drop") < 100) { StateManager.Instance.SetState("tutorial_drop", 100); ShowTutorial("Good work! Whenever you attempt to solve a puzzle,\nthe day ends and you wake up again in your room."); } #endregion StateManager.Instance.ModifyStates( interactingObject.interaction.dropper.effects ); } }
/// <summary> /// Pickup up an object you are interacting with /// </summary> /// <param name="interactingObject"></param> private void PickupObject(GameObject interactingObject) { LevelManager.Instance.PickedObject = (Sprite)interactingObject.sprite.Clone(); LevelManager.Instance.PickedObject.textureName = "pick_" + LevelManager.Instance.PickedObject.textureName; LevelManager.Instance.PickedObjectState = interactingObject.interaction.pickUpName + "_picked"; }
/// <summary> /// Checks if the player collides with a game object /// </summary> private void CheckObjectCollisions() { interactingObject = null; foreach (GameObject io in activeObjects) { if (io.interaction != null) { // 1D collision detection // Disabled: doesn't work // We have 2 intervals (a, b) and (c, d) // If (a-d)*(b-c) <= 0 then we have collision //if( ( player.position.X - ( io.interaction.boundX + io.interaction.boundWidth ) ) // * ( ( player.position.X + player.texture.Width ) - io.interaction.boundX ) <= 0 ) if (player.Position.X >= io.interaction.boundX && player.Position.X <= (io.interaction.boundX + io.interaction.boundWidth)) { interactingObject = io; #region Tutorial Popups if (interactingObject.interaction != null ) { if (interactingObject.interaction.affectedStates != null) { // press SPACE to interact with heater if (StateManager.Instance.GetState("tutorial_interaction") < 100) { StateManager.Instance.SetState("tutorial_interaction", 100); ShowTutorial("Press SPACE to interact with objects. \nTry turning off the heater."); } } // interact with computer if (interactingObject.interaction.callback == "news" && StateManager.Instance.GetState(StateManager.STATE_DAY) == 2 && StateManager.Instance.GetState("tutorial_computer_interact") < 100) { StateManager.Instance.SetState("tutorial_computer_interact", 100); ShowTutorial("You can use your computer to look at some news.\nYou might find hints there if you get stuck."); } if ( interactingObject.interaction.callback == "map" && StateManager.Instance.GetState("tutorial_bike") < 100 && StateManager.Instance.GetState(StateManager.STATE_DAY) >= 2 && StateManager.Instance.GetState("visited_neighborhood_2") == 100 ) { StateManager.Instance.SetState("tutorial_bike", 100); ShowTutorial("You can use your bike to quickly navigate\nto other locations you've been to. Press SPACE to open\nup the map, and choose with the left and right arrow keys."); } // pick up garbage bags if (interactingObject.interaction.pickUpName != null && interactingObject.interaction.pickUpName.StartsWith("garbage") && StateManager.Instance.GetState("tutorial_pickup") < 100) { StateManager.Instance.SetState("tutorial_pickup", 100); ShowTutorial("Some objects can be picked up and dropped\nby pressing SPACE. Try picking up the garbage bags\nand dropping them in the trashcan."); } } #endregion if (io.interaction.solid) { if (player.Position.X <= io.interaction.boundX + (io.interaction.boundWidth / 2)) player.moveTo( io.interaction.boundX ); else player.moveTo( io.interaction.boundX + io.interaction.boundWidth ); } } } } }