Beispiel #1
0
    void Update()
    {
        SpartanController controller = GetComponent <SpartanController>();

        if (timeSinceDamaged > shieldRechargeDelay && shield < maxShield)
        {
            shield += shieldRechargeRate * Time.deltaTime;

            if (shield > maxShield)
            {
                shield = maxShield;
            }

            controller.shieldModel.active = true;
        }
        else
        {
            float timeSinceShieldDamaged = Time.time - shieldDamagedTime;
            if (timeSinceShieldDamaged < 0.1f)
            {
                controller.shieldModel.active = true;
            }
            else
            {
                controller.shieldModel.active = false;
            }
        }

        timeSinceDamaged += Time.deltaTime;
    }
Beispiel #2
0
    // Update is called once per frame
    // @NOTE: we do late update because we dont want to kill any players before they got a chance to run
    // there normal update!
    void LateUpdate()
    {
        SpartanController player = this.GetComponent <SpartanController>();

        if (health <= 0 && !dead)
        {
            dead     = true;
            timeDied = Time.time;

            player.KillSpartan();

            Debug.Log("player " + player.localPlayerNum);

            // @TODO: kill player. Its weird tho, do we destroy the instance of that player, or just
            // change some stuff about it? Drop equipment, reset health, change position?
        }
    }
Beispiel #3
0
    // @GACK: maybe put these in a struct
    public void DamagePlayer(int healthDamage, int shieldDamage, bool headshot, float headshotMultiplier)
    {
        SpartanController controller = GetComponent <SpartanController>();

        if (shield > 0)
        {
            if (headshot)
            {
                shield -= shieldDamage * headshotMultiplier;
            }
            else
            {
                shield -= shieldDamage;
            }

            shieldDamagedTime = Time.time;
        }

        if (shield <= 0)
        {
            int overflowShieldDamage = (int)Mathf.Abs(shield);

            // @GAME @TODO: this may need some balancing!!!!!
            // if (overflowShieldDamage > 0) {
            //     Debug.Log(overflowShieldDamage);
            //     healthDamage = overflowShieldDamage;
            // }

            if (headshot)
            {
                health -= healthDamage * headshotMultiplier;
            }
            else
            {
                health -= healthDamage;
            }
        }

        timeSinceDamaged = 0.0f;

        if (shield < 0)
        {
            shield = 0;
        }
    }
Beispiel #4
0
    // @TODO: do health nubs instead of a bar because its a bit clearer
    // @PERF: setting this every frame is probably wasteful, we could instead just call UI functions when needed
    void Update()
    {
        RectTransform shieldMaskRect = shieldMask.GetComponent <RectTransform>();
        RectTransform healthMaskRect = healthMask.GetComponent <RectTransform>();
        RectTransform heatMaskRect   = heatMask.GetComponent <RectTransform>();


        Health health = player.GetComponent <Health>();

        // @NOTE: we cant modify the width directly, so we do this
        shieldMaskRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, health.NormalizedShield() * maxShieldMaskWidth);
        healthMaskRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, health.NormalizedHealth() * maxHealthMaskWidth);


        Text text = ammoCount.GetComponent <Text>();
        SpartanController controller = player.GetComponent <SpartanController>();
        GameObject        activeGun  = controller.GetActiveWeapon();

        if (activeGun != null)
        {
            Gun gun = activeGun.GetComponent <Gun>();

            if (gun.ammoType == AmmoType.Plasma)
            {
                heatMaskRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, gun.GetHeat() * maxHeatMaskWidth);
                // do a thing with the overheat bar
                text.text = string.Format("{0} \\\\\\ 0", gun.ammoInClip);
            }
            else
            {
                heatMaskRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
                text.text = string.Format("{0} \\\\\\ {1}", gun.ammoInClip, gun.ammoCount);
            }
        }
        else
        {
            text.text = string.Format("0 \\\\\\ 0");
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        foreach (GameObject player in players)
        {
            SpartanController controller = player.GetComponent <SpartanController>();

            Health health = player.GetComponent <Health>();

            if (health.dead)
            {
                float timeSinceDied = Time.time - health.timeDied;

                Transform bestSpawn = FindSpawnPoint();
                // @TODO: find a spawn point!!!!
                if (timeSinceDied >= respawnRate)
                {
                    wpnSpawner0.SpawnWeapon();
                    wpnSpawner1.SpawnWeapon();
                    controller.SpawnSpartan(bestSpawn.position, bestSpawn.rotation, wpnSpawner0.lastWeaponSpawned, wpnSpawner1.lastWeaponSpawned);
                }
            }
        }
    }
Beispiel #6
0
    // Use this for initialization
    void Start()
    {
        // @TODO: really what we want to do is create the players rather than find them in the scene!!!

        wpnSpawner0 = weaponSpawner0.GetComponent <WeaponSpawn>();
        wpnSpawner1 = weaponSpawner1.GetComponent <WeaponSpawn>();

        players = new GameObject[localPlayerCount];

        for (int i = 0; i < localPlayerCount; i++)
        {
            GameObject        player     = Instantiate(playerPrefab, new Vector3(0, i * 6, i * 4), Quaternion.identity);
            SpartanController controller = player.GetComponent <SpartanController>();
            controller.localPlayerNum = i;
            players[i] = player;
        }

        foreach (GameObject player in players)
        {
            SpartanController controller = player.GetComponent <SpartanController>();

            Transform bestSpawn = FindSpawnPoint();

            wpnSpawner0.SpawnWeapon();
            wpnSpawner1.SpawnWeapon();
            controller.SpawnSpartan(bestSpawn.position, bestSpawn.rotation, wpnSpawner0.lastWeaponSpawned, wpnSpawner1.lastWeaponSpawned);

            Camera cam = controller.camera.GetComponent <Camera>();

            SpartanUI ui = controller.canvas.GetComponent <SpartanUI>();
            ui.uiScale = 1.0f / localPlayerCount;

            if (localPlayerCount == 1)
            {
                Rect rect = new Rect(0, 0, 1, 1);
                cam.rect = rect;
            }
            else if (localPlayerCount == 2)
            {
                Rect rect = new Rect();
                rect.x      = 0;
                rect.y      = controller.localPlayerNum * 0.5f;
                rect.width  = 1;
                rect.height = 0.5f;

                cam.rect = rect;
            }
            else if (localPlayerCount == 3)
            {
                Rect rect = new Rect();

                if (controller.localPlayerNum == 0)
                {
                    rect.x      = 1;
                    rect.y      = 0;
                    rect.width  = 1;
                    rect.height = 0.5f;
                }
                else
                {
                    rect.x      = controller.localPlayerNum * 0.5f;
                    rect.y      = controller.localPlayerNum * 0.5f;
                    rect.width  = 0.5f;
                    rect.height = 0.5f;
                }

                cam.rect = rect;
            }
            else
            {
                Rect rect = new Rect();

                rect.x      = (controller.localPlayerNum % 2) * 0.5f;
                rect.y      = (controller.localPlayerNum / 2) * 0.5f;
                rect.width  = 0.5f;
                rect.height = 0.5f;

                cam.rect = rect;
            }
        }
    }