Exemple #1
0
        public bool moveToTarget(Vector3 target3dPos, float movementSpeed, bool keepInArena)
        {
            Vector3 current3dPos = getFeetPosition();
            Vector3 diff         = target3dPos - current3dPos; diff.z = 0;

            SoulAvenger.Character.FACING currentF = (diff.x > 0)?SoulAvenger.Character.FACING.RIGHT:SoulAvenger.Character.FACING.LEFT;
            currentFacing = currentF;

            tk2dAnimatedSprite sprite = GetComponent <tk2dAnimatedSprite>();

            movementSpeed *= sprite.localTimeScale;

            Vector3 velocity = diff;

            velocity.Normalize();

            velocity *= movementSpeed * Time.deltaTime;

            Vector3 newPos = current3dPos + velocity;

            bool ret = true;

            if (velocity.magnitude > diff.magnitude)
            {
                newPos = target3dPos;
                ret    = false;
            }

            tryToMove(newPos, keepInArena);

            return(ret);
        }
Exemple #2
0
        //true if the character moves, false if is colliding so it has already reach the target
        public bool moveToTarget(SoulAvenger.Character target, float movementSpeed, bool keepInArena)
        {
            Vector3 current3dPos = getFeet().position;
            Vector3 target3dPos  = target.getFeet().position;
            Vector3 diff         = target3dPos - current3dPos;

            diff.z = 0;

            if (feetsAreColliding(target))
            {
                SoulAvenger.Character.FACING currentF = (diff.x > 0)?SoulAvenger.Character.FACING.RIGHT:SoulAvenger.Character.FACING.LEFT;
                currentFacing = currentF;
                return(false);
            }

            tk2dAnimatedSprite sprite = GetComponent <tk2dAnimatedSprite>();

            movementSpeed *= sprite.localTimeScale;
            Vector3 velocity = diff; velocity.Normalize(); velocity *= movementSpeed * Time.deltaTime;

            Vector3 newPos = current3dPos + velocity;

            tryToMove(newPos, keepInArena);
            return(true);
        }
Exemple #3
0
    public void changeFacingTrigger(FACING which)
    {
        Vector2 offset = new Vector2(0, 0);
        Vector2 size   = new Vector2(0, 0);

        switch (which)
        {
        case FACING.Down:
            offset = new Vector2(0f, -48f);
            size   = new Vector2(32f, 32f);
            break;

        case FACING.Up:
            offset = new Vector2(0f, 16f);
            size   = new Vector2(32f, 32f);
            break;

        case FACING.Left:
            offset = new Vector2(-32f, -16f);
            size   = new Vector2(32f, 32f);
            break;

        case FACING.Right:
            offset = new Vector2(32f, -16f);
            size   = new Vector2(32f, 32f);
            break;
        }

        colliderTrigger.offset = offset;
        colliderTrigger.size   = size;
        return;
    }
Exemple #4
0
    }                                   // Returns true if the GameObject go and this GameObject are facing each other

    public void faceObject(GameObject go)
    {
        FACING newDirection = FACING.Default;
        Facing facing       = go.GetComponent <Facing>();

        switch (facing.facingDirection)
        {
        case FACING.Right:
            newDirection = FACING.Left;
            break;

        case FACING.Left:
            newDirection = FACING.Right;
            break;

        case FACING.Up:
            newDirection = FACING.Down;
            break;

        case FACING.Down:
            newDirection = FACING.Up;
            break;
        }
        facingDirection = newDirection;
        return;
    }
Exemple #5
0
    public bool isFacing(GameObject go)
    {
        FACING objectFacing = go.GetComponent <Facing>().facingDirection;

        if (objectFacing == null)
        {
            throw new System.Exception("ERROR: Facing script not attached to " + go.name.ToString());
        }
        if (facingDirection == FACING.Up && objectFacing == FACING.Down)
        {
            return(true);
        }
        else if (facingDirection == FACING.Down && objectFacing == FACING.Up)
        {
            return(true);
        }
        else if (facingDirection == FACING.Left && objectFacing == FACING.Right)
        {
            return(true);
        }
        else if (facingDirection == FACING.Right && objectFacing == FACING.Left)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }                                   // Returns true if the GameObject go and this GameObject are facing each other
Exemple #6
0
    private void FixedUpdate()
    {
        float horizontal = 0;

        if (Input.GetAxis("Horizontal") != 0)
        {
            horizontal = Input.GetAxis("Horizontal");
        }
        else
        {
            horizontal = joystick.Horizontal;
        }


        float vertical = 0;

        if (Input.GetAxis("Vertical") != 0)
        {
            vertical = Input.GetAxis("Vertical");
        }
        else
        {
            vertical = joystick.Vertical;
        }
        rb.velocity = new Vector2(horizontal * 4f, rb.velocity.y);
        rb.velocity = new Vector2(rb.velocity.x, vertical * 4f);

        var goesTo = facing;

        if (horizontal > 0.2)
        {
            goesTo = FACING.RIGHT;
        }
        else if (horizontal < -0.2)
        {
            goesTo = FACING.LEFT;
        }
        if (vertical > 0.2)
        {
            goesTo = FACING.UP;
        }
        else if (vertical < -0.2)
        {
            goesTo = FACING.DOWN;
        }

        if (goesTo != facing)
        {
            Vector3 vector = new Vector3(0, 0, (float)goesTo);
            if (goesTo == FACING.LEFT)
            {
                vector.z = 0;
                vector.y = 180;
            }
            transform.rotation = Quaternion.Euler(vector);
            facing             = goesTo;
        }
    }
Exemple #7
0
 public void FlipFacing()
 {
     if (facing == PlayerController.FACING.right)
     {
         facing = PlayerController.FACING.left;
     }
     else
     {
         facing = PlayerController.FACING.right;
     }
 }
Exemple #8
0
        public void faceTarget()
        {
            if (currentTarget != null)
            {
                Vector3 diff = currentTarget.getFeetPosition() - this.getFeetPosition();
                diff.z = 0;

                SoulAvenger.Character.FACING currentF = (diff.x > 0)?SoulAvenger.Character.FACING.RIGHT:SoulAvenger.Character.FACING.LEFT;
                if (currentFacing != currentF)
                {
                    currentFacing = currentF;
                }
            }
        }
Exemple #9
0
    public static FACING LookFacing(Vector3 dir)
    {
        float degs = Mathf.Abs(Mathf.Atan(dir.z / dir.x)) * Mathf.Rad2Deg;

        FACING facing;

        if (degs > 60) {
            if (dir.z > 0) facing = FACING.n;
            else facing = FACING.s;
        }

        else {
            if (dir.x > 0) {
                if (dir.z > 0) facing = FACING.ne;
                else facing = FACING.se;
            }
            else {
                if (dir.z > 0) facing = FACING.nw;
                else facing = FACING.sw;
            }
        }

        return facing;
    }
Exemple #10
0
 public Entity(String sprite, int posX, int posY, FACING facing, Legend legend) : this(sprite, posX, posY, legend)
 {
     this.facing = facing;
 }
Exemple #11
0
 public NPC(string sprite, int posX, int posY, FACING facing, string dialogueKey, Legend legend) : base(sprite, posX, posY, facing, legend)
 {
     this.dialogueKey = dialogueKey;
 }
Exemple #12
0
    public void SpawnPlayerInMap(Character c, Tile p, FACING facing)
    {
        DungeonCharacter dc = SpawnCharInMap(c, ALIGNMENT.player, p);
        charsInPlay.Add(dc);

        GameObject so = Instantiate(Resources.Load("spriteObj"), p.worldPos, Quaternion.identity) as GameObject;
        EntitySprite espr = so.GetComponentInChildren<EntitySprite>();
        so.transform.parent = dc.transform;
        dc.entity.erenderer = espr;
        dc.esprite = espr;
        espr.Initialize(dc.entity, c.spriteData, GameState.charLSManager);
        espr.Turn((int)facing);
    }
Exemple #13
0
    public void SpawnEnemyInMap(Character c, CharBehaviour cb, Tile p, FACING facing)
    {
        DungeonCharacter dc = SpawnCharInMap(c, ALIGNMENT.enemy, p);
        AutonomousCharacter ac = dc.gameObject.AddComponent("AutonomousCharacter") as AutonomousCharacter;
        ac.Initialize(dc, cb);

        GameObject so = Instantiate(Resources.Load("spriteObj"), p.worldPos, Quaternion.identity) as GameObject;
        EntitySprite espr = so.GetComponentInChildren<EntitySprite>();
        so.transform.parent = dc.transform;
        dc.entity.erenderer = espr;
        dc.esprite = espr;
        espr.Initialize(dc.entity, c.spriteData, GameState.charLSManager);
        espr.Turn((int)facing);

        enemiesInPlay.Add(ac);
    }
Exemple #14
0
 public void SetFacing(FACING facing)
 {
     this.facing = facing;
 }
Exemple #15
0
 public void Turn(float degs)
 {
     int fint = Mathf.RoundToInt(degs);
     FACING newFacing = (FACING)fint;
     facing = newFacing;
     sprite.PlayAnim(ANIM.walking.ToString() + "_" + facing.ToString());
     if (anim == ANIM.idle) {
         sprite.PauseAnim();
     }
 }