Example #1
0
    public bool Damage(int damage)
    {
        bool hitSuccess = false;
        bool canDamage  = true;

        if (health == 0 || character.rolling == 1 || character.invulnerable || character.stunned == 2)
        {
            canDamage = false;
        }

        if (character.isPlayer)
        {
            if (character.stunned == 1)
            {
                canDamage  = false;
                hitSuccess = true;
            }
        }

        if (canDamage)
        {
            health -= damage;

            if (health < 0)
            {
                health = 0;
            }

            if (character.isPlayer == false)
            {
                character.ai.Damage();
            }

            AlterHealthBar();

            character.AttackCancel();


            if (health > 0)
            {
                character.Hurt();
            }
            else
            {
                healthBar.Kill();
                character.Kill();
                SCR_main.PlayRandomSound(SND_death);
            }

            hitSuccess = true;
        }

        return(hitSuccess);
    }
Example #2
0
    void UpdateState()
    {
        stateCounter += Time.deltaTime;

        //INTRO
        if (state == 10)
        {
            if (stateCounter >= 0.5f)
            {
                CreateCountDown(0);
                StateNext();
            }
        }
        if (state == 11)
        {
            if (stateCounter >= 1f)
            {
                CreateCountDown(1);
                StateNext();
            }
        }
        if (state == 12)
        {
            if (stateCounter >= 1f)
            {
                cam.InitiateStage(1);
                CreateCountDown(2);
                StateNext();
            }
        }
        if (state == 13)
        {
            if (stateCounter >= 1f)
            {
                CreateCountDown(3);
                pauseAllowed = true;
                SCR_input.playerControlActive = true;
                SCR_enemySpawner.spawnOn      = true;
                player.GetComponent <SCR_characterControl>().ReticleOn(true);

                StateNext();
            }
        }
        if (state == 14)
        {
            if (stateCounter >= 1f)
            {
                ShowHUD(true);
                SetState(0);
            }
        }

        //FAIL
        if (state == 20)
        {
            if (stateCounter >= 0.6f)
            {
                SCR_gui.CreateIcon("GameOver", Vector3.zero);

                if (SCR_main.hMusic)
                {
                    music.FadeOut(1);
                }

                StateNext();
            }
        }

        if (state == 21)
        {
            if (stateCounter >= 0.3f)
            {
                if (SCR_main.hCursor)
                {
                    Cursor.visible = true;
                }

                optionPos = stageFinishOptionPos;
                SCR_gui.CreateOption("StageFailRetry", optionPos);
                optionPos += SCR_gui.optionSpacing;
                SCR_gui.CreateOption("StageFailExit", optionPos);
                SetState(0);
            }
        }


        //SUCCESS
        if (state == 30)
        {
            if (stateCounter >= 1f)
            {
                SCR_input.playerControlActive = false;
                player.GetComponent <SCR_characterControl>().ReticleOn(false);

                player.AttackCancel();
                player.speed[1] = Vector3.zero;
                player.PlayAnim(0);

                if (SCR_main.hMusic)
                {
                    music.FadeOut(1);
                }

                StateNext();
            }
        }

        if (state == 31)
        {
            if (stateCounter >= 0.3f)
            {
                startTimer = false;
                SCR_gui.CreateIcon("StageComplete", Vector3.zero);
                StateNext();
            }
        }

        if (state == 32)
        {
            if (stateCounter >= 0.2f)
            {
                if (SCR_main.hCursor)
                {
                    Cursor.visible = true;
                }

                optionPos = stageFinishOptionPos;
                SCR_gui.CreateOption("StageCompleteContinue", optionPos);
                optionPos += SCR_gui.optionSpacing;
                SCR_gui.CreateOption("StageCompleteExit", optionPos);
                SetState(0);
            }
        }
    }
Example #3
0
    void UpdateControl()
    {
        bool    canMove     = true;
        bool    dirPressed  = false;
        bool    planeHit    = false;
        Vector3 destination = Vector3.zero;

        if (character.attacking)
        {
            //prevent movement if the character is performing a standing attack.
            if (character.melee)
            {
                if (character.characterMelee.attackAnimSlot == 5 || character.characterMelee.attackAnimSlot == 6)
                {
                    canMove = false;
                }
            }
            else
            {
                if (character.characterRanged.attackAnimSlot == 5 || character.characterRanged.attackAnimSlot == 6)
                {
                    canMove = false;
                }
            }
        }

        if (standAttack == true && character.attacking)
        {
            //prevent movement if the character is performing a standing attack.
            if (character.melee)
            {
                if (character.characterMelee.attackAnimSlot == 7 || character.characterMelee.attackAnimSlot == 8)
                {
                    canMove            = false;
                    character.speed[1] = Vector3.zero;
                    character.running  = false;
                }
            }
            else
            {
                if (character.characterRanged.attackAnimSlot == 7 || character.characterRanged.attackAnimSlot == 8)
                {
                    canMove            = false;
                    character.speed[1] = Vector3.zero;
                    character.running  = false;
                }
            }
        }

        //Click or Double Click
        int newClick = 0;

        if (SCR_input.cType == 0)
        {
            if (Input.GetMouseButton(1))
            {
                if (rightClickHeld == false)
                {
                    rightClickHeld = true;

                    if (clickCurrent == 0)
                    {
                        clickCurrent = 1;
                        newClick     = 1;
                    }
                    else
                    {
                        if (clickCurrent == 1 && doubleClickTimer > 0f)
                        {
                            clickCurrent     = 0;
                            doubleClickTimer = 0f;
                            newClick         = 2;
                        }
                    }
                }
            }
            else
            {
                if (rightClickHeld)
                {
                    rightClickHeld = false;

                    if (clickCurrent == 1)
                    {
                        doubleClickTimer = doubleClickLimit;
                    }
                }
            }

            if (doubleClickTimer > 0f)
            {
                doubleClickTimer = Mathf.MoveTowards(doubleClickTimer, 0f, Time.deltaTime);

                if (doubleClickTimer == 0f)
                {
                    clickCurrent = 0;
                }
            }
        }
        else
        {
            if (SCR_input.cType == 1)
            {
                if (Input.GetMouseButtonDown(1))
                {
                    newClick = 2;
                }
            }
        }

        Plane plane   = new Plane(Vector3.up, Vector3.zero);
        float hitDist = 0f;
        Ray   ray;

        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (plane.Raycast(ray, out hitDist))
        {
            destination = ray.GetPoint(hitDist);
            planeHit    = true;

            if (reticle && Time.timeScale == 1f)
            {
                reticle.SetPos(new Vector2(destination.x, destination.z));
            }
        }


        if (SCR_input.cType == 0)
        {
            if (planeHit)
            {
                character.SetRotAngle(destination);
            }

            if (Input.GetMouseButton(1))
            {
                dirPressed = true;
            }
        }
        else
        {
            float inputX = Input.GetAxis("Horizontal");
            float inputY = Input.GetAxis("Vertical");

            if (inputX != 0f || inputY != 0f)
            {
                dirPressed = true;

                Vector3 inputDir = new Vector3(inputX, 0f, inputY).normalized;
                character.SetRotAngle(transform.position + inputDir);
            }
        }


        if (character.rolling == 0 && character.stunned == 0)
        {
            //Move to destination
            if (dirPressed)
            {
                if (canMove)
                {
                    character.speed[1] = (character.dir * character.runSpeed);

                    character.running = true;

                    if (character.attacking == false)
                    {
                        character.PlayAnim(1);
                    }
                }
                bool canRotate = true;

                if (character.attacking)
                {
                    canRotate = false;
                }

                if (character.melee)
                {
                    if (character.characterMelee.lockActive)
                    {
                        canRotate = false;
                    }
                }

                if (canRotate)
                {
                    character.SetRotTarget();
                }
            }
            else
            {
                character.speed[1] = Vector3.zero;
                character.running  = false;

                if (character.attacking == false)
                {
                    character.PlayAnim(0);
                }
                else
                {
                    //if character is performing a running attack and stops moving, the attack is cancelled.
                    if (character.melee)
                    {
                        if (character.characterMelee.attackAnimSlot == 7 || character.characterMelee.attackAnimSlot == 8)
                        {
                            character.PlayAnim(0);
                            character.AttackCancel();
                        }
                    }
                    else
                    {
                        if (character.characterRanged.attackAnimSlot == 7 || character.characterRanged.attackAnimSlot == 8)
                        {
                            character.PlayAnim(0);
                            character.AttackCancel();
                        }
                    }
                }
            }

            //Attack

            if (Input.GetMouseButtonDown(0))
            {
                if (character.rolling == 0 && character.stunned == 0)
                {
                    character.SetRotAngle(destination);
                    character.SetRotTarget();
                }

                character.attackPoint = destination;
                character.AttackStart();
            }
        }

        if (newClick == 2)
        {
            //Roll
            character.RollStart();
        }
    }