void FixedUpdate()
    {
        switch (this.State)
        {
            #region Normal
        case AvatarStates.Normal:
        {
            this.CheckAvatarMove();

            this.PlayerInteraction();

            break;
        }
            #endregion
        }


        this.previousState = this.State;

        //Debug.Log(string.Format("Axis H: {0}, V: {1}.", (float)Input.GetAxis(this.playerName + "Horizontal"), (float)Input.GetAxis(this.playerName + "Vertical")));
    }
Example #2
0
    protected virtual void Update()
    {
        switch (this.State)
        {
            #region Normal
        case AvatarStates.Normal:
        {
            this.CheckAvatarMove();

            break;
        }
            #endregion
        }

        this.previousDirection = this.currentDirection;
        this.previousPosition  = new Vector2(this.rigidBody.position.x, this.rigidBody.position.y);
        this.previousState     = this.State;

        //Debug.Log("Velocity: " + this.rigidBody.velocity.ToString());
        //if (this.rigidBody.velocity.x != 0)
        //    Debug.Log("Velocity: " + this.rigidBody.velocity.ToString());
        //Debug.Log(string.Format("Axis H: {0}, V: {1}.", (float)Input.GetAxis(this.playerName + "Horizontal"), (float)Input.GetAxis(this.playerName + "Vertical")));
    }
Example #3
0
    public static void ResolveCollision(AvatarController avatar, AvatarStates avatarState, AvatarController otherAvatar, AvatarStates otherAvatarState)
    {
        float            boundsDiffCheck = 0.5f;
        AvatarController hittingAvatar   = null;
        AvatarController hittedAvatar    = null;
        Vector2          hitDirection    = Vector2.zero;
        bool             isDraw          = false;

        var avatarPos         = avatar.rigidBody.position;
        var avatarBounds      = avatar.boxCollider.bounds;
        var otherAvatarPos    = otherAvatar.rigidBody.position;
        var otherAvatarBounds = otherAvatar.boxCollider.bounds;


        if ((avatarState == AvatarStates.Dash) && (otherAvatarState == AvatarStates.Dash))
        {
            //Check if it is an horizontal collision.
            if (((Mathf.Abs(avatarBounds.max.x - otherAvatarBounds.min.x) <= boundsDiffCheck) || (Mathf.Abs(avatarBounds.min.x - otherAvatarBounds.max.x) <= boundsDiffCheck)))
            {
                //If the collision is horizontal, then the hitting avatar is the one which it's direction is horizontal.
                if ((avatar.currentDirection.x != 0) && (otherAvatar.currentDirection.x == 0))
                {
                    hittingAvatar = avatar;
                    hittedAvatar  = otherAvatar;
                }
                else if ((avatar.currentDirection.x == 0) && (otherAvatar.currentDirection.x != 0))
                {
                    hittingAvatar = otherAvatar;
                    hittedAvatar  = avatar;
                }
                //Draw
                else
                {
                    isDraw = true;
                }
            }
            //Check if it is a vertical collision.
            else if (((Mathf.Abs(avatarBounds.max.y - otherAvatarBounds.min.y) <= boundsDiffCheck) || (Mathf.Abs(avatarBounds.min.y - otherAvatarBounds.max.y) <= boundsDiffCheck)))
            {
                //If the collision is vertical, then the hitting avatar is the one which it's direction is vertical.
                if ((avatar.currentDirection.y != 0) && (otherAvatar.currentDirection.y == 0))
                {
                    hittingAvatar = avatar;
                    hittedAvatar  = otherAvatar;
                }
                else if ((avatar.currentDirection.y == 0) && (otherAvatar.currentDirection.y != 0))
                {
                    hittingAvatar = otherAvatar;
                    hittedAvatar  = avatar;
                }
                //Draw
                else
                {
                    isDraw = true;
                }
            }
        }
        else if (avatarState == AvatarStates.Dash)
        {
            hittingAvatar = avatar;
            hittedAvatar  = otherAvatar;
        }
        else if (otherAvatarState == AvatarStates.Dash)
        {
            hittingAvatar = otherAvatar;
            hittedAvatar  = avatar;
        }

        //Means that a hit happens.
        if (hittedAvatar != null)
        {
            if (hittingAvatar.currentDirection.x == 1)
            {
                hitDirection = Vector2.left;
            }
            else if (hittingAvatar.currentDirection.x == -1)
            {
                hitDirection = Vector2.right;
            }
            else if (hittingAvatar.currentDirection.y == 1)
            {
                hitDirection = Vector2.down;
            }
            else if (hittingAvatar.currentDirection.y == -1)
            {
                hitDirection = Vector2.up;
            }

            hittedAvatar.State = AvatarStates.Stunned;

            hittedAvatar.rigidBody.AddForce(hitDirection * hittingAvatar.HitForce);
        }
        //If it is a draw, both are hit.
        else if (isDraw == true)
        {
            avatar.State          =
                otherAvatar.State = AvatarStates.Stunned;

            if (Mathf.Abs(avatar.currentDirection.x) == 1)
            {
                //For some reason, at this point, the current direction of avatar is wrong due to something weird
                //that I can't understand with rigidbody.position values.
                //Due to this, use previous direction for avatar.
                var avatarHitDir      = new Vector2(avatar.previousDirection.x * -1, avatar.previousDirection.y);
                var otherAvatarHitDir = new Vector2(otherAvatar.currentDirection.x * -1, otherAvatar.currentDirection.y);

                avatar.rigidBody.AddForce(avatarHitDir * otherAvatar.HitForce);
                otherAvatar.rigidBody.AddForce(otherAvatarHitDir * avatar.HitForce);
            }
            else if (Mathf.Abs(avatar.currentDirection.y) == 1)
            {
                //For some reason, at this point, the current direction of avatar is wrong due to something weird
                //that I can't understand with rigidbody.position values.
                //Due to this, use previous direction for avatar.
                var avatarHitDir      = new Vector2(avatar.previousDirection.x, avatar.previousDirection.y * -1);
                var otherAvatarHitDir = new Vector2(otherAvatar.currentDirection.x, otherAvatar.currentDirection.y * -1);

                avatar.rigidBody.AddForce(avatarHitDir * otherAvatar.HitForce);
                otherAvatar.rigidBody.AddForce(otherAvatarHitDir * avatar.HitForce);
            }
        }
        Debug.Log("Choque contra " + otherAvatar.gameObject.name.ToString());
    }
Example #4
0
 /// <summary>
 /// Stores a point in time for the avatar.
 /// </summary>
 /// <param name="_position">The position of the avatar.</param>
 /// <param name="_states">Current state of the avatar.</param>
 /// <param name="_sprite">Current sprite of the avatar.</param>
 public PointInTimeAvatar(Vector3 _position, AvatarStates _states, Sprite _sprite)
 {
     position = _position;
     state    = _states;
     sprite   = _sprite;
 }
Example #5
0
    /// <summary>
    /// Executes the main logic. Runs once per frame.
    /// </summary>
    protected virtual void Update()
    {
        if (DataLevel.InstanceDataLevel != null)
        {
            if (!DataLevel.InstanceDataLevel.Pause)
            {
                switch (this.State)
                {
                    #region CoolingDown
                case AvatarStates.CoolingDown:
                {
                    this.CheckAvatarMove();

                    this.dashCooldownTime += Time.deltaTime;

                    if (this.dashCooldownTime > this.DashCooldownMaxTime)
                    {
                        this.State = AvatarStates.Normal;
                    }

                    //Reset hiper move line
                    this.dashMoveLine.positionCount = 0;

                    break;
                }
                    #endregion

                    #region Dash
                case AvatarStates.Dash:
                {
                    this.dashActivedTime += Time.deltaTime;

                    if (Input.GetButton(this.playerName + "Dash") == false ||
                        this.dashActivedTime > this.DashBurnMaxTime)
                    {
                        this.State = AvatarStates.CoolingDown;
                        break;
                    }

                    this.CheckAvatarDashMove();

                    //If move direction changed, add new position to hiper move line.
                    if ((this.previousState == AvatarStates.Dash) &&
                        (this.previousDirection != Vector2.zero) &&
                        (this.previousDirection != this.currentDirection))
                    {
                        this.dashMoveLine.positionCount++;
                    }

                    //Update hiper move line liast position.
                    this.dashMoveLine.SetPosition(this.dashMoveLine.positionCount - 1, new Vector2(this.rigidBody.position.x, this.rigidBody.position.y));

                    //Vector3[] pos = new Vector3[this.hiperMoveLine.positionCount];
                    //this.hiperMoveLine.GetPositions(pos);
                    //Debug.Log(string.Join(",", pos.Select(item => string.Format("x: {0}, y: {1}", item.x, item.y)).ToArray()));

                    break;
                }
                    #endregion

                    #region Normal
                case AvatarStates.Normal:
                {
                    if (Input.GetButton(this.playerName + "Dash") &&
                        (
                            // Con los Input.GetButton la detección es inmediata, se puede estar parado presionando el dash y luego
                            // darle a moverse y funciona, con los Input.GetAxis de la manera están puestos si intentamos lo mismo
                            // no funciona, hay que moverse un poquito para que salga el Dash. Ahora, mientras el avatar se está
                            // moviendo no hay problemas
                            //(Input.GetButton(this.playerName + "Right") || Input.GetButton(this.playerName + "Left")) ||
                            (Input.GetAxisRaw(this.playerName + "Horizontal") <= -this.AxisSensitive || Input.GetAxisRaw(this.playerName + "Horizontal") >= this.AxisSensitive) ||
                            //(Input.GetButton(this.playerName + "Up") || Input.GetButton(this.playerName + "Down")) ||
                            (Input.GetAxisRaw(this.playerName + "Vertical") <= -this.AxisSensitive || Input.GetAxisRaw(this.playerName + "Vertical") >= this.AxisSensitive)
                        )
                        )
                    {
                        this.State = AvatarStates.Dash;
                        break;
                    }

                    this.CheckAvatarMove();

                    break;
                }
                    #endregion

                    #region Stunned
                case AvatarStates.Stunned:
                {
                    this.stunningTime += Time.deltaTime;

                    if (this.stunningTime > this.StunnedMaxTime)
                    {
                        this.State = AvatarStates.Normal;
                    }

                    this.ejectionVelocity = this.rigidBody.velocity;

                    break;
                }
                    #endregion

                    #region Still

                case AvatarStates.Still:
                {
                    break;
                }

                    #endregion
                }
            }
        }


        this.previousDirection = this.currentDirection;
        this.previousPosition  = new Vector2(this.rigidBody.position.x, this.rigidBody.position.y);
        this.previousState     = this.State;

        //Debug.Log("Velocity: " + this.rigidBody.velocity.ToString());
        //if (this.rigidBody.velocity.x != 0)
        //    Debug.Log("Velocity: " + this.rigidBody.velocity.ToString());
        //Debug.Log(string.Format("Axis H: {0}, V: {1}.", (float)Input.GetAxis(this.playerName + "Horizontal"), (float)Input.GetAxis(this.playerName + "Vertical")));
    }
Example #6
0
    //Pause function added to the move (ends)

	public void Start()
	{
	    try
	    {
            _pauseMenuPanel = Helper.Find<RectTransform>("PauseMenuPanel");
            _pauseMenuStartLocation = _pauseMenuPanel.rect.yMin;
	    }
	    catch (Exception)
	    {
            //Continue with bussiness as usual...
            //Detta händer om det inte finns någon paus-meny och knapp
	    }
        
		_mover = GetComponent<Mover>();
		_rotation = GetComponentInChildren<Rotation>();

		Floor floor = Helper.Find<Floor>("Floor");
		_gridManager = floor.GridManager;
		_pathFinder = new PathFinder(_gridManager);
        
        //Audio related
		_lockAudioSourceLocation = this.gameObject.transform.rotation;
	    _audioComponent = this.gameObject.transform.FindChild("AudioComponent").gameObject;
        _avatarSoul = GameObject.Find("AvatarSoul");

	    if (_avatarSoul != null)        //ADD soul if it is multiple characters
	    {
	        _soulMover = _avatarSoul.GetComponentInChildren<SoulMover>();

            //Om det finns en soul ta bort audio listener och ljus på avatar
            AudioListener audioList = GetComponent<AudioListener>();
	        Light lightOnChar = GetComponentInChildren<Light>();

	        if (audioList != null)
	        {
	            audioList.enabled = false;
	        }
	        if (lightOnChar != null)
	        {
	            lightOnChar.enabled = false;
	        }
	    }

	    _soundEffectPlayer = GetComponentInChildren<SoundEffectPlayer>();
        
		AvatarStates avatarStates = new AvatarStates(gameObject);
		_stateMachine = avatarStates.GetStateMachine();
	}