void SetSelectedObj(GameObject newSelection) { // Ignore new selections if picking up or holding object InteractState state = gameObject.GetComponentInParent <PlayerMovement>().interactState; if (state == InteractState.PickingUp || state == InteractState.Holding) { return; } // Deselect current selection if (selectedObj != null) { selectedObj.GetComponent <InteractiveObj>().Deselected(); } // Set new selected object selectedObj = newSelection; // Select new selection if (selectedObj != null) { selectedObj.GetComponent <InteractiveObj>().Selected(); } }
InteractState ManageDestroyLure(InteractState previous, InteractStateParam param) { //NOTHING InteractState newState = InteractState.Nothing; return(newState); }
private void Update() { onGround = IsGrounded(); previousMovementState = movementState; InputParams inputParams = inputController.RetrieveUserRequest(); //deplacements MoveAccordingToInput(inputParams); InteractAccordingToInput(inputParams); previousInteractState = interactState; UpdateMoveStateParameters(inputParams); UpdateInteractStateParameters(inputParams); movementState = moveStateCtrl.GetNewState(movementState, moveStateParameters); interactState = InteractStateCtrl.GetNewState(interactState, interactStateParameter); float speed = Mathf.Sqrt(Mathf.Pow(inputParams.moveX, 2) + Mathf.Pow(inputParams.moveZ, 2)); if (previousMovementState != movementState) { animBody.OnStateExit(previousMovementState); animBody.OnStateEnter(movementState); } if (previousInteractState != interactState) { animBody.OnStateExit(previousInteractState); animBody.OnStateEnter(interactState); } animBody.UpdateState(movementState, speed, moveSpeed); }
public void Ungrab() { grabbedObj = null; EnableInputMovement(); interactState = InteractState.Idle; }
public void Grab(GameObject obj) { grabbedObj = obj; DisableInputMovement(); interactState = InteractState.Grabbing; }
private IEnumerator Recover() { this._state = InteractState.RECOVERY; if (this._singleUse) { this.Used = true; this._hideInteractUI.Invoke(); this.enabled = false; yield break; } float elapsedTime = 0.0f; while (elapsedTime <= this._recoveryTime.Value) { if (GameConstants.paused) { yield return(null); continue; } yield return(null); elapsedTime += Time.deltaTime; } this._state = InteractState.STANDY; }
public void StartInteract() { if (selectedObj == null) { return; } List <Tags> tags = selectedObj.GetComponent <CustomTags>().tags; InteractState state = gameObject.GetComponentInParent <PlayerMovement>().interactState; if (state == InteractState.Holding) { gameObject.GetComponentInParent <PlayerMovement>().ThrowObj(); } else if (state == InteractState.Throwing) { return; } // Grabbable needs to take precedence over Interactive as objects that are both // need to be grabbed (e.g. draggable objects) else if (tags.Contains(Tags.Grabbable)) { // Grab gameObject.GetComponentInParent <PlayerMovement>().Grab(selectedObj); } else if (tags.Contains(Tags.Interactive)) { // Interact selectedObj.GetComponent <InteractiveObj>().Interact(gameObject.transform.parent.gameObject); } }
private void StopInteracting() { this._elapsedTime = 0.0f; this._variables.fillAmount = 0.0f; this._state = InteractState.STANDY; this._endInteractUI.Invoke(); }
private void StartInteracting() { this._state = InteractState.INTERACTING; this._elapsedTime = 0.0f; this._variables.fillAmount = 0.0f; this._startInteractUI.Invoke(); }
public void ThrowObj() { DisableInputMovement(); curThrowDur = 0; interactState = InteractState.Throwing; }
InteractState ManageSpawnLure(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING newState = InteractState.Nothing; return(newState); }
public InteractState GetNewState(InteractState previous, InteractStateParam param) { InteractState newState = previous; switch (previous) { case InteractState.Nothing: newState = ManageNothing(previous, param); break; case InteractState.Glide: newState = ManageGlide(previous, param); break; case InteractState.MeleeAttack: newState = ManageMeleeAttack(previous, param); break; case InteractState.DistantAttack: newState = ManageDistantAttack(previous, param); break; case InteractState.SpawnLure: newState = ManageSpawnLure(previous, param); break; case InteractState.DestroyLure: newState = ManageDestroyLure(previous, param); break; case InteractState.Inflate: newState = ManageInflate(previous, param); break; case InteractState.Tiny: newState = ManageResize(previous, param); break; case InteractState.Activate: newState = ManageActivate(previous, param); break; case InteractState.Absorb: newState = ManageAbsorb(previous, param); break; case InteractState.Carry: newState = ManageCarry(previous, param); break; case InteractState.Push: newState = ManagePush(previous, param); break; } return(newState); }
private void Update() { GameObject curClosestObj = ClosestInteractiveObj(); InteractState state = gameObject.GetComponentInParent <PlayerMovement>().interactState; if (selectedObj != curClosestObj) { SetSelectedObj(curClosestObj); } }
InteractState ManageMeleeAttack(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING if (param.finishedMeleeAttack) { newState = InteractState.Nothing; } return(newState); }
InteractState ManageInflate(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING if (param.canInflate) { newState = InteractState.Nothing; } return(newState); }
InteractState ManageActivate(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING if (!param.canGlide) { newState = InteractState.Nothing; } return(newState); }
InteractState ManageAbsorb(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING if (!param.yokaiStillInRange) { newState = InteractState.Nothing; } return(newState); }
InteractState ManageCarry(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING if (param.finishedCarry) { newState = InteractState.Nothing; } return(newState); }
InteractState ManageDistantAttack(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING if (param.finishedDistantAttack) { param.finishedDistantAttack = false; newState = InteractState.Nothing; } return(newState); }
protected override void InteractStateUpdate(InteractState state) { if (state == InteractState.OnAction) { if (innerTimer > 1f) { InteractState = InteractState.EndInteract; } var yVelocity = 2.5f - 2.5f * (innerTimer / 0.5f); transform.localPosition += new Vector3(0f, 1f, 2f) * (yVelocity * Time.deltaTime); } }
InteractState ManageMeleeAttack(InteractState previous, InteractStateParam param) { InteractState newState = previous; //NOTHING //DETECTER LA FIN DE L'ANIMATION OU UN AUTRE MOYEN DE DECLENCHER LE RETOUR A L'ETAT NOTHING if (!param.canGlide) { newState = InteractState.Nothing; } return(newState); }
// Use this for initialization void Start() { this.state = InteractState.Check; this.animator = GetComponent <Animator>(); this.playerMovementSystem = GetComponent <AbilityBasicMovement>(); this.playerDialogueState = GameObject.Find("Player").GetComponent <AbilityDialogue>(); this.DirectionSystem = new FourDirectionSystem(); this.holdItem.enabled = false; this.HPHandler = GetComponent <PlayerHealthComponent>(); this.SPHandler = GetComponent <PlayerSPComponent>(); this.KeyInventory = GetComponent <PlayerKeyInventory>(); }
public void AddInteractState(InteractObject interactObject) { InteractState state = new InteractState() { ID = interactObject.ID, inspectText = interactObject.inspectText, itemId = interactObject.itemId, interactItemId = interactObject.interactItemId, hasItem = interactObject.hasItem, interactable = interactObject.interactable }; Objects.Add(state); }
private void PickingUpObjUpdate() { // Animation finished, swap to "holdingObj" state if (curPickingUpDuration > pickingUpDuration) { interactState = InteractState.Holding; EnableInputMovement(); return; } pickedUpObj.transform.position = Vector3.Lerp(pickedUpSrcPosition, pickedUpDestPosition, curPickingUpDuration / pickingUpDuration); curPickingUpDuration += Time.deltaTime; }
private void Start() { movementState = MovementState.Idle; previousMovementState = movementState; interactState = InteractState.Nothing; previousInteractState = interactState; body = GetComponent <Rigidbody>(); animBody = GetComponent <AnimatorController>(); moveStateParameters = new MovementStateParam(); moveStateCtrl = new MovementStateController(); interactStateParameter = new InteractStateParam(); InteractStateCtrl = new InteractStateController(); inputController = GetComponent <InputController>(); interactBehaviorCtrl = GetComponent <InteractBehavior>(); }
protected override void SetActiveState(bool state) { if (state) { HUDManager.ShowInteractionText(); HUDManager.HideBeaconDialog(); m_State = InteractState.ShowingText; } else { HUDManager.HideInteractionText(); HUDManager.HideBeaconDialog(); m_State = InteractState.None; } }
public void EndInteract() { if (selectedObj == null) { return; } InteractState state = gameObject.GetComponentInParent <PlayerMovement>().interactState; if (state == InteractState.Grabbing) { // Ungrab gameObject.GetComponentInParent <PlayerMovement>().Ungrab(); } }
public override void OnInteract(PlayerInteractionController controller, bool click = false) { m_PlayerController = controller; if (m_State == InteractState.ShowingText) { HUDManager.HideInteractionText(); var beaconNames = Controller.GetBeacons(); HUDManager.ShowBeaconDialog(beaconNames); HUDManager.ConveyanceSitAction = OnSit; HUDManager.ConveyanceCancelAction = OnSitCancel; m_State = InteractState.DialogOptions; controller.DeactivateGameInput(); } }
public void PickupObject(GameObject obj) { // Maybe add argument for picked up item curPickingUpDuration = 0; DisableInputMovement(); pickedUpObj = obj; pickedUpSrcPosition = pickedUpObj.transform.position; pickedUpDestPosition = gameObject.transform.position; //objDestPosition.y += 4.5f; pickedUpDestPosition.y += height + heightPadding; // Used to rotate object relative to players rotation when picked up pickedUpOffsetRotation = gameObject.transform.rotation.eulerAngles; interactState = InteractState.PickingUp; }
InteractState ManageGlide(InteractState previous, InteractStateParam param) { InteractState newState = previous; if (param.canGlide) { newState = InteractState.Glide; } //NOTHING if (!param.canGlide) { param.canAirStream = false; newState = InteractState.Nothing; } return(newState); }
public void InteractWithObject() { if (interactState == Character.InteractState.HandsEmpty && AdjacentObj != null) { if (AdjacentObj.GetType() == typeof(PickableBox)) { interactState = Character.InteractState.JustPickedUpBox; StoredBox = (PickableBox)AdjacentObj; StoredBox.isCollidable = false; } } }
public void PickBox() { if (interactState == InteractState.HandsEmpty/*state 0*/ && !jumping && !falling) { if (AdjacentObj != null && AdjacentObj.GetType() == typeof(PickableBox) && (((PickableBox)(AdjacentObj)).IsLiftable)) { //check if there is area above the player to pick up the box Rectangle areaTop = new Rectangle((int)Position.X, CharacterHitbox.Bottom + 1, (int)(AdjacentObj.Hitbox.Width), (int)(AdjacentObj.Hitbox.Height)); bool pickuppable = true; // to pick up boxes from under the other this has been commented out //foreach (CellObject levelObject in GameplayScreen.CurrentLevel.Children) //check to see if it has collision with anything //{ // if (levelObject.isCollidable && areaTop.Intersects ( levelObject.Hitbox )) // { // pickuppable = false; // } // /* // + The hitboxes (rectangles) are actually upside down - 'bot' is actually the top, 'top' is the bottom, // * height increases upwards. // */ //} if (jumping || falling) //disallow putting down when jumping pickuppable = false; if (pickuppable) { interactState = InteractState.JustPickedUpBox; //state 1 StoredBox = (PickableBox)AdjacentObj; StoredBox.isCollidable = false; soundEffects.PlaySound("BoxPickup"); } } else if (InteractiveObj != null && InteractiveObj.GetType() == typeof(ToggleSwitch)) { ToggleSwitch currentSwitch = (ToggleSwitch)InteractiveObj; if (currentSwitch.IsToggleable && currentSwitch.IsReady) { soundEffects.PlaySound("ToggleSwitch"); currentSwitch.FlickSwitch(); } } } }
public void PutBox() { //if (/*player.adjacentObj == null*/) //will need a condition for when the adjacent area where the player would be trying to put the box is empty, //{ float sideXPos; float leeway = 10; //leeway allowed to place the box away from you (ie. amount allowed to place a box into another object) if (facingDirection == Character.FACING_RIGHT) { sideXPos = Position.X + Hitbox.Width; } else //facing left { sideXPos = Position.X - StoredBox.Hitbox.Width + leeway * 3; } Rectangle areaSide = new Rectangle((int)sideXPos, (int)Position.Y + 2, (int)StoredBox.Hitbox.Width - (int)leeway, (int)StoredBox.Hitbox.Height); bool putdownable = true; foreach (CellObject levelObject in GameplayScreen.CurrentLevel.Children) //check to see if it has collision with anything { if (levelObject.isCollidable && areaSide.Intersects(levelObject.Hitbox) && levelObject.GetType() != typeof(MessageEvent)) { putdownable = false; } /* + areaSide {X:-92 Y:-313 Width:38 Height:38} Microsoft.Xna.Framework.Rectangle £¨-313 £¨top£©to -275 (bot)£© + Hitbox {X:-112 Y:-360 Width:48 Height:48} Microsoft.Xna.Framework.Rectangle -360 (top£© to -312 (bot) So, the hitboxes (rectangles) are actually upside down - 'bot' is actually the top, 'top' is the bottom, * height increases upwards. */ } if (jumping || falling) //disallow putting down when jumping putdownable = false; if (putdownable) interactState = InteractState.StartingDropBox; //state for while the player begins putting down the box //} }
/// <summary> /// Code to update any animations occurring with PickBox. /// </summary> public void UpdatePickBox() { if (interactState == InteractState.JustPickedUpBox) //determine initial pickup animation angle { if (StoredBox.Position.X < Position.X) pickUpAnimationAngle = 180; else pickUpAnimationAngle = 0; interactState = InteractState.AnimatingPickup; //state 2 } if (interactState == InteractState.AnimatingPickup) //update box position { if (pickUpAnimationAngle != 90) { //endpoint is 90 if (pickUpAnimationAngle > 90) { pickUpAnimationAngle -= 9; //from left } else pickUpAnimationAngle += 9; //from right float angleRad = pickUpAnimationAngle * 2 * (float)Math.PI / 360; StoredBox.Position = Position + new Vector3(CharacterHitbox.Width * (float)Math.Cos(angleRad), CharacterHitbox.Height * (float)Math.Sin(angleRad), 0f); //no need to update hitbox anymore /*StoredBox.Hitbox = new Rectangle ( (int)(Hitbox.Location.X + Hitbox.Width * Math.Cos ( angleRad )), (int)(Hitbox.Location.Y + Hitbox.Height * Math.Sin ( angleRad )), StoredBox.Hitbox.Width, StoredBox.Hitbox.Height );*/ // Position + new Vector3(Hitbox.Width * (float)Math.Cos(angleRad), Hitbox.Height * (float)Math.Sin(angleRad), 0f); //if (storedBox.Position.X > Position.X) // storedBox.Position += new Vector3(-Hitbox.Width / 10, Hitbox.Height / 10, 0); putDownAnimationAngle = 90; } else { interactState = InteractState.CompletedPickup; //state 3 } } else if (interactState == InteractState.CompletedPickup) //state 3s { StoredBox.Position = Position + new Vector3(0, CharacterHitbox.Height, 0); //no need to update hitbox anymore /*StoredBox.Hitbox = new Rectangle ( Hitbox.Location.X, Hitbox.Location.Y + Hitbox.Height, storedBox.Hitbox.Width, storedBox.Hitbox.Height );*/ } }
//need renderContext to access level for collision checking /// <summary> /// Code to update any animations occurring with PutBox. /// </summary> /// <param name="renderContext"></param> public void UpdatePutBox(RenderContext renderContext) { if (interactState == InteractState.StartingDropBox) //state 4 { putFacingDirection = facingDirection; //set the direction the character is facing at the point the character begins putting down the box interactState = InteractState.AnimatingDropBox; } if (interactState == InteractState.AnimatingDropBox) //animation state { if (putDownAnimationAngle > 0 && putDownAnimationAngle < 180) { if (putFacingDirection == FACING_RIGHT) putDownAnimationAngle -= 9; else //if(putFacingDirection == FACING_LEFT) putDownAnimationAngle += 9; float angleRad = putDownAnimationAngle * 2 * (float)Math.PI / 360; StoredBox.Position = Position + new Vector3(CharacterHitbox.Width * (float)Math.Cos(angleRad), CharacterHitbox.Height * (float)Math.Sin(angleRad), 0f); //no need to update hitbox /* storedBox.Hitbox = new Rectangle ( (int)(Hitbox.Location.X + Hitbox.Width * Math.Cos ( angleRad )), (int)(Hitbox.Location.Y + Hitbox.Height * Math.Sin ( angleRad )), storedBox.Hitbox.Width, storedBox.Hitbox.Height ); */ } else { interactState = InteractState.HandsEmpty; StoredBox.TransVelocity = Vector3.Zero; float startX = (GameConstants.SINGLE_CELL_SIZE * 1) - (GameConstants.X_RESOLUTION / 2); float startY = (GameConstants.SINGLE_CELL_SIZE * 1) - (GameConstants.Y_RESOLUTION / 2); Vector3 CELLREMAINDER = new Vector3((StoredBox.Position.X - startX) % GameConstants.SINGLE_CELL_SIZE, (StoredBox.Position.Y - startY) % GameConstants.SINGLE_CELL_SIZE, StoredBox.Position.Z); //Move positions to the nearest cell if (CELLREMAINDER.X < GameConstants.SINGLE_CELL_SIZE / 2) StoredBox.Position = new Vector3(StoredBox.Position.X - CELLREMAINDER.X, StoredBox.Position.Y, StoredBox.Position.Z); else StoredBox.Position = new Vector3(StoredBox.Position.X - CELLREMAINDER.X + GameConstants.SINGLE_CELL_SIZE, StoredBox.Position.Y, StoredBox.Position.Z); /*if (CELLREMAINDER.Y < Game1.SINGLE_CELL_SIZE / 2) storedBox.Position = new Vector3(storedBox.Position.X, storedBox.Position.Y - CELLREMAINDER.Y, storedBox.Position.Z); else storedBox.Position = new Vector3(storedBox.Position.X, storedBox.Position.Y + Game1.SINGLE_CELL_SIZE - CELLREMAINDER.Y, storedBox.Position.Z); if (CELLREMAINDER.Z < Game1.SINGLE_CELL_SIZE / 2) storedBox.Position = new Vector3(storedBox.Position.X, storedBox.Position.Y, storedBox.Position.Z - CELLREMAINDER.Z); else storedBox.Position = new Vector3(storedBox.Position.X, storedBox.Position.Y, storedBox.Position.Z + Game1.SINGLE_CELL_SIZE - CELLREMAINDER.Z);*/ //quantize position to a multiple of SINGLE_CELL_SIZE StoredBox.CheckCollision(renderContext.Level); //check and update box position based on collision before updating any other boxes' positions //remove storedBox from player StoredBox.isCollidable = true; StoredBox = null; soundEffects.PlaySound("BoxDrop"); } } }
// Update is called once per frame void Update () { //If we have an event run it and when it ends null it if(interactState != null) { if (interactState.update()) interactState = null; return; } if (Input.GetKeyUp(KeyCode.Space)) { Vector3 magnitudeCheck; foreach (Teleporter teleporter in TheGame.get().teleporters) { magnitudeCheck = teleporter.transform.position - transform.position; magnitudeCheck.y = 0; if (magnitudeCheck.magnitude < interactRange) { transform.position = teleporter.teleportTo; Debug.Log(teleporter.teleportTo); Debug.Log(transform.position); break; } } foreach (Finisher finisher in TheGame.get().finishers) { magnitudeCheck = finisher.transform.position - transform.position; magnitudeCheck.y = 0; if (magnitudeCheck.magnitude < interactRange) { TheGame.get().teleporters.Clear(); TheGame.get().finishers.Clear(); TheGame.get().stressers.Clear(); TheGame.get().triggers.Clear(); SceneManager.LoadScene(finisher.sceneGoto); break; } } foreach (MissionTrigger trigger in TheGame.get().triggers) { magnitudeCheck = trigger.transform.position - transform.position; magnitudeCheck.y = 0; if (magnitudeCheck.magnitude < interactRange) { TheGame theGame = TheGame.get(); theGame.missionStep++; if(theGame.missionStep == theGame.missionGoals.Length) { theGame.teleporters.Clear(); theGame.finishers.Clear(); theGame.stressers.Clear(); theGame.triggers.Clear(); SceneManager.LoadScene(theGame.missionEndScene); return; } theGame.missionText.text = theGame.missionGoals[theGame.missionStep]; } } foreach (Stresser stresser in TheGame.get().stressers) { magnitudeCheck = stresser.transform.position - transform.position; magnitudeCheck.y = 0; if (magnitudeCheck.magnitude < interactRange) { //TODO : Add stress } } } //TODO : Check for more events }