// Start is called before the first frame update void Start() { groundColor = Color.white; prevPowerColor = PowerColor.WHITE; powerColor = PowerColor.WHITE; greenAudio = transform.Find("Sounds").Find("Green").gameObject.GetComponent <FadingAudioSource>(); }
public static string GetCamelCaseName(PowerColor color) { string LowerSelfName = System.Enum.GetName(typeof(PowerColor), color).ToLower(); char[] buffer = LowerSelfName.ToCharArray(); buffer[0] = char.ToUpper(buffer[0]); return(new string(buffer)); }
public static bool IsOn(PowerColor color) { if (!States.ContainsKey(color)) { return(false); } else { return(States[color]); } }
public static void SetState(PowerColor color, bool state) { if (!States.ContainsKey(color)) { States.Add(color, state); } else { States[color] = state; } }
public void PreviousPower() { LinkPowerColors temp = GetComponent <LinkPowerColors>(); if (powerIndex > 0) { powerIndex--; } else { powerIndex = temp.powers.Length - 1; } currentPower = temp.powers[powerIndex]; main.color = currentPower.main; gems.color = currentPower.gems; }
//Power stuff public void NextPower() { LinkPowerColors temp = GetComponent <LinkPowerColors>(); if (powerIndex < temp.powers.Length - 1) { powerIndex++; } else { powerIndex = 0; } currentPower = temp.powers[powerIndex]; main.color = currentPower.main; gems.color = currentPower.gems; }
// Update is called once per frame public void UpdatePowerColor(bool isShadowed) { // Remember for next frame prevPowerColor = powerColor; groundColor = MeasureGroundColor(); if (isShadowed) { // No powers for you if you're in the dark powerColor = PowerColor.WHITE; } else { powerColor = CalculatePowerColor(); } return; }
public void SetupColor() { PowerColor setCol = null; foreach (var col in powerColors) { if (PowerUpStrength > col.powerRate) { setCol = col; } else { break; } } if (setCol != null) { lineRender.material.color = setCol.color; } }
private bool ActivatePower(PowerColor color, int index) { int powerIndex = -1; for (int i = 0; i < activePowers.Length; ++i) { if (activePowers[i] == null) { powerIndex = i; break; } } if (powerIndex < 0) { return(false); } switch (color) { case PowerColor.Red: if (index < redPowers.Length) { var powerObj = Object.Instantiate(redPowers[index]); var power = powerObj.GetComponent <PlayerPower>(); power.Activate(this); activePowers[powerIndex] = power; return(true); } break; case PowerColor.Blue: if (index < bluePowers.Length) { var powerObj = Object.Instantiate(bluePowers[index]); var power = powerObj.GetComponent <PlayerPower>(); power.Activate(this); activePowers[powerIndex] = power; return(true); } break; case PowerColor.Yellow: if (index < yellowPowers.Length) { var powerObj = Object.Instantiate(yellowPowers[index]); var power = powerObj.GetComponent <PlayerPower>(); power.Activate(this); activePowers[powerIndex] = power; return(true); } break; case PowerColor.Green: if (index < greenPowers.Length) { var powerObj = Object.Instantiate(greenPowers[index]); var power = powerObj.GetComponent <PlayerPower>(); power.Activate(this); activePowers[powerIndex] = power; return(true); } break; case PowerColor.Wild: if (index < wildPowers.Length) { var powerObj = Object.Instantiate(wildPowers[index]); var power = powerObj.GetComponent <PlayerPower>(); power.Activate(this); activePowers[powerIndex] = power; return(true); } break; } return(false); }
// Update is called once per frame void Update() { // Update color the player is stading on (reads from ColorCheck.cs) powerColor = gameObject.GetComponent <ColorCheck>().powerColor; groundColor = gameObject.GetComponent <ColorCheck>().groundColor; // Ground Check Vector3 sphere_position = transform.position + Vector3.down * (controller.height * .5f - controller.radius); float sphere_radius = controller.radius + groundDistance; isGrounded = Physics.CheckSphere(sphere_position, sphere_radius, groundMask); // Check for black color if (isGrounded && (groundColor.grayscale < 0.1) && (Time.timeSinceLevelLoad > .5)) { alive = false; death.TriggerDeath(); } else { // All is well with the world alive = true; } // When the detected color is blue for the first time, bounce back. if ((powerColor == PowerColor.BLUE) && (prevPowerColor != PowerColor.BLUE)) { // TODO detecter le gradient de bleu et appliquer la force en direction opposee velocity = -velocity.normalized * Math.Max(30, velocity.magnitude); if (!isGrounded) { velocity.y = Math.Max(jumpSpeed, velocity.y); } else { velocity.y = jumpSpeed / 2; } } else { // Lateral mouvement if (isGrounded && (powerColor != PowerColor.CYAN)) { float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertical"); float actualMaxSpeed = (powerColor == PowerColor.GREEN) ? maxLateralSpeed * 3 : maxLateralSpeed; float actualAcceleration = lateralAcceleration; // Calculate velocity increase Vector3 lateralVelocity = new Vector3(velocity.x, 0f, velocity.z); Vector3 newSpeed = lateralVelocity + (actualAcceleration * Time.deltaTime * (transform.right * x + transform.forward * z)); // Apply increase to x and z while making sure they don't go over the max speed if (newSpeed.magnitude <= actualMaxSpeed) { velocity.x = newSpeed.x; velocity.z = newSpeed.z; } } // Jump if (isGrounded) { if ((powerColor == PowerColor.YELLOW) && (velocity.y < -3f)) { velocity.y = -velocity.y; } else { velocity.y = 0; } } if (Input.GetButtonDown("Jump") && isGrounded) { velocity.y = (powerColor == PowerColor.YELLOW) ? jumpSpeed * 3 : jumpSpeed; } } // Lateral Friction if (isGrounded && (powerColor != PowerColor.CYAN)) { // Friction en sqrt pour permettre aux grandes vitesses de rester plus longtemps // Tres important pour la dynamique entre la couleur high speed et la couleur jump velocity.x -= lateralFriction * Math.Sign(velocity.x) * (float)Math.Sqrt(Math.Abs(velocity.x)); velocity.z -= lateralFriction * Math.Sign(velocity.z) * (float)Math.Sqrt(Math.Abs(velocity.z)); } // Gravity velocity.y += verticalAcceleration * Time.deltaTime; // Update controller controller.Move(velocity * Time.deltaTime); // Remember power color for next frame prevPowerColor = powerColor; }
public Color PowerColorToColor(PowerColor pc) { return(colorArray[(int)pc]); }