Esempio n. 1
0
 public Frame(int frameID, bool isEnd, Player.FixedMouseButtons fuMouse)
 {
     this.frameID = frameID;
     this.isEnd   = isEnd;
     x            = fuMouse.str_x;
     y            = fuMouse.str_y;
     wasDown      = fuMouse.wasDown;
     wasUp        = fuMouse.wasUp;
 }
Esempio n. 2
0
    internal void HandleInput(ref Player.FixedMouseButtons fuMouse)
    {
        var player = GetComponent <Player>();

        switch (playMode)
        {
        case PlayMode.RECORD:
            if (fuMouse.wasDown || fuMouse.wasUp)
            {
                if (frames.Count <= 0)
                {
                    StartRecording(player);
                }
                var frame = new Frame(frameID, false, fuMouse);
                Debug.Log("Record # " + frame.frameID + " (" + (frame.wasDown ? "Down" : "Up") + ") x=" + frame.x + " y=" + frame.y);
                frames.Add(frame);

                var pos      = player.transform.position;
                var velocity = player.velocity;
                positions.Add(new Position(frameID, (int)(pos.x * 1000), (int)(pos.y * 1000), velocity.x.ToString(), velocity.y.ToString()));
            }
            break;

        case PlayMode.REPLAY:
            if (frames.Count() <= 0)
            {
                fuMouse         = new Player.FixedMouseButtons();
                fuMouse.isEnded = true;
                isEnded         = true;
            }
            else
            {
                var tail = frames.First();
                if (frameID != tail.frameID)
                {
                    fuMouse = new Player.FixedMouseButtons();
                }
                else
                {
                    Debug.Log("Replay # " + tail.frameID + " (" + (tail.wasDown ? "Down" : "Up") + ") x=" + tail.x + " y=" + tail.y);
                    fuMouse.str_x   = tail.x;
                    fuMouse.str_y   = tail.y;
                    fuMouse.wasDown = tail.wasDown;
                    fuMouse.wasUp   = tail.wasUp;


                    var pos      = player.transform.position;
                    var velocity = player.velocity;
                    var _pos     = new Position(frameID, (int)(pos.x * 1000), (int)(pos.y * 1000), velocity.x.ToString(), velocity.y.ToString());

                    if (positions.Count() > 0)
                    {
                        var posTail = positions.First();
                        Debug.Log("Replay # " + posTail.frameID + " " +
                                  "Position: x=" + _pos.x + " y=" + _pos.y + " vx=" + _pos.vx + " vy=" + _pos.vy + " | " +
                                  "REC Position: x=" + posTail.x + " y=" + posTail.y + " vx=" + posTail.vx + " vy=" + posTail.vy +
                                  "");

                        bool outSync = (
                            _pos.x != posTail.x ||
                            _pos.y != posTail.y ||
                            !String.Equals(_pos.vx, posTail.vx) ||
                            !String.Equals(_pos.vy, posTail.vy)
                            );

                        if (outSync)
                        {
                            Debug.Log("Out sync!");
                        }
                        positions.RemoveAt(0);
                    }

                    frames.RemoveAt(0);
                    if (frames.Count() <= 0)
                    {
                        Debug.Log("Replay Ended.");
                        fuMouse.isEnded = true;
                        isEnded         = true;
                    }
                }
            }
            break;
        }
        frameID++;
    }