예제 #1
0
 // Use this for initialization
 public void ActualizeEquation(string newEquationString)
 {
     if (this.equationString != newEquationString)
     {
         GameManager.GetCurrentCharacter().GetComponent <EquationScriptComponent>().OnStringChange(newEquationString);
         try
         {
             equation = new Text2AST.Equation(newEquationString, variables);
             List <Vector3> newlyCreatedTrajectory = new List <Vector3>();
             float          offset = (float)equation.With("x", 0).GetValue();
             for (double x = 0; x < 30; x += 0.1)
             {
                 newlyCreatedTrajectory.Add(new Vector3((float)x, (float)equation.With("x", x).GetValue() - offset, 49));
             }
             createdTrajectory = newlyCreatedTrajectory;
         }
         catch (Text2AST.WrongEquationException)
         {
             Debug.Log("Wrong written equation");
             equation = null;
         }
         catch (Text2AST.BadDefinedException)
         {
             Debug.Log("Bad defined equation");
             equation = null;
         }
         catch (System.Exception ex)
         {
             Debug.Log("Unknown exception");
             Debug.Log(ex.Message);
             equation = null;
         }
         equationString = newEquationString;
     }
 }
예제 #2
0
 public static void AddProjectile(Vector3 initLocation, Text2AST.Equation equation, bool isFacingRight, float power)
 {
     if (instance.gameObject.GetComponent <ProjectileLogic>() == null)
     {
         instance.projectile = instance.gameObject.AddComponent <ProjectileLogic>();
         instance.projectile.AddData(initLocation, equation, isFacingRight, power, () => instance.DestroyLogicAndDontFly());
     }
 }
예제 #3
0
 public void AddData(Vector3 initLocation, Text2AST.Equation equation, bool looksRight, float power, System.Action toDestroy)
 {
     this.initLocation = initLocation;
     this.lastLocation = initLocation;
     this.equation     = equation;
     lastX             = 0.0f;
     // initDX = 0.5f * (looksRight ? 1 : -1);
     offsetY        = new Vector3(0, GetY(lastX));
     initDX         = 0.5f;
     isRight        = looksRight ? 1 : -1;
     goDestroy      = true;
     this.toDestroy = toDestroy;
     TTL            = dontHitTTL;
     state          = State.DontHitYourself;
     this.power     = power;
     explosionTTL   = power2explosionTTL * (int)power;
 }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("enter pressed");
            GameObject currentCharacter = GameManager.instance.currentCharacter;
            if (GameManager.GetPlayerMode() != PlayerMode.SHOOTING)
            {
                return;
            }

            Text2AST.Equation equation = EquationScript.instance.equation;
            if (equation != null)
            {
                AddProjectile(
                    currentCharacter.GetComponent <Transform>().position,
                    equation,
                    currentCharacter.GetComponent <PlatformerCharacter2D>().m_FacingRight,
                    currentCharacter.GetComponent <StaminaComponent>().value / 2.0f);

                currentCharacter.GetComponent <StaminaComponent>().Set(0);
            }
        }
    }