コード例 #1
0
    void MovePartsToRandomStartPositions()
    {
        // if starting to fall down,  lock down positions and move to next state
        if (playerScript.velocity.y < 0)
        {
            for (int i = 0; i < creaturePartsArray.Length; i++)
            {
                creaturePartsOriginalPositionArray[i] = creaturePartsArray[i].transform.position;
            }

            creatureState = CreatureStates.AssemblingParts;
        }

        /*
         * // normal update, move towards start target posotions
         * float velocityRatio = 1.0f - (playerScript.velocity.y/spawnPlayerJumpVelocity);
         * for(int i = 0; i < creaturePartsArray.Length; i++)
         * {
         *      creaturePartsArray[i].transform.position = Vector3.Lerp(creaturePartsOriginalPositionArray[i], partsRandomStartPositionsList[i], Mathf.SmoothStep(0f,1f,velocityRatio) );
         * }
         *
         * // if starting to fall down,  lock down positions and move to next state
         * if(playerScript.velocity.y < 0)
         * {
         *      for(int i = 0; i < creaturePartsArray.Length; i++)
         *              creaturePartsOriginalPositionArray[i] = creaturePartsArray[i].transform.position;
         *
         *      creatureState = CreatureStates.AssemblingParts;
         * }
         */
    }
コード例 #2
0
    void AssembleCreature()
    {
        partsStartColor = playerScript.colorRecordingList[0];

        // player hits the ground., need to complete creature formation
        if (playerScript.velocity.y == 0 || playerScript.oldVelocity.y == 0)
        {
            //Debug.Log("Hit Ground");
            for (int i = 0; i < creaturePartsArray.Length; i++)
            {
                creaturePartsArray[i].transform.position = transform.position;
                creaturePartsArray[i].transform.rotation = Quaternion.identity;
            }
            creatureState = CreatureStates.CollectingPathData;
            //Debug.Log("Player HIT GROUND_ASSEBLE");
            //Debug.Log("Framecount: " + Time.frameCount.ToString() );
        }

        // ordinary update
        for (int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position      = Vector3.Lerp(creaturePartsOriginalPositionArray[i], transform.position, Mathf.SmoothStep(0f, 1f, playerScript.moveTowardsRatio));
            creaturePartsArray[i].transform.rotation      = Quaternion.Slerp(creaturePartsArray[i].transform.rotation, Quaternion.identity, Mathf.SmoothStep(0f, 1f, playerScript.moveTowardsRatio));
            creaturePartsArray[i].renderer.material.color = Color.Lerp(creaturePartsArray[i].renderer.material.color, partsStartColor, 0.75f * Mathf.SmoothStep(0f, 1f, playerScript.moveTowardsRatio));
        }
    }
コード例 #3
0
    void CollectPathData()
    {
        // get the data from the original list in the player
        positionsRecordingsList = new List <Vector3>(playerScript.positionRecordingList);
        rotationsRecordingsList = new List <Quaternion>(playerScript.rotationRecordingList);
        colorsRecordingsList    = new List <Color>(playerScript.colorRecordingList);
        //set color transparency, only works if shader in material is of Transparent/ type
        for (int i = 0; i < colorsRecordingsList.Count; i++)
        {
            Color tempColor = colorsRecordingsList[i];
            tempColor.a             = 0.9f;
            colorsRecordingsList[i] = tempColor;
        }
        // get original flight duration
        originalPathTimeLength = playerScript.recordingLength;
        // get spawn offset
        initialPositionOffset = transform.position - positionsRecordingsList[0];
        // wipe the original
        playerScript.positionRecordingList.Clear();
        playerScript.rotationRecordingList.Clear();
        playerScript.colorRecordingList.Clear();
        // change state
        creatureState = CreatureStates.FollowingPath;

        // set initial color
        for (int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].renderer.material.color = colorsRecordingsList[0];
        }
    }
コード例 #4
0
 protected void VanillaSlash(CreatureStates Creature,Raycast Raycast, Vector3 SlashDirection)
 {
     if (Raycast.SearchForCreature(SlashDirection, Creature.Storey))
     {
         Raycast.TargetCreature.Health -= Creature.Damage;
     }
 }
コード例 #5
0
    void FollowPath()
    {
        float pathProgressionRatio = currentPathTimeCounter / originalPathTimeLength;
        int   currentPathNodeIndex = Mathf.FloorToInt(pathProgressionRatio * (float)positionsRecordingsList.Count);

        if (currentPathNodeIndex > positionsRecordingsList.Count - 2)       // gone through the entire list, arrived at the end of the path
        {
            creatureState = CreatureStates.AnimatingDeath_GatheringParts;
            return;
        }

        float ratioToNextPathNode = (pathProgressionRatio * (float)positionsRecordingsList.Count) - (float)currentPathNodeIndex;

        //updating head part
        creaturePartsArray[0].transform.position      = Vector3.Lerp(positionsRecordingsList[currentPathNodeIndex], positionsRecordingsList[currentPathNodeIndex + 1], ratioToNextPathNode);
        creaturePartsArray[0].transform.rotation      = Quaternion.Slerp(rotationsRecordingsList[currentPathNodeIndex], rotationsRecordingsList[currentPathNodeIndex + 1], ratioToNextPathNode);
        creaturePartsArray[0].renderer.material.color = Color.Lerp(colorsRecordingsList[currentPathNodeIndex], colorsRecordingsList[currentPathNodeIndex + 1], ratioToNextPathNode);

        //update the position displacement
        float forwardSpeed = Mathf.Lerp(forwardSpeedStart, forwardSpeedEnd, Mathf.Sqrt(Mathf.Sqrt(pathProgressionRatio)));

        positionDisplacement += new Vector3(-forwardSpeed * Time.deltaTime * plabackTimeScale, 0, 0);
        //displace the head with the speed/position displacement vector
        creaturePartsArray[0].transform.position += positionDisplacement + initialPositionOffset;

        // make body parts follow the one in front
        for (int i = 1; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position      = Vector3.Lerp(creaturePartsArray[i].transform.position, creaturePartsArray[i - 1].transform.position, 21 * plabackTimeScale * Time.deltaTime);
            creaturePartsArray[i].transform.rotation      = Quaternion.Slerp(creaturePartsArray[i].transform.rotation, creaturePartsArray[i - 1].transform.rotation, 7 * plabackTimeScale * Time.deltaTime);
            creaturePartsArray[i].renderer.material.color = Color.Lerp(creaturePartsArray[i].renderer.material.color, creaturePartsArray[i - 1].renderer.material.color, 21 * plabackTimeScale * Time.deltaTime);
        }
        currentPathTimeCounter += Time.deltaTime * plabackTimeScale;
    }
コード例 #6
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    protected void Defend(Creature attacker, float delay = 0)
    {
        StopMoving();

        state = CreatureStates.Defending;
        StartCoroutine(DefendAnimation(attacker, delay, 8));
    }
コード例 #7
0
    void AnimateDeath_SendoffParts()
    {
        creatureState = CreatureStates.RelinquishingParts;

        /*
         * float sendoffSpeedScale = 1.5f;
         * float deltaCounter = 0;
         * for(int i = 0; i < creaturePartsArray.Length; i++)
         * {
         *      //update final location
         *      int aIndex = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).arrayIndex;
         *
         *      Vector3 anchorPosition = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.positionsList[aIndex];
         *      anchorPosition = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.transform.TransformPoint(anchorPosition);
         *      creaturePartsArray[i].transform.position = Vector3.Lerp( creaturePartsArray[i].transform.position, anchorPosition , sendoffSpeedScale * Time.deltaTime );
         *
         *      // lerp to target rotation
         *      Quaternion anchorRotation = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.rotationsList[aIndex];
         *      creaturePartsArray[i].transform.rotation = Quaternion.Slerp( creaturePartsArray[i].transform.rotation, anchorRotation, sendoffSpeedScale * Time.deltaTime);
         *
         *      // lerp color
         *      Color targetColor =  ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).partsArrayColor ;
         *      creaturePartsArray[i].renderer.material.color = Color.Lerp( creaturePartsArray[i].renderer.material.color, targetColor , sendoffSpeedScale * Time.deltaTime);
         *
         *      deltaCounter += Vector3.Distance( creaturePartsArray[i].transform.position, anchorPosition);
         * }
         * float deltaAverage = deltaCounter/(float)creaturePartsArray.Length;
         * if(deltaAverage < 5)
         *      creatureState = CreatureStates.RelinquishingParts;
         *
         */
    }
コード例 #8
0
    public override void Activate(CreatureStates Creature, Raycast Raycast, Good.Times.State State)
    {
        base.Activate (Creature, Raycast, State);
        if (State == State.BeginningOfTurn)
        {
            RecordHeight(Creature,Raycast);
        }

        if (State == State.Jump)
        {
            if (Raycast.SearchForCreature(Creature.Front,Creature.Storey) &&
                Raycast.SearchForHeight(Creature.Front,true) &&
                Creature.Jump >= Raycast.TargetMultipleCreature.Count)
            {
                float x = Raycast.TargetCreature.transform.position.x;
                float y = Raycast.TargetCreature.transform.position.y;
                float AddHeight = Raycast.TargetMultipleCreature.Select(h => h.Height).Sum();
                Move(Creature,x,y + AddHeight);
                Creature.Storey = Raycast.TargetMultipleCreature.OrderByDescending(s => s.Storey).ToList()[0].Storey + 1;
            }
        }

        if (State == State.EndOfTurn)
        {
            RecordHeight(Creature,Raycast);
            Fall(Creature, Raycast);
        }
    }
コード例 #9
0
    void AnimateDeath_SendoffParts()
    {
        float sendoffSpeedScale = 1.5f;

        float deltaCounter = 0;
        Color targetColor  = new Color(1, 1, 1, 1);

        for (int i = 0; i < creaturePartsArray.Length; i++)
        {
            //update final location
            int aIndex = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).arrayIndex;

            Vector3 anchorPosition = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.positionsList[aIndex];
            anchorPosition = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.transform.TransformPoint(anchorPosition);
            creaturePartsArray[i].transform.position = Vector3.Lerp(creaturePartsArray[i].transform.position, anchorPosition, sendoffSpeedScale * Time.deltaTime);

            // lerp to target rotation
            Quaternion anchorRotation = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.rotationsList[aIndex];
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp(creaturePartsArray[i].transform.rotation, anchorRotation, sendoffSpeedScale * Time.deltaTime);


            deltaCounter += Vector3.Distance(creaturePartsArray[i].transform.position, anchorPosition);

            creaturePartsArray[i].renderer.material.color = Color.Lerp(creaturePartsArray[i].renderer.material.color, targetColor, 0.5f * Time.deltaTime);
        }
        float deltaAverage = deltaCounter / (float)creaturePartsArray.Length;

        if (deltaAverage < 10)
        {
            creatureState = CreatureStates.RelinquishingParts;
        }
    }
コード例 #10
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    protected void ResolveEncountersAtGoal(int x, int y)
    {
        Vector2 goal = path[path.Count - 1];

        if (x == (int)goal.x && y == (int)goal.y)
        {
            Entity entity = grid.GetEntity(x, y);
            if (entity != null)
            {
                // stairs (player only)
                if ((this is Player) && (entity is Stair))
                {
                    Stair stair = (Stair)entity;

                    if (stair.state == EntityStates.Open)
                    {
                        state = CreatureStates.Descending;
                        Dungeon.instance.ExitLevel(stair.direction);
                    }
                    else
                    {
                        Hud.instance.Log("The stair doors are locked.");
                    }
                }
            }
        }
    }
コード例 #11
0
    void AnimateDeath_ShootUpParts()
    {
        Vector3 bottomPosition = finalAliveHeadPosition;
        Vector3 topPosition    = bottomPosition + new Vector3(0, positionsRecordingsList.Count * 1.5f, 0);      // rise is proportional to number of parts

        shootUpLerpCounter += 1f * Time.deltaTime;
        for (int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position = Vector3.Lerp(creaturePartsArray[i].transform.position, topPosition, Mathf.SmoothStep(0, 1f, shootUpLerpCounter));
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp(creaturePartsArray[i].transform.rotation, Quaternion.identity, Mathf.SmoothStep(0, 1f, shootUpLerpCounter));
        }

        Vector3 currentPosition = creaturePartsArray[0].transform.position;

        if ((topPosition.y - currentPosition.y) / (topPosition.y - bottomPosition.y) < 0.01f)         // if past 99% to the target, end
        {
            if (waitCounter < 0.50f)
            {
                waitCounter += Time.deltaTime;
            }
            else
            {
                creatureState = CreatureStates.AnimatingDeath_SendingoffParts;
            }
        }
    }
コード例 #12
0
 public override void Activate(CreatureStates Creature, Raycast Raycast, State State)
 {
     base.Activate (Creature, Raycast, State);
     if (State == State.Use)
     {
         VanillaSlash(Creature,Raycast,Creature.Front);
     }
 }
コード例 #13
0
 public override void Activate(CreatureStates Creature, Raycast Raycast, State State)
 {
     base.Activate (Creature, Raycast, State);
     if (State == WhenToActivate)
     {
         Creature.Health+=Health;
     }
 }
コード例 #14
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    protected virtual void ResolveEntityEncounters(int x, int y)
    {
        Entity entity = grid.GetEntity(x, y);

        if (entity == null)
        {
            return;
        }

        // resolve closed/locked doors
        if (entity is Door)
        {
            Door door = (Door)entity;
            if (door.state != EntityStates.Open)
            {
                // open the door
                if (door.state == EntityStates.Closed)
                {
                    state = CreatureStates.Using;
                    StartCoroutine(door.Open(this));
                    return;

                    // unlock the door
                }
                else if (door.state == EntityStates.Locked)
                {
                    state = CreatureStates.Using;
                    StartCoroutine(door.Unlock(this));
                    return;
                }
            }
        }

        // resolve closed/locked chests
        if (entity is Chest)
        {
            Chest chest = (Chest)entity;
            if (chest.state != EntityStates.Open)
            {
                // open the door
                if (chest.state == EntityStates.Closed)
                {
                    state = CreatureStates.Using;
                    StartCoroutine(chest.Open(this));
                    return;

                    // unlock the door
                }
                else if (chest.state == EntityStates.Locked)
                {
                    state = CreatureStates.Using;
                    StartCoroutine(chest.Unlock(this));
                    return;
                }
            }
        }
    }
コード例 #15
0
 private void Fall(CreatureStates Creature, Raycast Raycast)
 {
     if (Raycast.SearchForCreature(Vector3.down,Creature.Storey -1) == false &&
         Creature.Storey > 1)
     {
         float x = Creature.transform.position.x;
         float y = Creature.transform.position.y;
         Move(Creature,x,y-FallDistance);
         Creature.Storey--;
     }
 }
コード例 #16
0
    public override void Activate(CreatureStates Creature, Raycast Raycast, State State)
    {
        base.Activate (Creature, Raycast, State);
        if (Merge.Count < 2)
        {
            Debug.LogError("Need two or more statuses");
        }

        foreach (var i in Merge)
        {
            i.Activate(Creature,Raycast,State);
        }
    }
コード例 #17
0
ファイル: Creature.cs プロジェクト: snaptothegrid/Tiler
    // =====================================================
    // Initialization
    // =====================================================
    public override void Init(Grid grid, int x, int y, float scale = 1, Sprite asset = null)
    {
        base.Init(grid, x, y, scale, asset);
        walkable = false;

        SetImages(scale, new Vector3(0, 0.1f, 0), 0.035f);

        state = CreatureStates.Idle;
        stats = new CreatureStats();
        bar.Init(this);

        LocateAtCoords(x, y);
    }
コード例 #18
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    protected IEnumerator DefendAnimation(Creature attacker, float delay = 0, float advanceDiv = 8)
    {
        yield return(new WaitForSeconds(delay));

        // wait for impact
        float duration = speed * 0.5f;

        yield return(new WaitForSeconds(duration));

        // get combat positions
        Vector3 startPos = new Vector3(this.x, this.y, 0);
        Vector3 vec      = (new Vector3(attacker.x, attacker.y, 0) - startPos).normalized / advanceDiv;
        Vector3 endPos   = startPos - vec;

        // resolve combat outcome and apply combat sounds and effects

        bool isDead = ResolveCombatOutcome(attacker);

        if (isDead)
        {
            Die(attacker);
            yield break;
        }

        // move towards attacker
        float t = 0;

        while (t <= 1)
        {
            t += Time.deltaTime / duration * 0.5f;
            transform.localPosition = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0f, 1f, t));

            yield return(null);
        }

        // move back to position
        t = 0;
        while (t <= 1)
        {
            t += Time.deltaTime / (duration * 0.5f);
            transform.localPosition = Vector3.Lerp(endPos, startPos, Mathf.SmoothStep(0f, 1f, t));

            yield return(null);
        }

        state = CreatureStates.Idle;

        // emmit event once the defender has finished this action
        attacker.UpdateGameTurn();
    }
コード例 #19
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    // =====================================================
    // Initialization
    // =====================================================

    public override void Init(Grid grid, int x, int y, float scale = 1, Sprite asset = null)
    {
        base.Init(grid, x, y, scale, asset);
        walkable = false;

        SetImages(scale, new Vector3(0, 0.1f, 0), 0.035f);


        state = CreatureStates.Idle;
        stats = new CreatureStats();
        bar.Init(this);

        LocateAtCoords(x, y);
    }
コード例 #20
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    public virtual void StopMoving()
    {
        if (state == CreatureStates.Moving || state == CreatureStates.Using)
        {
            StopAllCoroutines();
        }

        state = CreatureStates.Idle;

        // clear path
        //DrawPath(Color.white);

        // creatures need to set their visibility also after they moved
        UpdateVisibility();
    }
コード例 #21
0
    public void AquireCreatureParts(GameObject[] partsArray)
    {
        List <GameObject> creaturePartsList = new List <GameObject>();
        List <Vector3>    creaturePartsOriginalPositionList = new List <Vector3>();

        for (int i = 0; i < partsArray.Length; i++)
        {
            partsArray[i].transform.parent = transform;
            ((CreaturePartsGeneralScript)partsArray[i].GetComponent("CreaturePartsGeneralScript")).isPartOfCreature = true;
            creaturePartsList.Add(partsArray[i]);
            creaturePartsOriginalPositionList.Add(partsArray[i].transform.position);
        }
        creaturePartsArray = creaturePartsList.ToArray();
        creaturePartsOriginalPositionArray = creaturePartsOriginalPositionList.ToArray();
        creatureState = CreatureStates.AssemblingParts;
    }
コード例 #22
0
 private void AutoSlashDirections(CreatureStates Creature, Raycast Raycast, Vector3 Front, Vector3 OtherFront, Vector3 Direction, Vector3 OtherDirection)
 {
     if (Creature.Front == Front || Creature.Front == OtherFront)
     {
         Raycast.SearchForMultipleDirections(new Vector3[] {Direction,OtherDirection}, Creature.Storey);
         if (Raycast.TargetMultipleCreature.Count == 1)
         {
             Raycast.TargetMultipleCreature[0].Health -= Creature.Damage;
         }
         if (Raycast.TargetMultipleCreature.Count == 2)
         {
             CreatureStates First = Raycast.TargetMultipleCreature[0];
             CreatureStates Second = Raycast.TargetMultipleCreature[1];
             CompareCreaturesHealth(First,Second).Health -= Creature.Damage;
         }
     }
 }
コード例 #23
0
    void CollectPathData()
    {
        //Debug.Log("Player HIT GROUND_COLLECTDATA");
        //Debug.Log("Framecount: " + Time.frameCount.ToString() );

        // get the data from the original list in the player
        positionsRecordingsList = new List <Vector3>(playerScript.positionRecordingList);
        rotationsRecordingsList = new List <Quaternion>(playerScript.rotationRecordingList);
        colorsRecordingsList    = new List <Color>(playerScript.colorRecordingList);
        //set color transparency, only works if shader in material is of Transparent/ type
        for (int i = 0; i < colorsRecordingsList.Count; i++)
        {
            Color tempColor = colorsRecordingsList[i];
            tempColor.a             = 0.9f;
            colorsRecordingsList[i] = tempColor;
        }
        // get original flight duration
        originalPathTimeLength = playerScript.recordingLength;
        // get spawn offset
        // CHEAP HACKED FIX, TODO, BETTER FIX
        if (positionsRecordingsList.Count == 0)
        {
            creatureState = CreatureStates.AnimatingDeath_SendingoffParts;
            return;
        }
        initialPositionOffset = transform.position - positionsRecordingsList[0];
        // wipe the original
        playerScript.positionRecordingList.Clear();
        playerScript.rotationRecordingList.Clear();
        playerScript.colorRecordingList.Clear();
        //Debug.Log("CLEARED DATA");
        // change state

        positionsRecordingsList.Add(finalPosition);
        rotationsRecordingsList.Add(Quaternion.identity);
        colorsRecordingsList.Add(Color.white);

        creatureState = CreatureStates.FollowingPath;

        // set initial color
        for (int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].renderer.material.color = colorsRecordingsList[0];
        }
    }
コード例 #24
0
    public override void Activate(CreatureStates Creature, Raycast Raycast, State State)
    {
        if (State == State.Use)
        {
            if (DoubleSided)
            {
                for (int i = 0; i < MoveAmount; i++)
                {
                    Creature.Move(Creature.Front);
                    DirectionalSlash(Creature,Raycast,Vector.Up,Vector.Left);
                    DirectionalSlash(Creature,Raycast,Vector.Up,Vector.Right);
                    DirectionalSlash(Creature,Raycast,Vector.Down,Vector.Left);
                    DirectionalSlash(Creature,Raycast,Vector.Down,Vector.Right);
                    DirectionalSlash(Creature,Raycast,Vector.Left,Vector.Up);
                    DirectionalSlash(Creature,Raycast,Vector.Left,Vector.Down);
                    DirectionalSlash(Creature,Raycast,Vector.Right,Vector.Up);
                    DirectionalSlash(Creature,Raycast,Vector.Right,Vector.Down);
                }
                Creature.Move(Creature.Front);
            }

            if (Auto)
            {
                for (int i = 0; i < MoveAmount; i++)
                {
                    AutoSlash (Creature, Raycast);
                }
                Creature.Move(Creature.Front);
            }

            if (!DoubleSided && !Auto)
            {
                for (int i = 0; i < MoveAmount; i++)
                {
                    Creature.Move(Creature.Front);
                    DirectionalSlash(Creature,Raycast,Vector.Up,DirectionToHit[0]);
                    DirectionalSlash(Creature,Raycast,Vector.Down,DirectionToHit[1]);
                    DirectionalSlash(Creature,Raycast,Vector.Left,DirectionToHit[2]);
                    DirectionalSlash(Creature,Raycast,Vector.Right,DirectionToHit[3]);
                }
                Creature.Move(Creature.Front);
            }
        }
    }
コード例 #25
0
    public void AquireCreatureParts(GameObject[] partsArray)
    {
        playerScript = (PlayerScript)GameObject.FindWithTag("Player").GetComponent("PlayerScript");

        List<GameObject> creaturePartsList = new List<GameObject>();
        List<Vector3> creaturePartsOriginalPositionList = new List<Vector3>();
        for(int i = 0; i < partsArray.Length; i++ )
        {
            partsArray[i].transform.parent = transform;
            ((CreaturePart)partsArray[i].GetComponent("CreaturePart")).isPartOfCreature = true;
            partsArray[i].GetComponent<PVA>().enabled = false;
            creaturePartsList.Add(partsArray[i]);
            creaturePartsOriginalPositionList.Add(partsArray[i].transform.position);;
        }
        creaturePartsArray = creaturePartsList.ToArray();
        creaturePartsOriginalPositionArray = creaturePartsOriginalPositionList.ToArray();

        creatureState = CreatureStates.MovingPartsToRandomStartPositions;
    }
コード例 #26
0
    void AnimateDeath_GatherParts()
    {
        Vector3 headPostion      = creaturePartsArray[0].transform.position;
        Vector3 lastPartPosition = creaturePartsArray[creaturePartsArray.Length - 1].transform.position;

        if (Mathf.Abs(Vector3.Distance(headPostion, lastPartPosition)) > 5)         // conitnue body animation until the last piece has caught up sufficiently to the head
        {
            for (int i = 1; i < creaturePartsArray.Length; i++)
            {
                creaturePartsArray[i].transform.position      = Vector3.Lerp(creaturePartsArray[i].transform.position, creaturePartsArray[i - 1].transform.position, 25 * plabackTimeScale * Time.deltaTime);
                creaturePartsArray[i].transform.rotation      = Quaternion.Slerp(creaturePartsArray[i].transform.rotation, creaturePartsArray[i - 1].transform.rotation, 25 * plabackTimeScale * Time.deltaTime);
                creaturePartsArray[i].renderer.material.color = Color.Lerp(creaturePartsArray[i].renderer.material.color, creaturePartsArray[i - 1].renderer.material.color, 25 * plabackTimeScale * Time.deltaTime);
            }
        }
        else
        {
            finalAliveHeadPosition = creaturePartsArray[0].transform.position;
            creatureState          = CreatureStates.AnimatingDeath_ShootingUpParts;
        }
    }
コード例 #27
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    protected void Attack(Creature target, float delay = 0)
    {
        if (state == CreatureStates.Using)
        {
            return;
        }
        if (target.state == CreatureStates.Dying)
        {
            return;
        }

        //delay += state == CreatureStates.Moving ? speed : 0;

        //StopMoving();
        state = CreatureStates.Attacking;

        StartCoroutine(AttackAnimation(target, delay, 3));

        target.Defend(this, delay);
    }
コード例 #28
0
    public void AquireCreatureParts(GameObject[] partsArray)
    {
        playerScript = (PlayerScript)GameObject.FindWithTag("Player").GetComponent("PlayerScript");

        List <GameObject> creaturePartsList = new List <GameObject>();
        List <Vector3>    creaturePartsOriginalPositionList = new List <Vector3>();

        for (int i = 0; i < partsArray.Length; i++)
        {
            partsArray[i].transform.parent = transform;
            ((CreaturePart)partsArray[i].GetComponent("CreaturePart")).isPartOfCreature = true;
            partsArray[i].GetComponent <PVA>().enabled = false;
            creaturePartsList.Add(partsArray[i]);
            creaturePartsOriginalPositionList.Add(partsArray[i].transform.position);;
        }
        creaturePartsArray = creaturePartsList.ToArray();
        creaturePartsOriginalPositionArray = creaturePartsOriginalPositionList.ToArray();

        creatureState = CreatureStates.MovingPartsToRandomStartPositions;
    }
コード例 #29
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    // =====================================================
    // Movement
    // =====================================================

    protected virtual IEnumerator FollowPath()
    {
        state = CreatureStates.Moving;

        for (int i = 0; i < path.Count; i++)
        {
            // get next tile coords
            Vector2 p = path[i];
            int     x = (int)p.x;
            int     y = (int)p.y;

            yield return(StartCoroutine(FollowPathStep(x, y)));
        }

        // resolve encounters once we arrived to the goal
        ResolveEncountersAtGoal(this.x, this.y);

        // stop moving once we reach the goal
        StopMoving();
    }
コード例 #30
0
    void AssembleCreature()
    {
        // player hits the ground., need to complete creature formation
        if (playerScript.oldVelocity.y < 0 && playerScript.velocity.y == 0)
        {
            //Debug.Log("Hit Ground");
            for (int i = 0; i < creaturePartsArray.Length; i++)
            {
                creaturePartsArray[i].transform.position = transform.position;
                creaturePartsArray[i].transform.rotation = Quaternion.identity;
            }
            creatureState = CreatureStates.CollectingPathData;
        }

        // ordinary update
        for (int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position = Vector3.Lerp(creaturePartsOriginalPositionArray[i], transform.position, Mathf.SmoothStep(0f, 1f, playerScript.moveTowardsRatio));
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp(creaturePartsArray[i].transform.rotation, Quaternion.identity, Mathf.SmoothStep(0f, 1f, playerScript.moveTowardsRatio));
        }
    }
コード例 #31
0
    public void AquireCreatureParts(GameObject[] partsArray)
    {
        playerScript = (PlayerScript)GameObject.FindGameObjectWithTag("Player").GetComponent("PlayerScript");
        creatureManagerScript = (CreatureManagerScript)GameObject.Find("CreatureManager").GetComponent("CreatureManagerScript");

        List<GameObject> creaturePartsList = new List<GameObject>();
        List<Vector3> creaturePartsOriginalPositionList = new List<Vector3>();
        for(int i = 0; i < partsArray.Length; i++ )
        {
            partsArray[i].transform.parent = transform;
            ((CreaturePartsGeneralScript)partsArray[i].GetComponent("CreaturePartsGeneralScript")).isPartOfCreature = true;
            creaturePartsList.Add(partsArray[i]);
            creaturePartsOriginalPositionList.Add(partsArray[i].transform.position);

            partsRandomStartPositionsList.Add( creatureManagerScript.GenerateRandomPointOnSemiSpehere());  // set random target start positions for each part
        }
        creaturePartsArray = creaturePartsList.ToArray();
        creaturePartsOriginalPositionArray = creaturePartsOriginalPositionList.ToArray();

        creatureState = CreatureStates.MovingPartsToRandomStartPositions;
    }
コード例 #32
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    // =====================================================
    // Combat Animations
    // =====================================================

    protected IEnumerator AttackAnimation(Tile target, float delay = 0, float advanceDiv = 2)
    {
        yield return(new WaitForSeconds(delay));

        if (target == null)
        {
            yield break;
        }

        float duration = speed * 0.5f;

        sfx.Play("Audio/Sfx/Combat/woosh", 0.4f, Random.Range(0.5f, 1.5f));

        // move towards target
        float   t        = 0;
        Vector3 startPos = transform.localPosition;
        Vector3 endPos   = startPos + (target.transform.position - transform.position).normalized / advanceDiv;

        while (t <= 1)
        {
            t += Time.deltaTime / duration;
            transform.localPosition = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0f, 1f, t));
            yield return(null);
        }

        // move back to position
        t = 0;
        while (t <= 1)
        {
            t += Time.deltaTime / duration;
            transform.localPosition = Vector3.Lerp(endPos, startPos, Mathf.SmoothStep(0f, 1f, t));
            yield return(null);
        }

        state = CreatureStates.Idle;
    }
コード例 #33
0
ファイル: Creature.cs プロジェクト: carlesvallve/Tiler
    // =====================================================
    // Death
    // =====================================================

    protected void Die(Creature attacker, float delay = 0)
    {
        StopMoving();

        state = CreatureStates.Dying;
        StartCoroutine(DeathAnimation(attacker, delay));

        // get a list of all items carried by the creature
        List <Item> allItems = new List <Item>();

        foreach (List <Item> itemCategory in items.Values)
        {
            foreach (Item item in itemCategory)
            {
                allItems.Add(item);
            }
        }

        // spawn all the items carried by the creature
        SpawnItemsFromInventory(allItems);

        // update vision to refresh spawned items rendering
        grid.player.UpdateVision(grid.player.x, grid.player.y);
    }
コード例 #34
0
 private void Move(CreatureStates Creature,float x, float y)
 {
     Creature.transform.position = new Vector3 (x,y);
 }
コード例 #35
0
 private void RecordHeight(CreatureStates Creature, Raycast Raycast)
 {
     if (Raycast.SearchForCreature(Vector3.down,Creature.Storey -1))
         FallDistance = Raycast.TargetCreature.Height;
 }
コード例 #36
0
ファイル: Creature.cs プロジェクト: snaptothegrid/Tiler
    protected virtual void ResolveEntityEncounters(int x, int y)
    {
        Entity entity = grid.GetEntity(x, y);
        if (entity == null) { return; }

        // resolve closed/locked doors
        if (entity is Door) {
            Door door = (Door)entity;
            if (door.state != EntityStates.Open) {
                // open the door
                if (door.state == EntityStates.Closed) {
                    state = CreatureStates.Using;
                    StartCoroutine(door.Open(this));
                    return;

                // unlock the door
                } else if (door.state == EntityStates.Locked) {
                    state = CreatureStates.Using;
                    StartCoroutine(door.Unlock(this));
                    return;
                }
            }
        }

        // resolve closed/locked chests
        if (entity is Chest) {
            Chest chest = (Chest)entity;
            if (chest.state != EntityStates.Open) {
                // open the door
                if (chest.state == EntityStates.Closed) {
                    state = CreatureStates.Using;
                    StartCoroutine(chest.Open(this));
                    return;

                // unlock the door
                } else if (chest.state == EntityStates.Locked) {
                    state = CreatureStates.Using;
                    StartCoroutine(chest.Unlock(this));
                    return;
                }
            }
        }
    }
コード例 #37
0
ファイル: Creature.cs プロジェクト: snaptothegrid/Tiler
    protected void ResolveEncountersAtGoal(int x, int y)
    {
        Vector2 goal = path[path.Count - 1];
        if (x == (int)goal.x && y == (int)goal.y) {

            Entity entity = grid.GetEntity(x, y);
            if (entity != null) {

                // stairs (player only)
                if ((this is Player) && (entity is Stair)) {
                    Stair stair = (Stair)entity;

                    if (stair.state == EntityStates.Open) {
                        state = CreatureStates.Descending;
                        Dungeon.instance.ExitLevel (stair.direction);
                    } else {
                        Hud.instance.Log("The stair doors are locked.");
                    }
                }

            }
        }
    }
コード例 #38
0
    void FollowPath()
    {
        float pathProgressionRatio = currentPathTimeCounter / originalPathTimeLength;
        int currentPathNodeIndex = Mathf.FloorToInt(pathProgressionRatio * (float)positionsRecordingsList.Count);
        if(currentPathNodeIndex > positionsRecordingsList.Count -2) // gone through the entire list, arrived at the end of the path
        {
            creatureState = CreatureStates.AnimatingDeath_GatheringParts;
            return;
        }

        float ratioToNextPathNode = (pathProgressionRatio * (float)positionsRecordingsList.Count) - (float)currentPathNodeIndex;
        //updating head part
        creaturePartsArray[0].transform.position = Vector3.Lerp( positionsRecordingsList[currentPathNodeIndex], positionsRecordingsList[currentPathNodeIndex + 1], ratioToNextPathNode);
        creaturePartsArray[0].transform.rotation = Quaternion.Slerp( rotationsRecordingsList[currentPathNodeIndex], rotationsRecordingsList[currentPathNodeIndex + 1], ratioToNextPathNode);
        creaturePartsArray[0].renderer.material.color = Color.Lerp( colorsRecordingsList[currentPathNodeIndex], colorsRecordingsList[currentPathNodeIndex +1], ratioToNextPathNode );

        //update the position displacement
        float forwardSpeed = Mathf.Lerp( forwardSpeedStart, forwardSpeedEnd,  Mathf.Sqrt( Mathf.Sqrt(pathProgressionRatio) ) );
        positionDisplacement += new Vector3(-forwardSpeed * Time.deltaTime * plabackTimeScale,0,0);
        //displace the head with the speed/position displacement vector
        creaturePartsArray[0].transform.position += positionDisplacement + initialPositionOffset;

        // make body parts follow the one in front
        for(int i = 1; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position = Vector3.Lerp( creaturePartsArray[i].transform.position, creaturePartsArray[i-1].transform.position, 21 * plabackTimeScale * Time.deltaTime );
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp( creaturePartsArray[i].transform.rotation, creaturePartsArray[i-1].transform.rotation, 7 * plabackTimeScale * Time.deltaTime);
            creaturePartsArray[i].renderer.material.color = Color.Lerp( creaturePartsArray[i].renderer.material.color, creaturePartsArray[i-1].renderer.material.color, 21 * plabackTimeScale * Time.deltaTime);
        }
        currentPathTimeCounter += Time.deltaTime * plabackTimeScale;
    }
コード例 #39
0
    void AnimateDeath_ShootUpParts()
    {
        Vector3 bottomPosition = finalAliveHeadPosition;
        Vector3 topPosition = bottomPosition + new Vector3(0, positionsRecordingsList.Count * 1.5f, 0); // rise is proportional to number of parts
        shootUpLerpCounter += 1f * Time.deltaTime;
        for(int i =0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position = Vector3.Lerp( creaturePartsArray[i].transform.position, topPosition, Mathf.SmoothStep(0,1f, shootUpLerpCounter) );
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp( creaturePartsArray[i].transform.rotation, Quaternion.identity, Mathf.SmoothStep(0,1f, shootUpLerpCounter) );
        }

        Vector3 currentPosition = creaturePartsArray[0].transform.position;
        if( (topPosition.y - currentPosition.y)/(topPosition.y  - bottomPosition.y) < 0.01f ) // if past 99% to the target, end
        {
            if(waitCounter < 0.50f)
                waitCounter += Time.deltaTime;
            else
                creatureState = CreatureStates.AnimatingDeath_SendingoffParts;
        }
    }
コード例 #40
0
ファイル: MabiCreature.cs プロジェクト: nvrlcky/aura
 /// <summary>
 /// Adds creature state "Dead".
 /// </summary>
 public virtual void Die()
 {
     this.Deactivate(CreatureConditionA.Deadly);
     this.State |= CreatureStates.Dead;
 }
コード例 #41
0
ファイル: Creature.cs プロジェクト: NegativeJ/aura
		public bool Has(CreatureStates state) { return ((this.State & state) != 0); }
コード例 #42
0
ファイル: MabiCreature.cs プロジェクト: pjm0616/aura
        /// <summary>
        /// Revives creature and sends necessary packets (BackFromDead + Stat Update).
        /// </summary>
        public void Revive()
        {
            if (!this.IsDead)
                return;

            this.State &= ~CreatureStates.Dead;
            this.CauseOfDeath = DeathCauses.None;
            this.WaitingForRes = false;

            WorldManager.Instance.Broadcast(new MabiPacket(Op.BackFromTheDead1, this.Id), SendTargets.Range, this);
            WorldManager.Instance.CreatureStatsUpdate(this);
            WorldManager.Instance.Broadcast(new MabiPacket(Op.BackFromTheDead2, this.Id), SendTargets.Range, this);
        }
コード例 #43
0
ファイル: MabiCreature.cs プロジェクト: pjm0616/aura
 /// <summary>
 /// Adds creature state "Dead".
 /// </summary>
 public virtual void Die()
 {
     this.State |= CreatureStates.Dead;
 }
コード例 #44
0
    void CollectPathData()
    {
        //Debug.Log("Player HIT GROUND_COLLECTDATA");
        //Debug.Log("Framecount: " + Time.frameCount.ToString() );

        // get the data from the original list in the player
        positionsRecordingsList = new List<Vector3>( playerScript.positionRecordingList );
        rotationsRecordingsList = new List<Quaternion>( playerScript.rotationRecordingList );
        colorsRecordingsList = new List<Color>( playerScript.colorRecordingList );
        //set color transparency, only works if shader in material is of Transparent/ type
        for(int i = 0; i < colorsRecordingsList.Count; i++)
        {
            Color tempColor = colorsRecordingsList[i];
            tempColor.a = 0.9f;
            colorsRecordingsList[i] = tempColor;
        }
        // get original flight duration
        originalPathTimeLength = playerScript.recordingLength;
        // get spawn offset
        // CHEAP HACKED FIX, TODO, BETTER FIX
        if(positionsRecordingsList.Count == 0)
        {
            creatureState = CreatureStates.AnimatingDeath_SendingoffParts;
            return;
        }
        initialPositionOffset = transform.position - positionsRecordingsList[0];
        // wipe the original
        playerScript.positionRecordingList.Clear();
        playerScript.rotationRecordingList.Clear();
        playerScript.colorRecordingList.Clear();
        //Debug.Log("CLEARED DATA");
        // change state
        creatureState = CreatureStates.FollowingPath;

        // set initial color
        for(int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].renderer.material.color = colorsRecordingsList[0];
        }
    }
コード例 #45
0
 public virtual void Activate(CreatureStates Creature, Raycast Raycast, State State)
 {
 }
コード例 #46
0
 void AnimateDeath_GatherParts()
 {
     Vector3 headPostion = creaturePartsArray[0].transform.position;
     Vector3 lastPartPosition = creaturePartsArray[creaturePartsArray.Length -1].transform.position;
     if( Mathf.Abs(Vector3.Distance(headPostion, lastPartPosition)) > 5) // conitnue body animation until the last piece has caught up sufficiently to the head
     {
         for(int i = 1; i < creaturePartsArray.Length; i++)
         {
             creaturePartsArray[i].transform.position = Vector3.Lerp( creaturePartsArray[i].transform.position, creaturePartsArray[i-1].transform.position, 25 * plabackTimeScale * Time.deltaTime );
             creaturePartsArray[i].transform.rotation = Quaternion.Slerp( creaturePartsArray[i].transform.rotation, creaturePartsArray[i-1].transform.rotation, 25 * plabackTimeScale * Time.deltaTime);
             creaturePartsArray[i].renderer.material.color = Color.Lerp( creaturePartsArray[i].renderer.material.color, creaturePartsArray[i-1].renderer.material.color, 25 * plabackTimeScale * Time.deltaTime);
         }
     }
     else
     {
         finalAliveHeadPosition = creaturePartsArray[0].transform.position;
         creatureState = CreatureStates.AnimatingDeath_ShootingUpParts;
     }
 }
コード例 #47
0
ファイル: Creature.cs プロジェクト: NegativeJ/aura
		public void Activate(CreatureStates state) { this.State |= state; }
コード例 #48
0
    void AssembleCreature()
    {
        partsStartColor =  playerScript.colorRecordingList[0];

        // player hits the ground., need to complete creature formation
        if( playerScript.velocity.y == 0 || playerScript.oldVelocity.y == 0  )
        {
            //Debug.Log("Hit Ground");
            for(int i = 0; i < creaturePartsArray.Length; i++)
            {
                creaturePartsArray[i].transform.position = transform.position;
                creaturePartsArray[i].transform.rotation = Quaternion.identity;
            }
            creatureState = CreatureStates.CollectingPathData;
            //Debug.Log("Player HIT GROUND_ASSEBLE");
            //Debug.Log("Framecount: " + Time.frameCount.ToString() );
        }

        // ordinary update
        for(int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position = Vector3.Lerp(creaturePartsOriginalPositionArray[i], transform.position, Mathf.SmoothStep(0f,1f,playerScript.moveTowardsRatio));
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp( creaturePartsArray[i].transform.rotation, Quaternion.identity, Mathf.SmoothStep(0f,1f,playerScript.moveTowardsRatio) );
            creaturePartsArray[i].renderer.material.color = Color.Lerp( creaturePartsArray[i].renderer.material.color, partsStartColor , 0.75f *Mathf.SmoothStep(0f,1f,playerScript.moveTowardsRatio) );
        }
    }
コード例 #49
0
ファイル: Creature.cs プロジェクト: NegativeJ/aura
		public void Deactivate(CreatureStates state) { this.State &= ~state; }
コード例 #50
0
 protected void DirectionalSlash(CreatureStates Creature,Raycast Raycast, Vector3 FacingDirection, Vector3 SlashDirection)
 {
     if (Creature.Front == FacingDirection)
         VanillaSlash(Creature,Raycast,SlashDirection);
 }
コード例 #51
0
    void AnimateDeath_SendoffParts()
    {
        float sendoffSpeedScale = 1.5f;
        float deltaCounter = 0;
        for(int i = 0; i < creaturePartsArray.Length; i++)
        {
            //update final location
            int aIndex = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).arrayIndex;

            Vector3 anchorPosition = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.positionsList[aIndex];
            anchorPosition = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.transform.TransformPoint(anchorPosition);
            creaturePartsArray[i].transform.position = Vector3.Lerp( creaturePartsArray[i].transform.position, anchorPosition , sendoffSpeedScale * Time.deltaTime );

            // lerp to target rotation
            Quaternion anchorRotation = ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).ownerArrayScript.rotationsList[aIndex];
            creaturePartsArray[i].transform.rotation = Quaternion.Slerp( creaturePartsArray[i].transform.rotation, anchorRotation, sendoffSpeedScale * Time.deltaTime);

            // lerp color
            Color targetColor =  ((CreaturePartsGeneralScript)creaturePartsArray[i].GetComponent("CreaturePartsGeneralScript")).partsArrayColor ;
            creaturePartsArray[i].renderer.material.color = Color.Lerp( creaturePartsArray[i].renderer.material.color, targetColor , sendoffSpeedScale * Time.deltaTime);

            deltaCounter += Vector3.Distance( creaturePartsArray[i].transform.position, anchorPosition);
        }
        float deltaAverage = deltaCounter/(float)creaturePartsArray.Length;
        if(deltaAverage < 5)
            creatureState = CreatureStates.RelinquishingParts;
    }
コード例 #52
0
    void MovePartsToRandomStartPositions()
    {
        // normal update, move towards start target posotions
        float velocityRatio = 1.0f - (playerScript.velocity.y/spawnPlayerJumpVelocity);
        for(int i = 0; i < creaturePartsArray.Length; i++)
        {
            creaturePartsArray[i].transform.position = Vector3.Lerp(creaturePartsOriginalPositionArray[i], partsRandomStartPositionsList[i], Mathf.SmoothStep(0f,1f,velocityRatio) );
        }

        // if starting to fall down,  lock down positions and move to next state
        if(playerScript.velocity.y < 0)
        {
            for(int i = 0; i < creaturePartsArray.Length; i++)
                creaturePartsOriginalPositionArray[i] = creaturePartsArray[i].transform.position;

            creatureState = CreatureStates.AssemblingParts;
        }
    }