示例#1
0
    private bool UpdateThrustAxis()
    {
        // check for rotations
        Quaternion rotation = Quaternion.identity;
        // ship controller will rotate the engine thrust
        bool updated = false;

        if (Input.GetKeyUp(KeyCode.A))
        {
            shipController.Rotate(spinRate, Vector3.forward);
            updated = true;
        }
        else if (Input.GetKeyUp(KeyCode.D))
        {
            shipController.Rotate(-spinRate, Vector3.forward);
            updated = true;
        }
        else if (Input.GetKeyUp(KeyCode.W))
        {
            shipController.Rotate(spinRate, Vector3.right);
            updated = true;
        }
        else if (Input.GetKeyUp(KeyCode.S))
        {
            shipController.Rotate(-spinRate, Vector3.right);
        }
        return(updated);
    }
示例#2
0
    // "Note also that the Input flags are not reset until "Update()",
    // so its suggested you make all the Input Calls in the Update Loop."
    // Do key processing in Update. Means some GE calls happen off stride in
    // FixedUpdate.
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            running = !running;
            GravityEngine.Instance().SetEvolve(running);
        }

        spaceship.Run(running, GravityEngine.Instance().GetPhysicalTime());

        // RF: Have state inner class with update method to segregate?
        switch (state)
        {
        case State.INTERCEPT_SELECTION:
            // check for rotations
            // ship change will trigger a recompute of trajectories, intercepts will only be
            // determinable once this is done
            Quaternion rotation = Quaternion.identity;
            if (Input.GetKey(KeyCode.A))
            {
                spaceship.Rotate(spinRate, Vector3.forward);
            }
            else if (Input.GetKey(KeyCode.D))
            {
                spaceship.Rotate(-spinRate, Vector3.forward);
            }
            else if (Input.GetKey(KeyCode.W))
            {
                spaceship.Rotate(spinRate, Vector3.right);
            }
            else if (Input.GetKey(KeyCode.S))
            {
                spaceship.Rotate(-spinRate, Vector3.right);
            }
            else if (Input.GetKeyDown(KeyCode.Minus))
            {
                spaceship.UpdateThrust(-thrustPerKeypress);
            }
            else if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.Plus))
            {
                spaceship.UpdateThrust(thrustPerKeypress);
            }
            // Can check intercepts when trajectory is up to date
            if (!lastTrajectoryUpToDate && GravityEngine.Instance().TrajectoryUpToDate())
            {
                CheckIntercepts();
            }
            lastTrajectoryUpToDate = GravityEngine.Instance().TrajectoryUpToDate();
            break;

        case State.SELECT_OBJECTIVE:
            // check for mouse on a target object
            int selected = GetShipSelection();
            if (selected >= 0)
            {
                target = targets[selected];
            }
            break;

        case State.MANEUVER:
            // Show current time and pending maneuvers
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(string.Format("World Time: {0:000.0} [x{1}]\n",
                                    GravityEngine.Instance().GetPhysicalTime(),
                                    GravityEngine.Instance().GetTimeZoom()));
            sb.Append(string.Format("\nManeuvers Pending:\n"));
            string[] mstrings = spaceship.ManeuverString();
            if (mstrings.Length > 0)
            {
                foreach (string s in spaceship.ManeuverString())
                {
                    sb.Append(string.Format("{0}\n", s));
                }
                maneuverText.text = sb.ToString();
            }
            else
            {
                SetState(State.SELECT_OBJECTIVE);
            }
            break;

        default:
            break;
        }
    }