override protected void onCollision(bool enter, RelPos p, GO other) { Type otherType = Type.Error; this.issueEvent <RemoteGetType>( (x, y) => x.Get(out otherType), other); if (otherType > Type.Followable) { collCtx ctx; ctx.enter = enter; ctx.p = p; ctx.other = other; ctx.otherType = otherType; if (enter) { this.onCollisionEnter(ctx); } else { this.onCollisionExit(ctx); } } }
public static UnityEngine.Vector3 toPosition(this RelPos p) { switch (p) { case RelPos.Top: return(new UnityEngine.Vector3(0.0f, 1.0f, 0.0f)); case RelPos.Left: return(new UnityEngine.Vector3(1.0f, 0.0f, 0.0f)); case RelPos.Right: return(new UnityEngine.Vector3(-1.0f, 0.0f, 0.0f)); case RelPos.Bottom: return(new UnityEngine.Vector3(0.0f, -1.0f, 0.0f)); case RelPos.Back: return(new UnityEngine.Vector3(0.0f, 0.0f, 1.0f)); case RelPos.Front: return(new UnityEngine.Vector3(0.0f, 0.0f, -1.0f)); default: return(new UnityEngine.Vector3(0.0f, 0.0f, 0.0f)); } }
protected GO getObjectAt(RelPos p) { GO ret = null; this.issueEvent <GetRelativeObject>( (x, y) => x.GetObjectAt(out ret, p)); return(ret); }
private void onCollisionDown(bool enter, RelPos p, GO other) { if (enter && other.GetComponent <BaseBlock>() != null) { this.transform.SetParent(other.transform); this.setCollisionCb(RelPos.Bottom, null); } }
private System.Collections.IEnumerator delayedOnLastBlockExit(RelPos p, GO other) { yield return(new UnityEngine.WaitForFixedUpdate()); if (this.downCount == 0) { this.onLastBlockExit(p, other); } }
protected GO getBlockAt(RelPos p) { GO ret = this.getObjectAt(p); if (!isBlock(ret)) { ret = null; } return(ret); }
private void onCollisionUp(bool enter, RelPos p, GO other) { bool onLedge = false; this.issueEvent <OnLedgeDetector>((x, y) => x.Check(out onLedge), other); if (enter && !onLedge) { this.checkCondition(other); } }
override protected void onLastBlockExit(RelPos p, GO other) { bool otherMoving = false; this.issueEvent <MovementController>( (x, y) => x.IsMoving(out otherMoving), other); if (otherMoving) { this.StartCoroutine(this._onLastBlockExit()); } }
private void onCollisionCenter(bool enter, RelPos p, GO other) { Type type = Type.Error; this.issueEvent <RemoteGetType>((x, y) => x.Get(out type), other); if (enter && type == Type.Player) { Global.Sfx.playCheckpoint(this.transform); this.rootEvent <LoaderEvents>( (x, y) => x.SetActiveCheckpoint(this.checkPointIdx)); this.destroy(); this.setCollisionCb(RelPos.Center, null); } }
private void onCenter(bool enter, RelPos p, GO other) { Type otherType = Type.Error; this.issueEvent <RemoteGetType>( (x, y) => x.Get(out otherType), other); if (otherType != Type.Player && otherType != Type.Minion) { /* Avoid triggering the death scene while rendering the * level thumbnails */ if (SceneMng.GetActiveScene().name != LevelSelectScene) { Global.Sfx.playPlayerCrushed(this.fastGetTr()); SceneMng.LoadSceneAsync("YouLose", SceneMode.Additive); } this.gameObject.SetActive(false); } }
private void onCollisionDown(bool enter, RelPos p, GO other) { if (other.GetComponent <BaseBlock>() != null) { if (enter) { this.downCount++; } else { this.downCount--; if (this.downCount == 0) { /* Call as a coroutine, to delay until the end of frame */ this.StartCoroutine(this.delayedOnLastBlockExit(p, other)); } } } this.onCollision(enter, p, other); }
private Dir CardinalRelPosToLocalDir(RelPos p) { switch (p) { case RelPos.Front: return(Dir.Front.toLocal(this.facing)); case RelPos.Right: return(Dir.Right.toLocal(this.facing)); case RelPos.Left: return(Dir.Left.toLocal(this.facing)); case RelPos.Back: return(Dir.Back.toLocal(this.facing)); default: return(Dir.None); } }
private void onCollisionUp(bool enter, RelPos p, GO other) { Type objType = Type.Error; bool onLedge = false; this.issueEvent <RemoteGetType>((x, y) => x.Get(out objType), other); if (objType != Type.Minion && objType != Type.Player) { return; } this.issueEvent <OnLedgeDetector>((x, y) => x.Check(out onLedge), other); if (enter && !onLedge) { this.updateCrackedStateEnter(); } else if (!enter) { this.updateCrackedStateExit(); } }
/** * Try to move sideways while in a ledge. One can simply move to the sides, * around a block or toward a block. * * @param dir Relative direction of the movement (Left or Right) * @param innerTurn New direction when moving **toward** a block * @param outerTurn New direction when moving **around** a block * @param moveDir Base direction of sideways movement * @param moveDelay How long the movement should take */ private void tryMoveLedgeSide(RelPos dir, Dir innerTurn, Dir outerTurn, Dir moveDir, float moveDelay) { GO dirObj, frontDirObj, topDirObj; bool isWall, isInner; dirObj = this.getBlockAt(dir); frontDirObj = this.getBlockAt(RelPos.FrontSomething | dir); topDirObj = this.getBlockAt(RelPos.TopSomething | dir); isWall = (dirObj == null) && (frontDirObj != null); isInner = (dirObj != null); if (isWall && (topDirObj == null)) { Dir d = moveDir.toLocal(this.facing); this.move(d, moveDelay); } else if (isInner) { this.turn(innerTurn); } else { GO frontTopDirObj; bool isOuter; frontTopDirObj = this.getBlockAt(RelPos.FrontTopSomething | dir); isOuter = (dirObj == null) && (frontDirObj == null); if (isOuter && (frontTopDirObj == null) && (topDirObj == null)) { Dir d = moveDir.toLocal(this.facing) | Dir.Front.toLocal(this.facing); this.move(d, moveDelay); this.turn(outerTurn); } } }
private void setCollisionCb(RelPos p, System.Action <bool, RelPos, GO> cb) { System.Tuple <RelPos, System.Action <bool, RelPos, GO> > arg; arg = new System.Tuple <RelPos, System.Action <bool, RelPos, GO> >(p, cb); this.BroadcastMessage("SetRelativePositionCallback", arg); }
public static RelPos masked(this RelPos p) { return((RelPos)((int)p & (int)mask)); }
public static int toInt(this RelPos p) { return((int)p); }
/** Retrieve how many itens are in this enumeration. */ public static int count(this RelPos p) { return(38); }
/** Convert the enumeration to a sequential integer. */ public static int toIdx(this RelPos p) { switch (p) { case RelPos.Top: return(0); case RelPos.Left: return(1); case RelPos.Right: return(2); case RelPos.Bottom: return(3); case RelPos.TopLeft: return(4); case RelPos.TopRight: return(5); case RelPos.BottomLeft: return(6); case RelPos.BottomRight: return(7); case RelPos.Back: return(8); case RelPos.BackTop: return(9); case RelPos.BackLeft: return(10); case RelPos.BackRight: return(11); case RelPos.BackBottom: return(12); case RelPos.BackTopLeft: return(13); case RelPos.BackTopRight: return(14); case RelPos.BackBottomLeft: return(15); case RelPos.BackBottomRight: return(16); case RelPos.Front: return(17); case RelPos.FrontTop: return(18); case RelPos.FrontLeft: return(19); case RelPos.FrontRight: return(20); case RelPos.FrontBottom: return(21); case RelPos.FrontTopLeft: return(22); case RelPos.FrontTopRight: return(23); case RelPos.FrontBottomLeft: return(24); case RelPos.FrontBottomRight: return(25); case RelPos.BottomBottomFront: return(26); case RelPos.FrontFront: return(27); case RelPos.BackBack: return(28); case RelPos.LeftLeft: return(29); case RelPos.RightRight: return(30); case RelPos.FrontTopFrontTop: return(31); case RelPos.FrontFrontTop: return(32); case RelPos.FrontFrontBottom: return(33); case RelPos.FrontBottomFrontBottom: return(34); case RelPos.Center: return(35); case RelPos.Nearby: return(36); case RelPos.BottomBottom: return(37); default: return(-1); } }
protected bool checkBlockAt(out GO obj, out Dir dir, RelPos p) { obj = this.getBlockAt(p); dir = this.CardinalRelPosToLocalDir(p); return(obj != null); }
/* == Base Methods ====================================================== */ virtual protected void onLastBlockExit(RelPos p, GO other) { }
virtual protected void onCollision(bool enter, RelPos p, GO other) { }
public static RelPos shift(this RelPos p) { return((RelPos)((int)p >> (int)RelPos.Shift)); }