Esempio n. 1
0
    IEnumerator DelayedRespawn(float seconds)
    {
        yield return(new WaitForSeconds(seconds));

        if (Respawn)
        {
            PlayerMovement pm = gameObject.GetComponent <PlayerMovement>();
            if (pm == null)
            {
                pm = gameObject.transform.parent.GetComponent <PlayerMovement>();
            }

            pm.gameObject.transform.position = SpawnManager.instance.GetRandomSpawnPoint();

            Rigidbody2D rig = isClone ? gameObject.transform.parent.gameObject.GetComponent <Rigidbody2D>() : GetComponent <Rigidbody2D>();
            //animations, immunity and stopping movement during that
            rig.gravityScale = 1;
            rig.isKinematic  = false;
            Array.ForEach(GetComponentsInChildren <Collider2D>(), x => x.isTrigger = false);
            SheetAnimation ani       = isClone ? gameObject.transform.parent.gameObject.GetComponent <SheetAnimation>() : GetComponent <SheetAnimation>();
            float          spawnTime = 0.5f;
            ani.PlayAnimation("Spawn", color, false, 8.0f / spawnTime);
            SetImmunity(true, true, spawnTime * 2.0f);  //extra immunity after spawning (*2.0f)
            pm.StunnedTimer = spawnTime;
            rig.isKinematic = true;
            StartCoroutine(SpawnCallback(spawnTime));
        }
        else
        {
            LevelBounds.instance.UnRegisterObject(this.gameObject);
            GameObject.Destroy(this.gameObject);
        }
    }
Esempio n. 2
0
    public void OnDeath(GameObject other)
    {
        FindObjectOfType <Splat>().DoSplat(transform.position, 0, (int)color);

        /*
         * //splat
         * GameObject splatObject = new GameObject("splatInstance");
         * splatObject.transform.position = this.gameObject.transform.position;
         * SpriteRenderer SR = splatObject.AddComponent<SpriteRenderer>();
         * SR.flipX = UnityEngine.Random.Range(0, 2) == 0? false : true;
         * SR.flipY = UnityEngine.Random.Range(0, 2) == 0 ? false : true;
         *
         * SR.sortingOrder = -14;  //before background but behind the rest
         * SheetAnimation ani = splatObject.AddComponent<SheetAnimation>();
         * LevelBounds.instance.RegisterObject(splatObject, true);
         * ani.PlayAnimation("Splat", color, false, 1);
         */
        /*
         * //shield powerup / spawn immunity
         * if(Immunity)
         * {
         *  if (!StayImmune) Immunity = false;
         *  IC();
         *  return;
         * }*/
        //score
        //Debug.Log(other.name + gameObject.name);
        int playerID     = other.name.Contains("1") ? 0 : (other.name.Contains("2") ? 1 : (other.name.Contains("3") ? 2 : 3));
        int thisplayerID = gameObject.name.Contains("1") ? 0 : (gameObject.name.Contains("2") ? 1 : (gameObject.name.Contains("3") ? 2 : 3));

        if (playerID == thisplayerID)
        {
            return;
        }
        //if (playerID > ScoreManager.instance.score.Length) playerID = 1;
        int useingID = ScoreManager.instance.scoreMode == ScoreManager.ScoreMode.Health ? thisplayerID : playerID;

        ScoreManager.instance.ChangeScore(useingID, ScorePerKill);
        if (ScoreManager.instance.scoreMode == ScoreManager.ScoreMode.Health && ScoreManager.instance.score[useingID] <= 0)
        {
            Respawn = false;
        }



        //Tag mode
        if (ScoreManager.instance.gameMode is TagMode)
        {
            TagMode Tagmode = (TagMode)ScoreManager.instance.gameMode;
            if (Tagmode.currentTag == other)
            {
                Tagmode.RemoveTag(other);
                //if (other.GetComponentInChildren<PlayerHit>())
                Tagmode.SetTag(gameObject);
            }

            /*
             * else if (Tagmode.currentTag == other)
             * {
             *  ScoreManager.instance.ChangeScore(playerID, 5);//bonus points if you are the Tag
             * }*/
        }
        else

        if (ScoreManager.instance.gameMode is OwnedMode)
        {
            OwnedMode ownedMode = (OwnedMode)ScoreManager.instance.gameMode;
            ownedMode.SetOwned(gameObject, other);
        }
        else

        //chicken mode
        if (ScoreManager.instance.gameMode is ChickenMode)
        {
            ChickenMode chickenmode = (ChickenMode)ScoreManager.instance.gameMode;
            if (chickenmode.currentChicken == gameObject || chickenmode.currentChicken == null)
            {
                chickenmode.RemoveChicken(gameObject);
                if (other.GetComponentInChildren <PlayerHit>())
                {
                    chickenmode.SetChicken(other);
                }
            }
            else if (chickenmode.currentChicken == other)
            {
                ScoreManager.instance.ChangeScore(playerID, 5);//bonus points if you are the chicken
            }
        }


        float          deathTime = 0.5f;
        PlayerMovement pm        = isClone ? gameObject.transform.parent.gameObject.GetComponent <PlayerMovement>() : GetComponent <PlayerMovement>();

        pm.StunnedTimer = deathTime;
        Rigidbody2D rig = isClone ? gameObject.transform.parent.gameObject.GetComponent <Rigidbody2D>() : GetComponent <Rigidbody2D>();

        rig.gravityScale = 0;
        rig.velocity     = Vector2.zero;
        rig.isKinematic  = true;
        PowerupUser pu = isClone? gameObject.transform.parent.gameObject.GetComponent <PowerupUser>() : GetComponent <PowerupUser>();

        pu.EndAllPowerups();
        Array.ForEach(GetComponentsInChildren <Collider2D>(), x => x.isTrigger = true);
        SheetAnimation sa = isClone ? gameObject.transform.parent.gameObject.GetComponent <SheetAnimation>() : GetComponent <SheetAnimation>();

        sa.PlayAnimation("Death", color, false, 5.0f / deathTime);
        StartCoroutine(DelayedRespawn(deathTime));

        /*
         * if (Respawn)
         * {
         *  PlayerMovement pm = gameObject.GetComponent<PlayerMovement>();
         *  if (pm == null) pm = gameObject.transform.parent.GetComponent<PlayerMovement>();
         *  PlayerMovement.Controls controls = pm.controls;
         *  pm.gameObject.transform.position = SpawnManager.instance.GetRandomSpawnPoint();
         * }
         * else
         * {
         *  GameObject.Destroy(this.gameObject);
         * }*/
    }
Esempio n. 3
0
    public void DoMovement(NetworkBase.PlayerInput input)
    {
        if (!canMove)
        {
            return;
        }
        //if (NetworkControl) return;

        bool grounded = false;

        float spriteXSizeHalf = gameObject.GetComponent <SpriteRenderer>().sprite.bounds.size.x / 2f;
        //racasts checking if player is standing on a block, casts from both edges of hitbox
        RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position - Vector2.up * 0.20f + new Vector2(spriteXSizeHalf - 0.05f, 0), -Vector2.up, 0.10f);

        //RaycastHit2D hit2 = Physics2D.Raycast((Vector2)transform.position - Vector2.up * 0.20f - new Vector2(gameObject.GetComponent<SpriteRenderer>().sprite.bounds.size.x / 2f, 0), -Vector2.up, 0.10f);
        //if ((hit.transform != null && hit.transform != transform) || (hit2.transform != null && hit2.transform != transform))
        //    grounded = true;
        if (hit.transform != null && hit.transform != transform)
        {
            grounded = true;
        }
        else
        {
            RaycastHit2D hit2 = Physics2D.Raycast((Vector2)transform.position - Vector2.up * 0.20f - new Vector2(spriteXSizeHalf - 0.05f, 0), -Vector2.up, 0.10f);
            if (hit2.transform != null && hit2.transform != transform)
            {
                grounded = true;
            }
        }

        //if (!Grounded && grounded) SAnimation.PlayAnimation("Idle", Pcolor);
        Grounded = grounded;

        /*
         * //Quickstop before input check
         * if ((QuickStop && grounded) || (!grounded && QuickStopAIR))
         * {
         *  _rigid.velocity = new Vector2(0, _rigid.velocity.y);
         * }*/

        if (grounded || AirControl)
        {
            Vector2 movement = new Vector2((_rigid.velocity.x < 0? Vector2.left.x : (_rigid.velocity.x > 0? Vector2.right.x : 0)) * MoveSpeed, _rigid.velocity.y);
            //if (Input.GetKey(controls == Controls.WASD ? KeyCode.A : KeyCode.LeftArrow)  || InputManager.GetAxis("Horizontal", playerID) < 0)
            if (input.xAxis < 0)
            {
                movement.x     = Vector2.left.x * MoveSpeed;
                LastMovedRight = false;
            }
            if (input.xAxis > 0)
            {
                movement.x     = Vector2.right.x * MoveSpeed;
                LastMovedRight = true;
            }
            if (input.xAxis == 0)
            {
                movement.x = 0;
            }

            _rigid.velocity = movement;
        }


        if (input.JumpUp || (!grounded && _rigid.velocity.y < 0.1f && _rigid.velocity.y > -0.1f))
        {
            _isJumping  = false;
            holdingJump = false;
            // _rigid.AddForce(Vector2.down * JumpENDForceDown);
            //_rigid.gravityScale = 1.0f;
        }


        if (input.JumpDown || input.Jump)
        {
            if (!_isJumping && (grounded || MultipleJumps))
            {
                jumpTimer   = HoldJumpMaxSec;
                _isJumping  = true;
                holdingJump = true;
                SAnimation.PlayAnimation("Jump", Pcolor, false, 5, 2, 0);
                SAnimation.SetFrame(2);
                //_currentJumpForce = (Physics.gravity * _rigid.mass).magnitude * 5f;
                _rigid.AddForce(Vector2.up * JumpForce);
                //ScoreManager.gameData.Jumped++;
            }
        }

        /*
         * if (input.Jump && _isJumping) holdingJump = true;
         * else holdingJump = false;
         */
    }