/// <summary> /// Makes the player respawn at the location passed in parameters /// </summary> /// <param name="spawnPoint">The location of the respawn.</param> public override void RespawnAt(Transform spawnPoint, FacingDirections facingDirection) { // if (!gameObject.activeInHierarchy) // { // //Debug.LogError("Spawn : your Character's gameobject is inactive"); // return; // } UnFreeze(); // we make sure the character is facing right Face(facingDirection); // we raise it from the dead (if it was dead) ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); // we re-enable its 2D collider this.gameObject.MMGetComponentNoAlloc <Collider2D>().enabled = true; // we make it handle collisions again _controller.CollisionsOn(); transform.position = new Vector3(spawnPoint.position.x, spawnPoint.position.y, transform.position.z); if (_health != null) { _health.ResetHealthToMaxHealth(); _health.Revive(); } respawnFeedback?.PlayFeedbacks(); }
private static Point GetPointInfrontOfRobot(Panel panel, FacingDirections facing) { Point forward; switch (facing) { case FacingDirections.UP: forward = panel.Upper; break; case FacingDirections.DOWN: forward = panel.Lower; break; case FacingDirections.LEFT: forward = panel.Left; break; case FacingDirections.RIGHT: forward = panel.Right; break; default: throw new Exception("f**k me"); } return(forward); }
public bool Place(int x, int y, FacingDirections facing) { _x = x; _y = y; _facing = facing; return(true); }
/// <summary> /// Convert facing direction to angle (radians). /// </summary> /// <param name="facingDirection">Facing direction to convert</param> /// <returns>Angle in radians</returns> private static float AngleFromFacingDirection(FacingDirections facingDirection) { switch (facingDirection) { case FacingDirections.N: return(4.71238898f); case FacingDirections.Ne: return(5.49778714f); case FacingDirections.E: return(0.0f); case FacingDirections.Se: return(0.785398163f); case FacingDirections.S: return(1.57079633f); case FacingDirections.Sw: return(2.35619449f); case FacingDirections.W: return(3.14159265f); case FacingDirections.Nw: return(3.92699082f); } throw new Exception("Could not calculate direction from facing directin: " + facingDirection.ToString()); }
public void OnBlockAttack(float damage, GameObject attacker, FacingDirections attackDirection, AttackEffects effect, float power, Vector2 effectDirection, float effectForce) { // if (effect == AttackEffects.HIT) { // this.controller.fsm.UpdateVariable(CharVars.DAMAGE_EFFECT.ToS(), effect); // this.controller.fsm.UpdateVariable(CharVars.NEW_FACING_DIRECTION.ToS(), attackDirection); // this.defenseController.SendSuccessMessage(attacker, effect); // } }
public PhysicsComponent() { this.NearbyUnits = new List <GameObject>(); position = new Vector2(50 * Constants.TILESIZE, 50 * Constants.TILESIZE); destination = position; Speed = Constants.Unit.DEFAULT_SPEED; Up = Down = Left = Right = IsMoving = false; FacingDirection = FacingDirections.DOWN; IsSelected = false; objective = null; }
/// <summary> /// Sets the direction for the player to face. /// </summary> /// <param name="newDirection">The new direction for the player to face.</param> public void SetDirection(FacingDirections newDirection) { //Fire the event if the direction was different if (CurDirection != newDirection) { if (DirectionChangedEvent != null) { DirectionChangedEvent(newDirection); } CurDirection = newDirection; } }
public void FaceDirection(FacingDirections zDirection = FacingDirections.RIGHT) { switch (zDirection) { case FacingDirections.RIGHT: transform.rotation = Quaternion.Euler(0, 90, 0); break; case FacingDirections.LEFT: transform.rotation = Quaternion.Euler(0, -90, 0); break; } }
public void OnReceiveAttack(float damage, GameObject attacker, FacingDirections attackDirection, AttackEffects effect, float power, Vector2 effectDirection, float effectForce, bool blocked) { if (effect == AttackEffects.HIT) { this.controller.fsm.UpdateVariable(CharVars.NEW_FACING_DIRECTION.ToS(), attackDirection); this.controller.fsm.UpdateVariable(CharVars.DAMAGE_EFFECT.ToS(), effect); this.controller.fsm.UpdateVariable(CharVars.DAMAGE_EFFECT_DIRECTION.ToS(), effectDirection); this.controller.fsm.UpdateVariable(CharVars.DAMAGE_EFFECT_FORCE.ToS(), this.hitForce); if (blocked) { this.defenseController.SendBlockAttack(damage, attacker, attackDirection, effect, power, effectDirection, effectForce); } else { this.controller.fsm.UpdateVariable(CharVars.IS_BLOCKING.ToS(), false); this.defenseController.SendSuccessMessage(attacker, effect); } } }
private bool Turn(TurnDirection direction) { var facingAsNumber = (int)_facing; facingAsNumber += 1 * (direction == TurnDirection.Right ? 1 : -1); if (facingAsNumber == 5) { facingAsNumber = 1; } if (facingAsNumber == 0) { facingAsNumber = 4; } _facing = (FacingDirections)facingAsNumber; return(true); }
/// <summary> /// Forces the character to face right or left /// </summary> /// <param name="facingDirection">Facing direction.</param> public virtual void Face(FacingDirections facingDirection) { // Flips the character horizontally if (facingDirection == FacingDirections.Right) { if (!IsFacingRight) { Flip(true); } } else { if (IsFacingRight) { Flip(true); } } }
/// <summary> /// Gets a direction based on a speed value. /// </summary> /// <param name="speed">A Vector2 of the speed the character is moving.</param> /// <param name="curDirection">The current direction value. This is returned if there is no movement.</param> /// <returns></returns> public static FacingDirections GetDirectionFromSpeed(Vector2 speed, FacingDirections curDirection) { //Moving left if (speed.x < 0) { if (speed.y < 0) { return(FacingDirections.SouthWest); } else if (speed.y > 0) { return(FacingDirections.NorthWest); } return(FacingDirections.West); } //Moving right else if (speed.x > 0) { if (speed.y < 0) { return(FacingDirections.SouthEast); } if (speed.y > 0) { return(FacingDirections.NorthEast); } return(FacingDirections.East); } //Moving down if (speed.y < 0) { return(FacingDirections.South); } //Moving up if (speed.y > 0) { return(FacingDirections.North); } //Return the current direction if not moving return(curDirection); }
private int GetPositonAfterMove(int?x, int?y, FacingDirections facing) { switch (facing) { case FacingDirections.East: return((int)x + 1); case FacingDirections.West: return((int)x - 1); case FacingDirections.North: return((int)y + 1); case FacingDirections.South: return((int)y - 1); default: return(-1); } }
/// <summary> /// Makes the player respawn at the location passed in parameters /// </summary> /// <param name="spawnPoint">The location of the respawn.</param> public virtual void RespawnAt(Transform spawnPoint, FacingDirections facingDirection) { if (!gameObject.activeInHierarchy) { //Debug.LogError("Spawn : your Character's gameobject is inactive"); return; } // we make sure the character is facing right Face(facingDirection); // we raise it from the dead (if it was dead) ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); // we re-enable its 2D collider GetComponent <Collider2D>().enabled = true; // we make it handle collisions again _controller.CollisionsOn(); transform.position = spawnPoint.position; if (_health != null) { _health.ResetHealthToMaxHealth(); _health.Revive(); } }
public void SendReceiveAttack(float damage, GameObject attacker, FacingDirections attackDirection, AttackEffects effect, float power, Vector2 effectDirection, float effectForce, bool blocked) { if (OnReceiveAttack != null) { this.OnReceiveAttack(damage, attacker, attackDirection, effect, power, effectDirection, effectForce, blocked); } }
private void Awake() { //Default to South CurDirection = FacingDirections.South; }
public static Vector3[] BuildArcPositions(float radius, float arcLength, int numPoints, float minAngle, float offsetAngle, bool centered, float[] sizes, FacingDirections direction) { if (numPoints < 1) return new Vector3[0]; float[] angles = new float[numPoints]; float totalArcSize = 0.0f; float angleInc = (arcLength / numPoints < minAngle) ? minAngle : arcLength / numPoints; for (int i = 0; i < numPoints; i++) { float theta = (sizes != null) ? ChordAngle(radius, sizes[i] + minAngle) : i * angleInc; angles[i] = theta; totalArcSize += theta; } float startAngle = (centered) ? ((numPoints) * angleInc) * 0.5f : 0.0f; startAngle += offsetAngle; if (centered && sizes != null) startAngle = totalArcSize * 0.5f + offsetAngle - angles[0]*0.5f; Vector3[] points = new Vector3[numPoints + 1]; float totalAngle = startAngle; float dirModifier = (direction == FacingDirections.INWARDS) ? -1.0f : 1.0f; for (int i = 0; i <= numPoints; i++) { for (int j = (i < 1 ? 0 : 1); j < 2; j++) { float angle = (i > 0) ? angles[i - 1] * j : 0.0f; points[i] = new Vector3( Mathf.Cos(totalAngle + (angle * dirModifier)) * radius, Mathf.Sin(totalAngle + (angle * dirModifier)) * radius, 0.0f ); totalAngle -= angle; } } return points; }
private bool TryGetFacingDirection(string direction, out FacingDirections facing) { return(Enum.TryParse <FacingDirections>(direction, true, out facing)); }
public void FlipTo(Dictionary<string, object> parameters, FacingDirections facingDirection) { parameters[this.facingDirectionVariable] = (FacingDirections)((int)facingDirection); Vector3 localScale = this.gameObject.transform.localScale; if (Tools.GetValueSign(localScale.x) != (int)facingDirection) { localScale.x *= -1; } this.gameObject.transform.localScale = localScale; }
/// <summary> /// Makes the player respawn at the location passed in parameters /// </summary> /// <param name="spawnPoint">The location of the respawn.</param> public virtual void RespawnAt(Transform spawnPoint, FacingDirections facingDirection) { transform.position = spawnPoint.position; if (!gameObject.activeInHierarchy) { gameObject.SetActive(true); //Debug.LogError("Spawn : your Character's gameobject is inactive"); } // we raise it from the dead (if it was dead) ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); // we re-enable its 2D collider if (this.gameObject.MMGetComponentNoAlloc <Collider2D>() != null) { this.gameObject.MMGetComponentNoAlloc <Collider2D>().enabled = true; } // we re-enable its 2D collider if (this.gameObject.MMGetComponentNoAlloc <Collider>() != null) { this.gameObject.MMGetComponentNoAlloc <Collider>().enabled = true; } // we make it handle collisions again _controller.enabled = true; _controller.CollisionsOn(); _controller.Reset(); // we kill all potential velocity if (this.gameObject.MMGetComponentNoAlloc <Rigidbody>() != null) { this.gameObject.MMGetComponentNoAlloc <Rigidbody>().velocity = Vector3.zero; } if (this.gameObject.MMGetComponentNoAlloc <Rigidbody2D>() != null) { this.gameObject.MMGetComponentNoAlloc <Rigidbody2D>().velocity = Vector3.zero; } Reset(); if (_health != null) { _health.ResetHealthToMaxHealth(); _health.Revive(); } if (CharacterBrain != null) { CharacterBrain.enabled = true; } // facing direction if (FindAbility <CharacterOrientation2D>() != null) { FindAbility <CharacterOrientation2D>().Face(facingDirection); } // facing direction if (FindAbility <CharacterOrientation3D>() != null) { FindAbility <CharacterOrientation3D>().Face(facingDirection); } }
public static void Draw(SpriteBatch spriteBatch, Vector2 position, SpriteComponent spriteComponent, FacingDirections FacingDirection) { var textureSizeModified = Constants.TILESIZE * spriteComponent.TextureModifier; var originVectorModified = spriteComponent.TextureModifier == 1 ? Vector2.Zero : new Vector2(textureSizeModified / 3, textureSizeModified / 2); var pot = position - Camera.position; DrawHitBoxes(spriteBatch, position, spriteComponent); spriteBatch.Draw(spriteComponent.Texture, position - Camera.position, AnimationProcessor.GetFrame(spriteComponent.AnimationComponent), Color.White, 0, originVectorModified, 1, SpriteEffects.None, Constants.Sprites.DEFAULT_UNIT_INDEX); }