コード例 #1
0
ファイル: Player.cs プロジェクト: avkisovec/ColdMustache
    // Update is called once per frame
    void Update()
    {
        if (UniversalReference.MouseScreenPosDelta != new Vector2(0, 0))
        {
            if (ActivelyAiming)
            {
                gunRotatorHand.AimGun(UniversalReference.MouseWorldPos);
            }
            else
            {
                gunRotatorHand.HoldGun(UniversalReference.MouseWorldPos);
            }
        }

        Vector2 MouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        entity.LookingToward = MouseWorldPos;

        //true if looking right, false if looking left
        bool LookingRight = entity.LookingToward.x > transform.position.x;


        //decreasing active cooldowns
        if (CurrShootingWindDownDuration > 0)
        {
            //when decreasing cooldowns, always use Time.deltaTime (the time it took to render last frame, in seconds) - framerate independent
            CurrShootingWindDownDuration -= Time.deltaTime;
        }
        if (CurrShootingCooldown > 0)
        {
            CurrShootingCooldown -= Time.deltaTime;
        }


        //inaccuracy
        Inaccuracy += UniversalReference.PlayerRb.velocity.magnitude / 30;

        //inaccuracy starts decreasing only when it has not increased
        if (Inaccuracy <= InaccuracyInLastFrame && InaccuracyRecoveryBlock <= 0)
        {
            if (Inaccuracy > InaccuracyMin)
            {
                Inaccuracy -= Time.deltaTime * InaccuracyRecoveryFactor; //decreased by 1 every second (can be different for balance purposes)
            }
        }

        if (InaccuracyRecoveryBlock > 0)
        {
            InaccuracyRecoveryBlock -= Time.deltaTime;
        }

        if (Inaccuracy > InaccuracyMax)
        {
            Inaccuracy = InaccuracyMax;
        }
        if (Inaccuracy < InaccuracyMin)
        {
            Inaccuracy = InaccuracyMin;
        }

        InaccuracyInLastFrame = Inaccuracy;

        /*
         *
         * //when not firing/aiming, hold the gun in resting position
         * if(Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1) || CurrShootingWindDownDuration > 0)
         * {
         *  smg.ActivelyAiming = true;
         * }
         * else
         * {
         *  smg.ActivelyAiming = false;
         * }
         *
         */

        #region  Movement

        //movement vector will hold information about direction, speed is added after, in Entity script
        //you cannot walk when mouse is dragging a window, that causes problems (though MovementVector has to be set to 0 stop previous movement)
        Vector2 MovementVector = new Vector2(0, 0);
        if (MouseInterceptor.IsMouseAvailable())
        {
            if (Input.GetKey(KeybindManager.MoveUp))
            {
                MovementVector += new Vector2(0, 1);
                LegsManager.RequestRunUp(LookingRight);
            }
            if (Input.GetKey(KeybindManager.MoveDown))
            {
                MovementVector += new Vector2(0, -1);
                LegsManager.RequestRunDown(LookingRight);
            }
            if (Input.GetKey(KeybindManager.MoveLeft))
            {
                MovementVector += new Vector2(-1, 0);
                LegsManager.RequestRunLeft(LookingRight);
            }
            if (Input.GetKey(KeybindManager.MoveRight))
            {
                MovementVector += new Vector2(1, 0);
                LegsManager.RequestRunRight(LookingRight);
            }
            entity.MoveInDirection(MovementVector);
        }

        if (MovementVector.x < 0.01f && MovementVector.x > -0.01f && MovementVector.y < 0.01f && MovementVector.y > -0.01f)
        {
            LegsManager.RequestIdle(entity.LookingToward);
        }

        #endregion


        float HealthRatio = entity.Health / entity.MaxHealth;
        if (HealthRatio < 0.5f)
        {
            LowHealthOverlay.color = new Color(LowHealthOverlay.color.r, LowHealthOverlay.color.g, LowHealthOverlay.color.b,
                                               (0.5f - HealthRatio) * 0.85f
                                               );
        }
        else
        {
            LowHealthOverlay.color = new Color(LowHealthOverlay.color.r, LowHealthOverlay.color.g, LowHealthOverlay.color.b, 0);
        }

        #region StuffForTestingPurposes

        if (Input.GetKeyDown(KeyCode.F10))
        {
            //export navmap as text

            //hard path means Drive:/path - the complete path, not relative to application directory
            NavTestStatic.ExportNavMap();

            Debug.Log("hi");
        }

        if (Input.GetKeyUp(KeyCode.T))
        {
            AlphabetManager.SpawnFloatingText("Hi!", new Vector3(transform.position.x, transform.position.y, -35));
        }

        if (Input.GetKey(KeyCode.P))
        {
            SpamParticlesToFuckWithFramerate();
        }
        if (Input.GetKey(KeyCode.O))
        {
            SpamOptimisedParticlesToFuckWithFramerate();
        }
        if (Input.GetKey(KeyCode.I))
        {
            SpamListParticlesToFuckWithFramerate();
        }


        #endregion

        #region CheatCodes

        if (CheatManager.LastCheat == "GODMODE" || CheatManager.LastCheat == "GM")
        {
            entity.MaxHealth     = float.MaxValue;
            entity.Health        = float.MaxValue;
            entity.BaseMoveSpeed = 25;
        }

        if (CheatManager.LastCheat == "NUKE")
        {
            //ExplosionFrag.SpawnOriginal(Util.Vector3To2Int(transform.position), 100, 10);
            ExplosionFrag.SpawnOriginal(Util.Vector3To2Int(transform.position), 100);
        }

        if (CheatManager.LastCheat == "KILLALL" || CheatManager.LastCheat == "KA")
        {
            foreach (Entity e in GameObject.FindObjectsOfType <Entity>())
            {
                if (e.Team == Entity.team.Enemy)
                {
                    Destroy(e.gameObject);
                }
            }
        }

        if (CheatManager.LastCheat == "NAVDRAW") // Nav Draw
        {
            for (int x = 0; x < NavTestStatic.MapWidth; x++)
            {
                for (int y = 0; y < NavTestStatic.MapHeight; y++)
                {
                    if (!NavTestStatic.IsTileWalkable(x, y))
                    {
                        GameObject go = new GameObject();
                        go.transform.position = new Vector3(x, y, -10);
                        go.AddComponent <SpriteRenderer>().sprite = UniversalReference.Pixel;
                        go.GetComponent <SpriteRenderer>().color  = new Color(1, 0, 0, 0.6f);
                    }
                }
            }
        }

        if (CheatManager.LastCheat == "NAVDRAWLIGHT") // Nav Draw Light
        {
            for (int x = 0; x < NavTestStatic.MapWidth; x++)
            {
                for (int y = 0; y < NavTestStatic.MapHeight; y++)
                {
                    if (!NavTestStatic.CanLightPassThroughTile(x, y))
                    {
                        GameObject go = new GameObject();
                        go.transform.position = new Vector3(x, y, -10);
                        go.AddComponent <SpriteRenderer>().sprite = UniversalReference.Pixel;
                        go.GetComponent <SpriteRenderer>().color  = new Color(1, 1, 0, 0.6f);
                    }
                }
            }
        }

        if (CheatManager.LastCheat == "NAVDRAWEXPLOSION") // Nav Draw Explosion
        {
            for (int x = 0; x < NavTestStatic.MapWidth; x++)
            {
                for (int y = 0; y < NavTestStatic.MapHeight; y++)
                {
                    if (!NavTestStatic.CanExplosionPassThroughTile(new Vector2Int(x, y)))
                    {
                        GameObject go = new GameObject();
                        go.transform.position = new Vector3(x, y, -10);
                        go.AddComponent <SpriteRenderer>().sprite = UniversalReference.Pixel;
                        go.GetComponent <SpriteRenderer>().color  = new Color(1, 0.5f, 0, 0.6f);
                    }
                }
            }
        }


        //deals 10 000 damage to every enemy entity
        if (CheatManager.LastCheat == "KARTHUS") // Karthus
        {
            foreach (Entity e in GameObject.FindObjectsOfType <Entity>())
            {
                if (e.Team == Entity.team.Enemy)
                {
                    e.TakeDamage(10000, DamagerInflicter.WeaponTypes.Undefined);
                }
            }
        }


        //sets every enemy entity's base movespeed to 0
        if (CheatManager.LastCheat == "FREEZE") // Freeze
        {
            foreach (Entity e in GameObject.FindObjectsOfType <Entity>())
            {
                if (e.Team == Entity.team.Enemy)
                {
                    e.BaseMoveSpeed = 0;
                }
            }
        }


        //sets every enemy entity's team to player
        if (CheatManager.LastCheat == "CHARM") // Charm
        {
            foreach (Entity e in GameObject.FindObjectsOfType <Entity>())
            {
                if (e.Team == Entity.team.Enemy)
                {
                    e.Team = Entity.team.Player;
                }
            }
        }

        //teleport player to cursor location
        if (CheatManager.LastCheat == "TP") // Tp (teleport)
        {
            Vector2 Target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            transform.position = new Vector3(Target.x, Target.y, 0);
        }


        //deals 10 000 damage to every environment object
        if (CheatManager.LastCheat == "EARTHQUAKE") // Earthquake
        {
            //not doing this with simple foreach as something messes with the collection, i think its the wallsegments or something
            //EDIT: the problem still exists, only +- 90% of walls are destroyed, some remain, and can be destroyed by weapons, but not with this

            EnvironmentObject[] e = GameObject.FindObjectsOfType <EnvironmentObject>();
            int limit             = e.Length;

            for (int i = 0; i < limit; i++)
            {
                if (e[i] != null)
                {
                    e[i].TakeDamage(10000);
                }
            }
        }



        #endregion

        #region Input

        if (Input.GetKeyDown(KeybindManager.UseItem))
        {
            if (CurrentlyEquippedItem != null)
            {
                CurrentlyEquippedItem.DoYourThing();
            }
        }

        if (Input.GetKeyUp(KeyCode.F5))
        {
            SaverLoader.QuickSave(spriteManagerHand);
        }

        //quickload
        if (Input.GetKeyUp(KeyCode.F6))
        {
            SaverLoader.QuickLoad(spriteManagerHand);

            //Debug.Log("Quickload Complete.");
        }

        if (Input.GetKey(KeybindManager.MousePrimary) && MouseInterceptor.IsMouseAvailable())
        {
            CurrentlyEquippedWeapon.TryShooting(MouseWorldPos);
        }
        if (Input.GetKey(KeybindManager.AltFire))
        {
            CurrentlyEquippedWeapon.TryAltFire();
            CurrentlyEquippedWeapon.TryAltFire(MouseWorldPos);
        }
        if (Input.GetKey(KeybindManager.Reload))
        {
            CurrentlyEquippedWeapon.ForceReload();
        }

        #endregion
    }