Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (healthComponent == null)
        {
            Spaceship ship = GameplayManager.spaceship;
            if (ship != null)
            {
                healthComponent = ship.GetComponent <SpaceshipHealth>();
            }
        }
        else
        {
            currentScale.x            = healthComponent.currentHealth / healthComponent.maxHealth * initialScale.x;
            this.transform.localScale = currentScale;

            switch (healthComponent.state)
            {
            case HealthState.HEALTHY:
                healthbarSprite.color = healthyColor;
                break;

            case HealthState.INJURED:
                healthbarSprite.color = injuredColor;
                break;

            case HealthState.CRITICAL:
                healthbarSprite.color = criticalColor;
                break;

            default:
                throw new Exception("Unknown health state: " + healthComponent.state);
            }
        }
    }
Пример #2
0
    public override void OnPickup(Spaceship spaceship)
    {
        base.OnPickup(spaceship);
        SpaceshipHealth health = spaceship.GetComponent <SpaceshipHealth>();

        health.currentHealth = Mathf.Min(health.currentHealth + healthAmount, health.maxHealth);
    }
Пример #3
0
	// Update is called once per frame
	void Update () {

		if (healthComponent == null) {
			Spaceship ship = GameplayManager.spaceship;
			if (ship != null) {
				healthComponent = ship.GetComponent<SpaceshipHealth>();
			}
		}
		else {
			currentScale.x = healthComponent.currentHealth/healthComponent.maxHealth * initialScale.x;
			this.transform.localScale = currentScale;
	
			switch (healthComponent.state) {
				case HealthState.HEALTHY:
					healthbarSprite.color = healthyColor;
					break;
				case HealthState.INJURED:
					healthbarSprite.color = injuredColor;
					break;
				case HealthState.CRITICAL:
					healthbarSprite.color = criticalColor;
					break;
				default:
					throw new Exception("Unknown health state: " + healthComponent.state);
			}
		}
	}
Пример #4
0
    public void Awake()
    {
        //Procura o componente do Player declarado
        healthManager = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceshipHealth>();

        //Ativa a destruição do objeto dentro de seu tempo de vida
        Destroy(gameObject, this.timeToDestruct);
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (matchData == null)
        {
            Spaceship ship = GameplayManager.spaceship;

            if (ship != null)
            {
                matchData       = GameplayManager.spaceship.GetComponent <SpaceshipMatchData>();
                spaceshipHealth = GameplayManager.spaceship.GetComponent <SpaceshipHealth>();
            }
        }
        else
        {
            if (matchData.spawnTimeRemaining > 1.0f)
            {
                if (matchData.lastKilledBy == matchData.spaceship.gameObject)
                {
                    label.text = string.Format("Suicide!\nRespawning in {0}...", (int)matchData.spawnTimeRemaining);
                }
                else
                {
                    label.text = string.Format("{0} {1} by Player {2}!\nRespawning in {3}...", currentDeathAdjective, currentDeathVerb, (spaceshipHealth.lastHurtByPlayerID + 1), (int)matchData.spawnTimeRemaining);
                }
            }
            else if (matchData.spawnTimeRemaining > 0.0f)
            {
                label.text = string.Format("Preparing for descent...");
                UpdateDeathWords();
            }
            else if (MatchManager.lastKilledPlayerId != -1)
            {
                if (MatchManager.lastKilledPlayerIdLastFrame != MatchManager.lastKilledPlayerId)
                {
                    UpdateDeathWords();
                }
                label.text = string.Format("{0} {1} Player {2}!", currentDeathAdjective, currentDeathVerb, (MatchManager.lastKilledPlayerId + 1));
            }
            else
            {
                label.text = "";
            }
        }
    }
Пример #6
0
    private static IEnumerator HandleSpawnWait(Spaceship spaceship)
    {
        SpaceshipMatchData matchData = spaceship.GetComponent <SpaceshipMatchData>();
        SpaceshipControl   controls  = spaceship.GetComponent <SpaceshipControl>();
        Collider           collider  = spaceship.GetComponent <Collider>();

        matchData.spawnTimeRemaining = normalSpawnWait;

        spaceship.isVisible       = false;
        spaceship.controlsEnabled = false;

//		instance.networkView.RPC("SetVisibility", RPCMode.All, false);

//		spaceship.spaceshipModelRoot.gameObject.SetActive(instance.isVisible);
//		controls.enabled = instance.isVisible;
//		collider.enabled = instance.isVisible;

        while (matchData.spawnTimeRemaining > 0.0f)
        {
            yield return(null);

            matchData.spawnTimeRemaining = Mathf.Max(0.0f, matchData.spawnTimeRemaining - Time.deltaTime);
        }

        spaceship.transform.position = spawnPoints[lastCheckpointID].transform.position;
        spaceship.transform.rotation = spawnPoints[lastCheckpointID].transform.rotation;

//		instance.networkView.RPC("SetVisibility", RPCMode.All, true);

//		spaceship.spaceshipModelRoot.gameObject.SetActive(instance.isVisible);
//		controls.enabled = instance.isVisible;
//		collider.enabled = instance.isVisible;
        SpaceshipHealth healthComponent = spaceship.GetComponent <SpaceshipHealth>();

        healthComponent.currentHealth = healthComponent.maxHealth;
        spaceship.isVisible           = true;
        spaceship.controlsEnabled     = true;

        Debug.Log("Spawning '" + spaceship + "' at SpawnPoint " + lastCheckpointID + "!");
    }
Пример #7
0
	// Update is called once per frame
	void Update () {

		if (matchData == null) {
			Spaceship ship = GameplayManager.spaceship;
			
			if (ship != null) {
				matchData = GameplayManager.spaceship.GetComponent<SpaceshipMatchData>();
				spaceshipHealth = GameplayManager.spaceship.GetComponent<SpaceshipHealth>();
			}
		}
		else {
			if (matchData.spawnTimeRemaining > 1.0f) { 
				if (matchData.lastKilledBy == matchData.spaceship.gameObject) {
					label.text = string.Format("Suicide!\nRespawning in {0}...", (int)matchData.spawnTimeRemaining);
				}
				else {
					label.text = string.Format("{0} {1} by Player {2}!\nRespawning in {3}...", currentDeathAdjective, currentDeathVerb, (spaceshipHealth.lastHurtByPlayerID+1), (int)matchData.spawnTimeRemaining); 
				}
			}
			else if (matchData.spawnTimeRemaining > 0.0f) {
				label.text = string.Format("Preparing for descent..."); 
				UpdateDeathWords();
			}
			else if (MatchManager.lastKilledPlayerId != -1) {
				if (MatchManager.lastKilledPlayerIdLastFrame != MatchManager.lastKilledPlayerId) {
					UpdateDeathWords();
				}
				label.text = string.Format("{0} {1} Player {2}!", currentDeathAdjective, currentDeathVerb, (MatchManager.lastKilledPlayerId+1));
			}
			else {
				label.text = "";
			}
		}
	}
Пример #8
0
    // Update is called once per frame
    void Update()
    {
        if (spaceship == null)
        {
            Spaceship ship = GameplayManager.spaceship;
            if (ship != null)
            {
                spaceship = ship.GetComponent <Spaceship>();
                health    = ship.GetComponent <SpaceshipHealth>();
            }
        }
        else
        {
            for (int i = 0; i < indicatorSprites.Length; ++i)
            {
                indicatorSprites[i].enabled = false;
            }

            GameObject [] spaceships   = GameObject.FindGameObjectsWithTag("Spaceship");
            Vector3       screenCenter = new Vector3(Screen.width, Screen.height, 0.0f) * 0.5f;
            int           j            = 0;

            for (int i = 0; i < spaceships.Length; ++i)
            {
                Spaceship ship = spaceships[i].GetComponent <Spaceship>();
                if (ship == spaceship)
                {
                    continue;
                }
                Vector3 screenPosition = spaceship.spaceshipCamera.WorldToScreenPoint(ship.transform.position);

                if (screenPosition.z > 0 &&
                    screenPosition.x > 0 && screenPosition.x < Screen.width &&
                    screenPosition.y > 0 && screenPosition.y < Screen.height)
                {
                    Vector3 newIndicatorPosition = 2.0f * (screenPosition - screenCenter);
                    newIndicatorPosition.z       = 0f;
                    indicatorSprites[j].sprite2D = onScreenSprite;
                    indicatorSprites[j].alpha    = 1.0f;
                    indicatorSprites[j].enabled  = true;
                    indicatorSprites[j].transform.localPosition = newIndicatorPosition;
                }
//				else {
//					Debug.Log (string.Format("Untransformed screenPosition of {0}: {1}", ship.gameObject, screenPosition));
////					screenPosition.z *= -1.0f;
//					float border = 0.9f;
//
//					screenPosition -= screenCenter; // Map screen coords origin to center of screen
//					Debug.Log (string.Format("Transformed to origin screenPosition of {0}: {1}", ship.gameObject, screenPosition));
//
//					float slope = screenPosition.x/screenPosition.y;
//					//y = mx
//					//x = y/m
//					float halfWidth = 0.5f*Screen.width;
//					float halfHeight = 0.5f*Screen.height;
//
//					screenPosition.x = Mathf.Clamp(Screen.height/slope, -border*halfWidth, border*halfWidth);
//					screenPosition.y = Mathf.Clamp(slope*Screen.width, -border*halfHeight, border*halfHeight);
//					Debug.Log (string.Format("Transformed screenPosition of {0} after clamping: {1}", ship.gameObject, screenPosition));
//
//
//					screenPosition += screenCenter;
//					Debug.Log (string.Format("ScreenPosition of {0} after clamping and remapping to screen coordinates: {1}", ship.gameObject, screenPosition));
//
////					Debug.Log(string.Format("Viewport position for {0}: {1}", ship, viewportPosition));
////					screenPosition = spaceship.spaceshipCamera.ViewportToScreenPoint(viewportPosition);
////					Vector3 newIndicatorPosition = 2.0f*(screenPosition-screenCenter);
//					Vector3 newIndicatorPosition = screenPosition;
//					indicatorSprites[j].sprite2D = offScreenSprite;
//					indicatorSprites[j].alpha = 0.75f;
//					indicatorSprites[j].enabled = true;
//					indicatorSprites[j].transform.localPosition = newIndicatorPosition;
//				}

                ++j;
            }
        }
    }
Пример #9
0
	// Update is called once per frame
	void Update () {
		if (spaceship == null) {
			Spaceship ship = GameplayManager.spaceship;
			if (ship != null) {
				spaceship = ship.GetComponent<Spaceship>();
				health = ship.GetComponent<SpaceshipHealth>();
			}
		}
		else {
			for (int i = 0; i < indicatorSprites.Length; ++i) {
				indicatorSprites[i].enabled = false;
			}

			GameObject [] spaceships = GameObject.FindGameObjectsWithTag("Spaceship");
			Vector3 screenCenter = new Vector3(Screen.width, Screen.height, 0.0f)*0.5f;
			int j = 0;

			for (int i = 0; i < spaceships.Length; ++i) {
				Spaceship ship = spaceships[i].GetComponent<Spaceship>();
				if (ship == spaceship) {
					continue;
				}
				Vector3 screenPosition = spaceship.spaceshipCamera.WorldToScreenPoint(ship.transform.position);

				if (screenPosition.z > 0 && 
				    screenPosition.x > 0 && screenPosition.x < Screen.width &&
				    screenPosition.y > 0 && screenPosition.y < Screen.height) {

					Vector3 newIndicatorPosition = 2.0f*(screenPosition-screenCenter);
					newIndicatorPosition.z = 0f;
					indicatorSprites[j].sprite2D = onScreenSprite;
					indicatorSprites[j].alpha = 1.0f;
					indicatorSprites[j].enabled = true;
					indicatorSprites[j].transform.localPosition = newIndicatorPosition;
				}
//				else {
//					Debug.Log (string.Format("Untransformed screenPosition of {0}: {1}", ship.gameObject, screenPosition));
////					screenPosition.z *= -1.0f;
//					float border = 0.9f;
//					
//					screenPosition -= screenCenter; // Map screen coords origin to center of screen
//					Debug.Log (string.Format("Transformed to origin screenPosition of {0}: {1}", ship.gameObject, screenPosition));
//					
//					float slope = screenPosition.x/screenPosition.y;
//					//y = mx
//					//x = y/m
//					float halfWidth = 0.5f*Screen.width;
//					float halfHeight = 0.5f*Screen.height;
//
//					screenPosition.x = Mathf.Clamp(Screen.height/slope, -border*halfWidth, border*halfWidth);
//					screenPosition.y = Mathf.Clamp(slope*Screen.width, -border*halfHeight, border*halfHeight);
//					Debug.Log (string.Format("Transformed screenPosition of {0} after clamping: {1}", ship.gameObject, screenPosition));
//					
//
//					screenPosition += screenCenter;
//					Debug.Log (string.Format("ScreenPosition of {0} after clamping and remapping to screen coordinates: {1}", ship.gameObject, screenPosition));
//					
////					Debug.Log(string.Format("Viewport position for {0}: {1}", ship, viewportPosition));
////					screenPosition = spaceship.spaceshipCamera.ViewportToScreenPoint(viewportPosition);
////					Vector3 newIndicatorPosition = 2.0f*(screenPosition-screenCenter);
//					Vector3 newIndicatorPosition = screenPosition;
//					indicatorSprites[j].sprite2D = offScreenSprite;
//					indicatorSprites[j].alpha = 0.75f;
//					indicatorSprites[j].enabled = true;
//					indicatorSprites[j].transform.localPosition = newIndicatorPosition;
//				}

				++j;
			}

		}
	}