Пример #1
0
    public static StatSave Add(StatSave s)
    {
        StatSave old = null;

        if (File.Exists("stats.json"))
        {
            StreamReader reader = File.OpenText("stats.json");
            string       data   = reader.ReadLine();
            reader.Close();
            old = JsonConvert.DeserializeObject <StatSave>(data);
        }
        else
        {
            old = new StatSave(0, 0, 0);
        }
        old.deathCount += s.deathCount;
        old.winCount   += s.winCount;
        old.gamesCount += s.gamesCount;
        string text = JsonConvert.SerializeObject(old);

        Debug.Log(text);
        StreamWriter stream = File.CreateText("stats.json");

        stream.WriteLine(text);
        stream.Close();
        return(old);
    }
Пример #2
0
    private void Start()
    {
        StatSave stats = StatSave.Add(new StatSave(0, 0, 0));

        wins.text   = "Wins: " + stats.winCount;
        deaths.text = "Deaths: " + stats.deathCount;
        games.text  = "Games: " + stats.gamesCount;
    }
Пример #3
0
    private void Die()
    {
        if (isDead)
        {
            return;
        }
        StatSave statUpdate = new StatSave(1, 0, 0);

        StatSave.Add(statUpdate);
        transform.position = new Vector3(0, -500, 0);
        currentHealth      = maxHealth;
        healthBar.value    = (0.0f + currentHealth) / maxHealth;
        isDead             = true;
        respawnCounter     = respawnTime;
        if (!beaconManager.IsBeaconAlive(color))
        {
            respawnCounter = float.PositiveInfinity;
        }
        respawnScreen.SetActive(true);
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (knockedBack)
        {
            knockbackCounter -= Time.deltaTime;
            if (knockbackCounter <= 0)
            {
                knockedBack = false;
            }
        }
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical   = Input.GetAxisRaw("Vertical");

        string movementType = "walk";
        float  speed        = walkSpeed;

        if (Input.GetKey(KeyCode.LeftShift))
        {
            movementType = "run";
            speed        = runSpeed;
        }

        Vector3 forward = transform.forward * vertical;
        Vector3 right   = transform.right * horizontal;

        Vector3 newVelocity = new Vector3(forward.x + right.x, 0, forward.z + right.z);

        newVelocity.Normalize();

        if (!knockedBack)
        {
            rb.velocity = new Vector3(newVelocity.x * speed, rb.velocity.y, newVelocity.z * speed);
        }



        if (horizontal != 0 || vertical != 0)
        {
            if (anim.GetBool(movementType) != true)
            {
                anim.SetBool(movementType, true);
                sendAnimation(movementType, "true");
            }
            if (anim.GetBool((movementType == "walk") ? "run" : "walk"))
            {
                sendAnimation((movementType == "walk") ? "run" : "walk", "false");
                anim.SetBool((movementType == "walk") ? "run" : "walk", false);
            }
        }
        else
        {
            if (anim.GetBool("run"))
            {
                sendAnimation("run", "false");
                anim.SetBool("run", false);
            }
            if (anim.GetBool("walk"))
            {
                sendAnimation("walk", "false");
                anim.SetBool("walk", false);
            }
        }


        float mouseX = Input.GetAxis("Mouse X");

        originalRotation.y += mouseX * rotateSensitivity;

        transform.rotation = Quaternion.Euler(new Vector3(originalRotation.x, originalRotation.y, originalRotation.z));

        if (Input.GetKeyDown(KeyCode.Space) && canJump)
        {
            rb.AddForce(Vector3.up * jumpStrength);
            canJump = false;
        }

        if (transform.position.y < yMin)
        {
            Die();
        }
        if (currentHealth <= 0)
        {
            Die();
        }
        if (isDead)
        {
            respawnCounter  -= Time.deltaTime;
            respawnText.text = "Respawn in " + Mathf.Round(respawnCounter);
            if (float.IsInfinity(respawnCounter))
            {
                respawnText.text = "You Will Not Respawn";
            }
            if (respawnCounter <= 0)
            {
                isDead = false;
                Respawn();
            }
        }
        if (Input.GetMouseButtonDown(0))
        {
            sound.Play();
            sendAnimation("attack", "trigger");
            anim.SetTrigger("attack");
            attacks[0].run();
        }
        if (Input.GetMouseButtonDown(1))
        {
            sound.Play();
            sendAnimation("stab", "trigger");
            anim.SetTrigger("stab");
            attacks[1].run();
        }
        int winner = beaconManager.GetWinningBeacon();

        if (winner != -1)
        {
            GameObject[] otherPlayers    = GameObject.FindGameObjectsWithTag("Enemy");
            int          amountSurviving = 0;
            foreach (GameObject g in otherPlayers)
            {
                if (g.transform.position.y > -400)
                {
                    amountSurviving++;
                }
            }
            if (transform.position.y > -400)
            {
                amountSurviving++;
            }
            if (amountSurviving <= 1)
            {
                string text = "You Lost";
                if (winner == color)
                {
                    text = "You Won";
                    won  = true;
                    if (!playedEndSound)
                    {
                        win.Play();
                    }
                }
                if (gameObject.transform.position.y > -400)
                {
                    text = "You Won";
                    won  = true;
                    if (!playedEndSound)
                    {
                        win.Play();
                    }
                }
                if (!won && !playedEndSound)
                {
                    lose.Play();
                }
                playedEndSound = true;
                winText.text   = text;
                winScreen.SetActive(true);
                if (!isReturning)
                {
                    isReturning   = true;
                    returnCounter = 3;
                }
            }
        }
        if (isReturning)
        {
            returnCounter  -= Time.deltaTime;
            returnText.text = "Returning To Lobby in " + Mathf.Round(returnCounter);
            if (returnCounter <= 0)
            {
                if (won)
                {
                    NetData n = new NetData("game_over", "");
                    multi.sendData(JsonConvert.SerializeObject(n));
                    StatSave statUpdate1 = new StatSave(0, 1, 0);
                    StatSave.Add(statUpdate1);
                }
                StatSave statUpdate = new StatSave(0, 0, 1);
                StatSave.Add(statUpdate);
                multi.ReturnToLobby();
            }
        }
    }