Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (movePhase == MovePhase.PhaseOne)
     {
         if (transform.position.z <= 12)
         {
             if (GetComponent <CraftController>().currentHp * 100 / GetComponent <CraftController>().hp >= 80)
             {
                 movePhase = MovePhase.PhaseTwo;
             }
             else
             {
                 movePhase = MovePhase.PhaseThree;
             }
             GetComponent <Rigidbody>().velocity = Vector3.zero;
             moveVertexIndex = 0;
         }
     }
     else if (movePhase == MovePhase.PhaseTwo)
     {
         if (GetComponent <CraftController>().currentHp * 100 / GetComponent <CraftController>().hp <= 80)
         {
             movePhase       = MovePhase.PhaseThree;
             moveVertexIndex = 0;
         }
     }
 }
Example #2
0
 /* Movement */
 public void SetTarget(Vector2 pos)
 {
     if (pos != (Vector2)transform.position)
     {
         _targetPosition = pos;
         _moving         = MovePhase.Moving;
     }
 }
Example #3
0
 public void DIE()
 {
     state = MovePhase.EndTurn;
     turnCRTL.targets.Remove(transform);
     Debug.Log("DIED");
     turnCRTL.units.Remove(gameObject);
     turnCRTL.SortByIndex(finalIndex);
     turnCRTL.SortList();
     GameObject.Destroy(gameObject);
 }
Example #4
0
 //ENds turn and sends action to next player if needed
 void turnNext()
 {
     //If execution is on, send action to the next player
     if (turnCRTL.exec == true)
     {
         turnCRTL.SendAction();
     }
     Debug.Log("TurnEnded " + finalIndex);
     //sets self to wait
     state = MovePhase.waiting;
 }
    protected override void Init(EGameState gameState)
    {
        base.Init(gameState);

        startT = t;
        rb     = GetComponent <Rigidbody>();
        if (rb != null)
        {
            rb.isKinematic = true;
        }
        phase  = startState;
        frozen = startFrozen;
    }
Example #6
0
    //Tells the player to start the turn and what to do
    public void TurnStart(int action)
    {
        state = MovePhase.executing;
        //if no action given, wait a turn
        if (action == 0)
        {
            state = MovePhase.EndTurn;
            //Debug.Log("waited turn");
        }

        else if (action <= 2)
        {
            //move unit 1 or 2 squares
            moveUnit(suunta, action);
        }

        if (action == 3)
        {
            //flip the player and end turn
            Flip();
        }
        if (action == 4)
        {
            //Starts the jump
            jump(Vector2.up * 3);
        }
        if (action == 5)
        {
            //starts a different jump
            jump(Vector2.up * 2 + Vector2.right * suunta);
        }
        if (action == 6)
        {
            jump(Vector2.up * 1 + Vector2.right * suunta * 2);
        }
        if (action == 7)
        {
            //Makes the player Crouch
            crouch();
            state = MovePhase.EndTurn;
        }
        if (action == 8)
        {
            //starts the shooting function
            //TODO: implement shooting and move ending turn to the ammo

            state = MovePhase.shooting;
            shoot(suunta);
        }
        actionLocal = action;
    }
Example #7
0
    // Move towards the target position
    void MoveTowardsTarget()
    {
        Vector2 posNow = transform.position;

        switch (_moving)
        {
        case MovePhase.Moving:
            float movedDistance = (posNow - _lastPosition).magnitude;

            if (posNow != _targetPosition)             // If we haven't reached target pos
            {
                if ((movedDistance < _stallThreshold)) // Check if we're stalled
                {
                    //_moving = MovePhase.Stalled;
                }

                _distance = posNow - _targetPosition;
                if (_anim != null)
                {
                    _anim.SetFloat("hSpeed", _distance.x);
                }
                _rb.MovePosition(Vector2.MoveTowards(posNow, _targetPosition, MoveSpeed / 20));
            }
            else
            {
                _moving = MovePhase.Idle;
            }

            break;

        case MovePhase.Stalled:
            Debug.Log("Stalled!");
            _targetPosition = posNow;
            _moving         = MovePhase.Idle;
            break;

        case MovePhase.Idle:

            break;
        }

        if (_anim != null)
        {
            _anim.SetBool("Stopped", _moving == MovePhase.Idle);
        }

        _lastPosition = posNow;
    }
    protected override void DidEnterGameState(EGameState gameState, EGameState fromState)
    {
        bool wasActive = isActive;

        base.DidEnterGameState(gameState, fromState);
        if (isActive)
        {
            t         = startT;
            phaseTime = 0f;
            if (fromState != EGameState.Paused && fromState != EGameState.Map)
            {
                phase  = startState;
                frozen = startFrozen;
                dT     = 0f;
            }
        }
    }
Example #9
0
    //Handles all the turn logic
    void TurnLogic()
    {
        isGrounded = CollisionCheck(transform.position, Vector2.down, 1, groundLayer);
        //inElevator = CollisionCheck(transform.position, Vector2.down, 1, elevatorLayer);
        CanMove = !CollisionCheck(transform.position - new Vector3(0, 0.25f, 0), (Vector2.right * suunta) * 1.1f, 0.5f, groundLayer) && !CollisionCheck(transform.position + new Vector3(0, 0.25f, 0), (Vector2.right * suunta) * 1.1f, 0.5f, groundLayer);
        IsDead  = CollisionCheck(transform.position, Vector2.down, 1, DeathLayer);
        //Debug.Log("CanMove: "+ CanMove+ " Player: "+ playerIndex);
        if (Physics2D.OverlapCircle(transform.position - new Vector3(0, 0.25f, 0), 0.2f, groundLayer))
        {
            GoToGrid();
            transform.position = (Vector2)transform.position + Vector2.up;
        }
        if (IsDead)
        {
            DIE();
        }
        if (state == MovePhase.executing || state == MovePhase.InAir)
        {
            transform.position = Vector2.MoveTowards(transform.position, target, 0.2f * speed * Time.deltaTime);
        }
        if (state == MovePhase.executing && actionLocal <= 2)
        {
            speed = 10;
            anim.SetBool("Walk", true);
        }
        if (state == MovePhase.executing && actionLocal > 3 && actionLocal < 7)
        {
            speed = 30;
            anim.SetBool("Jump", true);
        }
        if (state != MovePhase.executing)
        {
            anim.SetBool("Walk", false);
            anim.SetBool("Jump", false);
        }
        if (state == MovePhase.executing && (Vector2)transform.position == target && isGrounded)
        {
            state = MovePhase.EndTurn;
        }
        if (state == MovePhase.executing && (Vector2)transform.position == target && !isGrounded)
        {
            state = MovePhase.InAir;
            gravity(Liikkuvuus);
        }
        if (state == MovePhase.InAir && isGrounded)
        {
            GoToGrid();
            airtime = -1;
            state   = MovePhase.EndTurn;
        }
        if (state == MovePhase.InAir && !isGrounded && (Vector2)transform.position == target)
        {
            gravity(Liikkuvuus);
        }
        if (!CanMove && !performFallDown && state == MovePhase.executing)
        {
            GoToGrid();
            state = MovePhase.EndTurn;
        }
        if (state == MovePhase.EndTurn)
        {
            turnNext();
        }
        if (state == MovePhase.waiting && !turnCRTL.exec)
        {
            state = MovePhase.Plan;
        }
        RaycastHit2D hitElevator = Physics2D.Raycast(new Vector2(transform.position.x,
                                                                 transform.position.y - 1.05f), -transform.up);

        if (hitElevator.collider != null)
        {
            if (hitElevator.collider.gameObject.tag == ("Elevator"))
            {
                inElevator = true;
            }
            else
            {
                inElevator = false;
            }
        }
        if (hitElevator.collider == null)
        {
            inElevator = false;
        }
        if (!isGrounded && !performFallDown && state == MovePhase.Plan && !inElevator)
        {
            RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x,
                                                             transform.position.y - 1.05f), -transform.up);
            if (hit.collider != null)
            {
                targetPos = (new Vector2(hit.collider.transform.position.x,
                                         hit.collider.transform.position.y * 1.5f));
            }
            else
            {
                targetPos = new Vector2(0, -1000f);
            }
            performFallDown = true;
        }
        if (performFallDown == true)
        {
            FallDown(speed / 10);
        }
    }
Example #10
0
 void StartMoving(MovePhase phase)
 {
     _vars.MoveRemainTime = 0;
     _vars.MoveStopTime   = DateTime.MinValue;
     _vars.MovePhase      = phase;
 }
    protected override void FixedUpdatePlay()
    {
        base.FixedUpdatePlay();



        if (!frozen)
        {
            switch (phase)
            {
            case MovePhase.MoveUp:

                dT = Mathf.Lerp(dT, Time.fixedDeltaTime / moveTime, 0.25f);


                if (t >= 1f)
                {
                    phase     = MovePhase.PauseTop;
                    phaseTime = 0f;
                }
                break;

            case MovePhase.PauseTop:
                phaseTime += Time.fixedDeltaTime;
                dT         = 0f;
                if (phaseTime >= pauseTime)
                {
                    phase = cycle? MovePhase.MoveUp : MovePhase.MoveDown;
                    if (cycle)
                    {
                        t = 0f;
                    }
                    phaseTime = 0f;
                }
                break;

            case MovePhase.MoveDown:
                dT = Mathf.Lerp(dT, -Time.fixedDeltaTime / moveTime, 0.25f);


                if (t <= 0f)
                {
                    phase     = MovePhase.PauseBottom;
                    phaseTime = 0f;
                }
                break;

            case MovePhase.PauseBottom:
                phaseTime += Time.fixedDeltaTime;
                dT         = 0;
                if (phaseTime >= pauseTime)
                {
                    phase     = MovePhase.MoveUp;
                    phaseTime = 0f;
                }
                break;
            }
        }
        else
        {
            dT *= 0.98f;
        }

        t += dT;

        float outT = t;

        if (smooth)
        {
            outT = KSpline.SmoothT(t);
        }

        Vector3 newPos = line.ReadPoint(outT);

        if (rb != null)
        {
            rb.MovePosition(newPos);
        }
        else
        {
            transform.position = newPos;
        }
    }
Example #12
0
 // Use this for initialization
 new void Start()
 {
     base.Start();
     movePhase = MovePhase.PhaseOne;
 }