예제 #1
0
파일: Track.cs 프로젝트: Cyrelc/330
 // Use this for initialization
 void Start()
 {
     b = new BSpline(ctrl);
     u = 0f;
     top_speed = 40f;
     velocity = 0;
     lane = Vector3.zero;
     drag *= weight;
     int x = 0;
     for (float i = 0; i < ctrl.Length; i += 0.1f, x++)
         lane_display[x] = (b.Evaluate(i) - b.Evaluate(i+0.1f));
 }
예제 #2
0
파일: CC1.cs 프로젝트: massiecb/330
	// Update is called once per frame
	void FixedUpdate () {
		if (lap_count < 2 && winpage == false) {
			velocity = deltaVelocity (velocity);
			float next_position;
			if (lane_change_pause < 15)
				lane_change_pause++;
			if (u + 1 >= bspline.Length)
				next_position = u + 1 - bspline.Length;
			else
				next_position = (float)Math.Truncate (u) + 1f;
			float point_smooth = 1 / (bspline.Evaluate (next_position) - bspline.Evaluate ((float)Math.Truncate (u))).magnitude;
			u += Time.fixedDeltaTime * velocity / 5 * point_smooth;
			if (CrossPlatformInputManager.GetAxis ("Horizontal") != 0 && lane_change_pause == 15)
				changeLanes ();
			if (u >= bspline.Length) {
				u -= bspline.Length;
				lap_count += 1;
			}
			Vector3 next_pos = bspline.Evaluate (u);
			UI_Update ();
			ghost.transform.LookAt (next_pos);
			ghost.transform.position = next_pos;
			if (whatTrack == -1)
				next_pos = ghost.transform.position - ghost.transform.right * shift;
			else if (whatTrack == 1)
				next_pos = ghost.transform.position + ghost.transform.right * shift;
			if (lane_change != 1) {
				if (lane_change + 0.01 > 1f)
					lane_change = 1;
				else
					lane_change += 0.01f;
			}
			if (u < 76 || u > 87)
				next_pos.y = gameTerrain.SampleHeight (next_pos) + 0.3f;
			transform.localRotation = ghost.transform.localRotation;
			transform.position = transform.position * (1 - lane_change) + next_pos * lane_change;
			if (Input.GetKeyDown ("space") && powerUp != Avail_PowerUps.None) {
				//Debug.Log (powerUp);
				power_up.enabled = false;
				spawnPoint.UsePowerUp (powerUp);
				powerUp = Avail_PowerUps.None;
				//            Debug.Log(powerUp);
			}
		}
			else if (winpage == false){
				print ("You WIN!!!!!");
				winpage = true;
			}
	}
예제 #3
0
    // Use this for initialization
    void Start()
    {
        b         = new BSpline(ctrl);
        u         = 0f;
        top_speed = 40f;
        velocity  = 0;
        lane      = Vector3.zero;
        drag     *= weight;
        int x = 0;

        for (float i = 0; i < ctrl.Length; i += 0.1f, x++)
        {
            lane_display[x] = (b.Evaluate(i) - b.Evaluate(i + 0.1f));
        }
    }
예제 #4
0
파일: Path.cs 프로젝트: johtela/Compose3D
        public static Path <V, D> FromBSpline(BSpline <D> spline, int numNodes)
        {
            var nodes = new V[numNodes];
            var curr  = spline.Knots.First();
            var last  = spline.Knots.Last() - 0.000001f;
            var step  = (float)(last - curr) / (numNodes - 1);

            for (int i = 0; i < numNodes; i++)
            {
                nodes[i].position = spline.Evaluate(curr);
                curr = Math.Min(curr + step, last);
            }
            return(new Path <V, D> (nodes));
        }
예제 #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        changeLanes();
        deltaVelocity();
        u += Time.deltaTime * velocity / 5;
        if (u >= b.Length)
        {
            u -= b.Length;
        }
        Vector3 next_pos = b.Evaluate(u);

        for (int i = 0; i < lane_display.Length; i++)
        {
            Handles.DrawLine(lane_display[i], lane_display[i + 1]);
        }
        transform.LookAt(next_pos);
        transform.position = next_pos + lane;
    }
예제 #6
0
파일: AI.cs 프로젝트: massiecb/330
 // Update is called once per frame
 void FixedUpdate()
 {
     if (lap_count < 4 && winpage == false)
     {
         AnimatorStateInfo state = anim.GetCurrentAnimatorStateInfo(0);
         if (delay < 15)
         {
             delay++;
         }
         velocity = deltaVelocity(velocity);
         if (lane_change_pause < 15)
         {
             lane_change_pause++;
         }
         float next_position;
         if (u + 1 > b.Length)
         {
             next_position = u + 1f - b.Length;
         }
         else
         {
             next_position = (float)Math.Truncate(u) + 1f;
         }
         float point_smooth = 1 / (b.Evaluate(next_position) - b.Evaluate((float)Math.Truncate(u))).magnitude;
         u += Time.fixedDeltaTime * velocity / 5 * point_smooth;
         //if (CrossPlatformInputManager.GetAxis("Horizontal") != 0 && lane_change_pause == 15)
         //	changeLanes();
         if (u >= b.Length)
         {
             u -= b.Length;
             lap_count++;
         }
         Vector3 next_pos = b.Evaluate(u);
         ghost.transform.LookAt(next_pos);
         ghost.transform.position = next_pos;
         if (whatTrack == -1)
         {
             next_pos = ghost.transform.position - ghost.transform.right * shift;
         }
         else if (whatTrack == 1)
         {
             next_pos = ghost.transform.position + ghost.transform.right * shift;
         }
         if (lane_change != 1)
         {
             if (lane_change + 0.01 > 1f)
             {
                 lane_change = 1;
             }
             else
             {
                 lane_change += 0.01f;
             }
         }
         transform.localRotation = ghost.transform.localRotation;
         transform.position      = transform.position * (1 - lane_change) + next_pos * lane_change;
         if (state.IsName("Accelerate"))
         {
             AccelerationHandler();
         }
         else if (state.IsName("UseShell"))
         {
             if (delay == 15)
             {
                 ShellHandler();
             }
             delay = 0;
         }
         else if (state.IsName("ChangeLanes"))
         {
             ChangeLane();
         }
         else if (state.IsName("UseOilSlick"))
         {
             OilSlickHandler();
         }
         else if (state.IsName("Speedy"))
         {
             SpeedyHandler();
         }
         else if (state.IsName("Invinc"))
         {
             InvincHandler();
         }
     }
     else if (winpage == false)
     {
         GameObject [] temp = GameObject.FindGameObjectsWithTag("Car");
         for (int i = 0; i < temp.Length; i++)
         {
             if (temp[i].GetComponent <CC1>() != null)
             {
                 temp[i].GetComponent <CC1>().winpage = true;
             }
         }
         winpage = true;
         print("You lose");
     }
 }
예제 #7
0
        private void animate()
        {
            Animation.Sequence sequence = new Animation.Sequence();

            bool originalCanPause = false;

            sequence.Add(new Animation.Execute(delegate()
            {
                Entity p = PlayerFactory.Instance;
                if (p != null)
                {
                    p.Get <Model>("FirstPersonModel").Enabled.Value = false;
                    p.Get <Model>("Model").Enabled.Value            = false;
                    p.Get <CameraController>().Enabled.Value        = false;
                    p.Get <FPSInput>().Enabled.Value   = false;
                    p.Get <UIRenderer>().Enabled.Value = false;
                    AkSoundEngine.PostEvent(AK.EVENTS.STOP_PLAYER_BREATHING_SOFT, p);
                }
                CameraStop.CinematicActive.Value = true;
                originalCanPause = this.main.Menu.CanPause;
#if !DEVELOPMENT
                this.main.Menu.CanPause.Value = false;
#endif
            }));

            sequence.Add(new Animation.Set <Matrix>(this.main.Camera.RotationMatrix, Matrix.CreateFromQuaternion(this.Entity.Get <Transform>().Quaternion)));
            sequence.Add(new Animation.Set <Vector3>(this.main.Camera.Position, Vector3.Transform(new Vector3(0, 0, this.Offset), this.Entity.Get <Transform>().Matrix)));

            Animation.Ease.EaseType lastEase = Animation.Ease.EaseType.None;
            BSpline spline        = null;
            Entity  current       = this.Entity;
            float   totalDuration = 0.0f;
            while (current != null)
            {
                CameraStop currentStop      = current.Get <CameraStop>();
                Transform  currentTransform = current.Get <Transform>();

                Entity     next     = currentStop.Next.Value.Target;
                CameraStop nextStop = next == null ? null : next.Get <CameraStop>();

                if (!lastEase.BlendsInto(currentStop.Blend) || next == null)
                {
                    if (spline != null)
                    {
                        spline.Add(currentTransform.Position, currentTransform.Quaternion, currentStop.Offset);
                    }
                    spline = new BSpline();
                }

                float currentTime = spline.Duration;
                spline.Duration += currentStop.Duration;
                totalDuration   += currentStop.Duration;

                if (currentStop.Blend != Animation.Ease.EaseType.None && next != null)
                {
                    BSpline currentSpline = spline;
                    currentSpline.Add(currentTransform.Position, currentTransform.Quaternion, currentStop.Offset);
                    Transform nextTransform = next.Get <Transform>();
                    sequence.Add
                    (
                        new Animation.Ease
                        (
                            new Animation.Custom
                            (
                                delegate(float x)
                    {
                        float lerpValue                       = (currentTime + x * currentStop.Duration) / currentSpline.Duration;
                        BSpline.ControlPoint point            = currentSpline.Evaluate(lerpValue);
                        Matrix rotationMatrix                 = Matrix.CreateFromQuaternion(point.Orientation);
                        this.main.Camera.RotationMatrix.Value = rotationMatrix;
                        Matrix m = rotationMatrix * Matrix.CreateTranslation(point.Position);
                        this.main.Camera.Position.Value = Vector3.Transform(new Vector3(0, 0, point.Offset), m);
                    },
                                currentStop.Duration
                            ),
                            currentStop.Blend
                        )
                    );
                }
                else
                {
                    sequence.Add
                    (
                        new Animation.Custom
                        (
                            delegate(float x)
                    {
                        this.main.Camera.RotationMatrix.Value = Matrix.CreateFromQuaternion(currentTransform.Quaternion);
                        this.main.Camera.Position.Value       = Vector3.Transform(new Vector3(0, 0, currentStop.Offset), currentTransform.Matrix);
                    },
                            currentStop.Duration
                        )
                    );
                }

                sequence.Add(new Animation.Execute(currentStop.OnDone));

                lastEase = currentStop.Blend;
                current  = next;
            }

            Action done = delegate()
            {
                Entity p = PlayerFactory.Instance;
                if (p != null)
                {
                    p.Get <Model>("FirstPersonModel").Enabled.Value = true;
                    p.Get <Model>("Model").Enabled.Value            = true;
                    p.Get <CameraController>().Enabled.Value        = true;
                    p.Get <FPSInput>().Enabled.Value   = true;
                    p.Get <UIRenderer>().Enabled.Value = true;
                }
                CameraStop.CinematicActive.Value = false;
                this.main.Menu.CanPause.Value    = originalCanPause;
            };

            Animation anim;
            if (PlayerFactory.Instance != null && totalDuration > 0.0f)             // Fade in and out
            {
                anim = new Animation
                       (
                    new Animation.Vector3MoveTo(this.main.Renderer.Tint, Vector3.Zero, 0.5f),
                    new Animation.Parallel(sequence, new Animation.Vector3MoveTo(this.main.Renderer.Tint, Vector3.One, 0.5f)),
                    new Animation.Vector3MoveTo(this.main.Renderer.Tint, Vector3.Zero, 0.5f),
                    new Animation.Execute(done),
                    new Animation.Vector3MoveTo(this.main.Renderer.Tint, Vector3.One, 0.5f)
                       );
            }
            else
            {
                // Just do it
                anim = new Animation
                       (
                    sequence,
                    new Animation.Execute(done)
                       );
            }
            anim.EnabledWhenPaused = false;
            WorldFactory.Instance.Add(anim);
        }