示例#1
0
    public override void Move(Vector2 delta)
    {
        // NO TravelMind? Trim/bloat me to fit within Room!
        if (!HasTravelMind())
        {
            Rect pr = GetMyRectBL(); // prev MyRect (bottom-left aligned).
            Rect nr = GetMyRectBL(); // new MyRect (bottom-left aligned).
            nr.position += delta;    // Move.

            // INCREASE size.
            Rect camBounds = MyRoom.GetCameraBoundsLocal();
            Rect bA        = MathUtils.BloatRect(camBounds, -0.8f); // bloated inward
            Rect bB        = MathUtils.BloatRect(camBounds, 0.8f);  // bloated outward
            if (pr.xMin <= bA.xMin && nr.xMin >= bB.xMin)
            {
                nr.xMin = bB.xMin;
            }
            if (pr.xMax >= bA.xMax && nr.xMax <= bB.xMax)
            {
                nr.xMax = bB.xMax;
            }
            if (pr.yMin <= bA.yMin && nr.yMin >= bB.yMin)
            {
                nr.yMin = bB.yMin;
            }
            if (pr.yMax >= bA.yMax && nr.yMax <= bB.yMax)
            {
                nr.yMax = bB.yMax;
            }

            // DECREASE size.
            nr = TrimmedRectToRoomBounds(nr, MyRoom); // finally, cut off the sides that aren't in bounds!

            // Return!
            nr.position = nr.center; // offset to CENTER aligned.
            SetSize(nr.size);
            SetPos(nr.position);
        }
        // YES TravelMind! Just use base Move.
        else
        {
            base.Move(delta);
        }
    }
示例#2
0
    //protected Vector2 GravityForce =
    //override protected Vector2 Gravity { get { return base.Gravity * FlipDir; } }
    //override protected float JumpForce { get { return base.JumpForce * FlipDir; } }
    //override public bool IsGrounded() {
    //    return myWhiskers.OnSurface(FlipDir<0 ? Sides.T : Sides.B);
    //}
    //override protected float WallSlideMinYVel { get { return FlipDir<0 ? Mathf.NegativeInfinity : -0.11f; } }
    //override protected float WallSlideMaxYVel { get { return FlipDir<0 ? 0.11f : Mathf.Infinity; } }
    //override protected Vector2 WallKickForce { get { return new Vector2(0.35f, 0.46f*FlipDir); } }
    //protected override Vector2 GetVelForWallKick() {
    //    if (FlipDir < 0) {
    //        return new Vector2(-myWhiskers.DirLastTouchedWall*WallKickForce.x, Mathf.Min(vel.y, WallKickForce.y));
    //    }
    //    return base.GetVelForWallKick();
    //}
    //private static int FlipDir=1; // 1 or -1.

    //   private void OnDrawGizmos() {
    //	if (myRoom==null) { return; }
    //	Gizmos.color = Color.cyan;
    //	Gizmos.DrawWireCube (myRoom.PosGlobal+camBoundsLocal.center, new Vector3(camBoundsLocal.size.x,camBoundsLocal.size.y, 10));
    //}

    // ----------------------------------------------------------------
    //  Start
    // ----------------------------------------------------------------
    //override protected void Start () {
    //	base.Start();

    //	SetSize (new Vector2(1.5f, 1.8f));
    //}
    public void InitializeAsPlayer(Room _myRoom, PlayerData data)
    {
        base.InitializeAsPlatformCharacter(_myRoom, data);

        // Give huge linear/angular drag to my rigidbody.
        Rigidbody2D myRB = GetComponent <Rigidbody2D>();

        myRB.drag        = 999999;
        myRB.angularDrag = 999999;

        DirFacing            = data.dirFacing;
        timeStoppedWallSlide = Mathf.NegativeInfinity;

        // Set camBoundsLocal!
        const float boundsBloat = 0f;         // I have to like *really* be off-screen for this to register.

        camBoundsLocal           = MyRoom.GetCameraBoundsLocal();
        camBoundsLocal.size     += new Vector2(boundsBloat, boundsBloat) * 2f;
        camBoundsLocal.position -= new Vector2(boundsBloat, boundsBloat);

        GameManagers.Instance.DataManager.UnlockPlayerType(PlayerType()); // TEMP: Also unlock this PlayerType here (and only here).
    }