public void SetRuleset(int xStart, int xEnd, int possibleRotations, Shape[] ruleset) { mPossibleXStartPosition = xStart; mPossibleXEndPosition = xEnd; mNumberOfPossibleRotations = possibleRotations; mShapesInRuleset = ruleset; }
public void HandleTranslateRequest(UnityEngine.Vector3 movementVector) { if (mCurrentShape == null) return; //Move current shape mTetrisGrid.HandleTranslateRequest (mCurrentShape, movementVector); //Check for end game condition if (mTetrisGrid.GetRowBlockCount (0) > 0) { NotifyObservers (ClassicTetrisStateUpdate.GameEnded); return; } //Check if a shape was placed. If so, check for full rows, spawn new shape if (mTetrisGrid.WasShapeAddedToScene) { //Delete full rows foreach (int row in mTetrisGrid.GetFullRows ()) { UnityEngine.Debug.Log ("Row " + row + " is full. Deleting now..." + ++mDebugId); NotifyObservers (ClassicTetrisStateUpdate.RowDeleted); mTetrisGrid.DeleteRow (row); } mCurrentShape = mPreviewShape; mCurrentShape.TranslateToInitialPosition (); mPreviewShape = mFactory.SpawnRandomizedTetrisShape (mRulesetOption); NotifyObservers (ClassicTetrisStateUpdate.GeneratedNewShape); } }
public bool CheckCollisionWithBotWall(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (Math.Abs (pos.row + movementVector.y) >= mRowCount) return true; } return false; }
private void GenerateRuleset2() { Shape[] rulesetShapes = new Shape[1]; rulesetShapes [0] = new Shape (UnityEngine.GameObject.Find ("zShapeRight"), RotationStyles.flip90, 0); ShapeRuleset ruleset = new ShapeRuleset (); ruleset.SetRuleset (2, 7, 4, rulesetShapes); mRulesets.Add (ruleset); }
public void Cleanup() { if (mCurrentShape != null) mCurrentShape.DeleteShape (); if (mPreviewShape != null) mPreviewShape.DeleteShape (); mCurrentShape = null; mPreviewShape = null; mTetrisGrid.Cleanup (); }
public bool CheckCollisionWithRightWall(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (pos.column + movementVector.x >= mColumnCount) { return true; } } return false; }
public bool CheckCollisionWithAnyWall(Shape shape, UnityEngine.Vector3 movementVector) { if (CheckCollisionWithLeftWall (shape, movementVector) || CheckCollisionWithRightWall (shape, movementVector) || CheckCollisionWithBotWall (shape, movementVector)) { return true; } return false; }
private void GenerateRuleset1() { Shape[] rulesetShapes = new Shape[5]; rulesetShapes [0] = new Shape (UnityEngine.GameObject.Find ("tShape"), RotationStyles.none, 0); rulesetShapes [1] = new Shape (UnityEngine.GameObject.Find ("zShapeRight"), RotationStyles.none, 0); rulesetShapes [2] = new Shape (UnityEngine.GameObject.Find ("zShapeLeft"), RotationStyles.none, 0); rulesetShapes [3] = new Shape (UnityEngine.GameObject.Find ("lShapeRight"), RotationStyles.none, 0); rulesetShapes [4] = new Shape (UnityEngine.GameObject.Find ("lShapeLeft"), RotationStyles.none, 0); ShapeRuleset ruleset = new ShapeRuleset (); ruleset.SetRuleset (2, 7, 4, rulesetShapes); mRulesets.Add (ruleset); }
public bool collides(Shape shape, UnityEngine.Vector3 movementVector) { var shape1 = this.mCompositeGameObject.transform; var shape2 = shape.mCompositeGameObject.transform; foreach (UnityEngine.Transform block1 in shape1) { foreach (UnityEngine.Transform block2 in shape2) { if (((UnityEngine.Mathf.Abs ((block1.position.x + movementVector.x) - block2.position.x) * 2) < ((((UnityEngine.BoxCollider)block1.collider).size.x + ((UnityEngine.BoxCollider)block2.collider).size.x) - .1) && (UnityEngine.Mathf.Abs ((block1.position.y + movementVector.y) - block2.position.y) * 2) < ((((UnityEngine.BoxCollider)block1.collider).size.y + ((UnityEngine.BoxCollider)block2.collider).size.y) - .1))) { return true; } } } return false; }
public void Initialize(int rowCount, int columnCount, int rulesetOption) { mTetrisGrid.Initialize (rowCount, columnCount); mRulesetOption = rulesetOption; mCurrentShape = mFactory.SpawnRandomizedTetrisShape (mRulesetOption); mCurrentShape.TranslateToInitialPosition (); mPreviewShape = mFactory.SpawnRandomizedTetrisShape (mRulesetOption); }
public bool CheckCollisionWithTopWall(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (pos.row + movementVector.y > 0) { return true; } } return false; }
private void AddCurrentShapeToSceneBitGrid(Shape shape, bool val) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { mSceneGrid [pos.row, pos.column] = val; } mSceneGrid.UpdateRowBytes (); }
//feed in shape into this scene public void HandleTranslateRequest(Shape mCurrentShape, UnityEngine.Vector3 movementVector) { mWasShapeAddedToScene = false; //bool shapesCollided = DoAnyShapesCollideInScene (mCurrentShape, movementVector); //only do this once if (CheckCollisionWithLeftWall (mCurrentShape, movementVector) || CheckCollisionWithRightWall (mCurrentShape, movementVector)) return; //no action else if (CheckCollisionWithBotWall (mCurrentShape, movementVector) || (DoAnyShapesCollideInScene (mCurrentShape, movementVector) && movementVector.y != 0)) { //mCurrentShape.PlayCollisionAudio (); mWasShapeAddedToScene = true; ++mPlacedShapeCount; mListOfShapes.Add (mCurrentShape); AddCurrentShapeToSceneBitGrid (mCurrentShape, true); mSceneGrid.PrintBitArray (); //debug print } else if (!DoAnyShapesCollideInScene (mCurrentShape, movementVector)) mCurrentShape.Translate (movementVector); }
public void HandleRotateRequest(Shape shape) { UnityEngine.Vector3 movementVector = new UnityEngine.Vector3 (0, 0, 0); shape.Rotate (); if (CheckCollisionWithAnyWall (shape, movementVector) || DoAnyShapesCollideInScene (shape, movementVector)) { shape.Rotate (true); } }
//Returns information on each sub-block of the passed in Shape public List<CellInformation> GetCellInformation(Shape s, UnityEngine.Vector3 movementVector) { List<CellInformation> neighbors = new List<CellInformation> (); List<Coordinate> filledGridPositions = s.GetCurrentGridPosition (); foreach (AssemblyCSharp.Coordinate rowCol in filledGridPositions) { CellInformation info = new CellInformation (); info.coordinate.row = rowCol.row + (int)movementVector.y; info.coordinate.column = rowCol.column + (int)movementVector.x; int rowCount = mRowCount * -1; if (info.coordinate.row > 0 || info.coordinate.row <= rowCount || info.coordinate.column < 0 || info.coordinate.column >= mColumnCount) return null; int right = info.coordinate.column + 1; int left = info.coordinate.column - 1; int up = info.coordinate.row + 1; int down = info.coordinate.row - 1; if (up <= 0 && mSceneGrid [up, info.coordinate.column] == true) { info.TopNeighborStatus = TetrisGridCellStatus.Filled; } if (right < mColumnCount && mSceneGrid [info.coordinate.row, right] == true) { info.RightNeighborStatus = TetrisGridCellStatus.Filled; } if (right == mColumnCount) //boost a little bit on the sides of scores don't clump in the middle info.RightNeighborStatus = TetrisGridCellStatus.Wall; if (left >= 0 && mSceneGrid [info.coordinate.row, left] == true) { info.LeftNeighborStatus = TetrisGridCellStatus.Filled; } if (left == -1) info.LeftNeighborStatus = TetrisGridCellStatus.Wall; if (down > rowCount && mSceneGrid [down, info.coordinate.column] == true) { info.BotNeighborStatus = TetrisGridCellStatus.Filled; } if (down > rowCount && mSceneGrid [down, info.coordinate.column] == false && filledGridPositions.Count (x => x.row == (rowCol.row - 1) && x.column == rowCol.column) == 0) { info.BotNeighborStatus = TetrisGridCellStatus.Open; } if (down == rowCount) { info.BotNeighborStatus = TetrisGridCellStatus.Wall; } neighbors.Add (info); } return neighbors; }
//These collision detection functions are made public so they can be accessed by the AI public bool DoAnyShapesCollideInScene(Shape shape, UnityEngine.Vector3 movementVector) { List<Coordinate> filledGridPositions = shape.GetCurrentGridPosition (); foreach (Coordinate pos in filledGridPositions) { if (mSceneGrid [pos.row + (int)movementVector.y, pos.column + (int)movementVector.x] == true) return true; } return false; }