/// <summary> /// Checkes if two game objects are in collision /// </summary> /// <param name="first">The first game object</param> /// <param name="second">The second game object</param> /// <returns>True if the objects are in collision, false - otherwise</returns> private bool AreInCollision(GameObject first, GameObject second) { char[,] firstImage = first.GetImage(); char[,] secondImage = second.GetImage(); for (int firstRow = 0; firstRow < firstImage.GetLength(0); firstRow++) { for (int firstCol = 0; firstCol < firstImage.GetLength(1); firstCol++) { if (firstImage[firstRow, firstCol] != ' ') { for (int secondRow = 0; secondRow < secondImage.GetLength(0); secondRow++) { for (int secondCol = 0; secondCol < secondImage.GetLength(1); secondCol++) { if (secondImage[secondRow, secondCol] != ' ' && first.X + firstCol == second.X + secondCol && first.Y + firstRow == second.Y + secondRow) { return true; } } } } } } return false; }
/// <summary> /// Determines if a given object is on a valid position /// </summary> /// <param name="obj">The object whose position to be checked for validity</param> /// <returns>True - if the object is on valid position, false - otherwise</returns> private bool isOnValidPosition(GameObject obj) { // if is outside the game field if (obj.X < 0 || obj.X + obj.Width > this.renderer.Width || obj.Y < 0 || obj.Y + obj.Height > this.renderer.Height) { return false; } // if is over other object for (int i = 0; i < this.staticObjects.Count; i++) { if (this.AreInCollision(this.currentFigure, this.staticObjects[i])) { return false; } } return true; }
public void NotifyBlockFellOver(GameObject blockObj) { if (this.fellOverBlocks.Contains(blockObj)) return; this.fellOverBlocks.Add(blockObj); this.blockFellOverTime = Time.GameTimer; }