void OnTriggerEnter2D(Collider2D other) { //When hit by player bullets if (other.tag == "PlayerProjectile") { //When hit by the right bullet if (Stage_Utilities.compareColorsLoose(weakColor, Color.white) || Stage_Utilities.compareColorsLoose(other.GetComponent <SpriteRenderer> ().color, weakColor)) { if (state != STUNNED) { soundController.PlayResponseSound(1); int damage = other.GetComponent <Projectile_Behavior> ().GetPower(); TakeDamage(damage); //Explode if health <= 0 after taking damage if (myHealth <= 0) { Explode(); //Stun if not dead after taking damage } else { //Store the current state to come back to after stun is over prevState = state; //Set stun timer and stun state if (prevState != STUNNED) { timeOfStunned = howLongToStayStunned; state = STUNNED; } } Destroy(other.gameObject); } //Play nasty chord when hit by the wrong bullet } else { soundController.PlayResponseSound(0); } } }
//Change background color according to player's color void ChangeBGColor() { if (!Stage_Utilities.compareColorsLoose(playerSprite.color, Color.red)) { moveBG.GetComponent <SpriteRenderer> ().color = playerSprite.color; //Get the matching color from the dictionary Color matchedColor; colorDict.TryGetValue(new Color(playerSprite.color.r, playerSprite.color.g, playerSprite.color.b, 1f), out matchedColor); matchedColor = new Color(matchedColor.r, matchedColor.g, matchedColor.b, 255); //Color the background with the matching color mySpriteRenderer.color = matchedColor; cam.backgroundColor = matchedColor; } }
// Update is called once per frame void FixedUpdate() { //text color is always the same as player color textColor = GameObject.FindWithTag("Player").GetComponent <SpriteRenderer> ().color; if (!Stage_Utilities.compareColorsLoose(textColor, Color.red)) { myTextMesh.color = new Color(textColor.r, textColor.g, textColor.b, myTextMesh.color.a); } //text fade in and out as player approaches or goes away if (ifIn) { FadeIn(); } else { FadeOut(); } }
bool CheckWinningCondition() { //Get current abilities int currentAbilityNum = myAStack.GetAvailableAbilityNum(); List <Player_Ability> currentAbilityList = myAStack.GetAbilityList(); //Get target abilities Color[] targetAbilities = stage.GetComponent <Stage_WinningCondition> ().GetTargetList(); //See if current abilities match target abilities int collectedTargetNum = 0; for (int i = 0; i < currentAbilityNum; i++) { for (int j = 0; j < targetAbilities.Length; j++) { if (Stage_Utilities.compareColorsLoose(currentAbilityList[i].abilityColor, targetAbilities [j])) { collectedTargetNum += 1; break; } } } if (collectedTargetNum == targetAbilities.Length) { return(true); } else { return(false); } }
//Swtich abilities void SwitchForm() { //Get current ability list and ability number int abilityNum = myAStack.GetAvailableAbilityNum(); List <Player_Ability> abilityList = myAStack.GetAbilityList(); if (Input.GetKeyDown(KeyCode.Z)) { if (abilityNum >= 1) //Only able to use the first ability when ability number is greater than 1 //Switch to the ability if not currently using it { if (!Stage_Utilities.compareColorsLoose(mySpriteRenderer.color, abilityList [0].abilityColor)) { mySpriteRenderer.color = abilityList [0].abilityColor; attackSpriteRenderer.color = abilityList [0].abilityColor; bulletPrefab.GetComponent <SpriteRenderer> ().color = abilityList [0].abilityColor; dustPuff.GetComponent <ParticleSystem> ().startColor = abilityList [0].abilityColor; } else //Switch back to original if currently using it { mySpriteRenderer.color = new Color(1, 1, 1); attackSpriteRenderer.color = new Color(1, 1, 1); bulletPrefab.GetComponent <SpriteRenderer> ().color = new Color(1, 1, 1); dustPuff.GetComponent <ParticleSystem> ().startColor = new Color(1, 1, 1); } } } if (Input.GetKeyDown(KeyCode.X)) { if (abilityNum >= 2) //Only able to use the second ability when ability number is greater than 2 { if (!Stage_Utilities.compareColorsLoose(mySpriteRenderer.color, abilityList [1].abilityColor)) { mySpriteRenderer.color = abilityList [1].abilityColor; attackSpriteRenderer.color = abilityList [1].abilityColor; bulletPrefab.GetComponent <SpriteRenderer> ().color = abilityList [1].abilityColor; dustPuff.GetComponent <ParticleSystem> ().startColor = abilityList [1].abilityColor; } else { mySpriteRenderer.color = new Color(1, 1, 1); attackSpriteRenderer.color = new Color(1, 1, 1); bulletPrefab.GetComponent <SpriteRenderer> ().color = new Color(1, 1, 1); dustPuff.GetComponent <ParticleSystem> ().startColor = new Color(1, 1, 1); } } } if (Input.GetKeyDown(KeyCode.C)) { if (abilityNum >= 3) //Only able to use the third ability when ability number is greater than 3 { if (!Stage_Utilities.compareColorsLoose(mySpriteRenderer.color, abilityList [2].abilityColor)) { mySpriteRenderer.color = abilityList [2].abilityColor; attackSpriteRenderer.color = abilityList [2].abilityColor; bulletPrefab.GetComponent <SpriteRenderer> ().color = abilityList [2].abilityColor; dustPuff.GetComponent <ParticleSystem> ().startColor = abilityList [2].abilityColor; } else { mySpriteRenderer.color = new Color(1, 1, 1); attackSpriteRenderer.color = new Color(1, 1, 1); bulletPrefab.GetComponent <SpriteRenderer> ().color = new Color(1, 1, 1); dustPuff.GetComponent <ParticleSystem> ().startColor = new Color(1, 1, 1); } } } }