bool canRotate(BTetrisTransform tetrimino, TetriminoConfig.RotationType rotationType, Vector3 translation) { //if(tetrimino) var points = tetrimino.toCoordArray(translation, rotationType); return( points.All(point => this.field.pointInField(point)) && !this.field.collides(points)); }
public List <Vector3> toCoordArray(Vector3 translation, TetriminoConfig.RotationType rotationType) { var shapeID = (rotationType == TetriminoConfig.RotationType.none ? this._shapeID : this.tetriminoConfig.config[this._shapeID].nextConfig[(int)rotationType]); var points = this.tetriminoConfig.toPoints(shapeID); var result = points.Select(point => { return(point + translation + position); } ).ToList(); return(result); }
public void tryRotateMovingPiece(TetriminoConfig.RotationType rotationnEnum) { var canRotate = false; Vector3 translation; // one-liner that checks for rotation and translation, plus memorizing the translation result if (this.canRotate(this.movingPiece, rotationnEnum, (translation = Vector3.zero))) { canRotate = true; } if (!canRotate && this.canRotate(this.movingPiece, rotationnEnum, (translation = Vector3.left))) { canRotate = true; } if (!canRotate && this.canRotate(this.movingPiece, rotationnEnum, (translation = Vector3.right))) { canRotate = true; } if (!canRotate && this.canRotate(this.movingPiece, rotationnEnum, (translation = Vector3.forward))) { canRotate = true; } if (!canRotate && this.canRotate(this.movingPiece, rotationnEnum, (translation = Vector3.back))) { canRotate = true; } //if (!canRotate) //{ // translation = Vector3.zero; // canRotate = this.canRotate(this.movingPiece, rotationnEnum, translation); //} // if all is well if (canRotate) { this.movingPiece.move(translation); this.movingPiece.rotate((int)rotationnEnum); } }