public bool IsOut() { var pos = transform.position; var size = GetComponent <Collider2D>().bounds.size; return(BorderDetector.IsOut(pos, size)); }
private void StartLevel() { for (var i = 0; i < currentLevel.asteroidsCount; i++) { var pos = BorderDetector.GetRandomPosOnPerimeter(); BaseEnemy enemy = Instantiate(currentLevel.asteroidPrefab, pos, Quaternion.Euler(0, 0, Random.Range(0f, 360f))); enemy.AddForwardForse(currentLevel.asteroidSpeed); gameManager.AddEnemy(enemy); } }
public bool IsCollised() { var pos = transform.position; var size = GetComponent <Collider2D>().bounds.size; var isCol = BorderDetector.IsCollised(pos, size); IsCollisedDebug = isCol; IsOutDebug = BorderDetector.IsOut(pos, size); posDebug = pos; sizeDebug = size; topRightDebug = BorderDetector.RightTop; leftBottomDebug = BorderDetector.LeftBottom; return(isCol); }
/// <summary> /// ugly spaghetti code, but it gets it's job done /// rewrite if better performance needed /// </summary> /// <param name="side"></param> /// <param name="input"></param> /// <returns></returns> private int findContentFrom(Side side, Bitmap input) { int from = 0, to = 0; Color c; var detector = new BorderDetector(safetyTryCount); if (side == Side.Left) { from = 0; to = input.Width; for (int x = 0; x < to; x++) { bool hit = false; for (int y = 0; y < input.Height; y++) { // SLOOOOOW, use LockBits c = input.GetPixel(x, y); if (c.R > threshold || c.G > threshold || c.B > threshold) { hit = true; break; } } if (hit) { if (detector.Hit()) { return(from + detector.HitPosition); } } else { detector.Miss(); } } } else if (side == Side.Right) { from = input.Width - 1; to = 0; for (int x = from; x > to; x--) { bool hit = false; for (int y = 0; y < input.Height; y++) { // SLOOOOOW, use LockBits c = input.GetPixel(x, y); if (c.R > threshold || c.G > threshold || c.B > threshold) { hit = true; break; } } if (hit) { if (detector.Hit()) { return(from - detector.HitPosition); } } else { detector.Miss(); } } } else if (side == Side.Top) { from = 0; to = input.Height; for (int y = from; y < to; y++) { bool hit = false; for (int x = 0; x < input.Width; x++) { // SLOOOOOW, use LockBits c = input.GetPixel(x, y); if (c.R > threshold || c.G > threshold || c.B > threshold) { hit = true; break; } } if (hit) { if (detector.Hit()) { return(from + detector.HitPosition); } } else { detector.Miss(); } } } else if (side == Side.Bottom) { from = input.Height - 1; to = 0; for (int y = from; y > to; y--) { bool hit = false; for (int x = 0; x < input.Width; x++) { // SLOOOOOW, use LockBits c = input.GetPixel(x, y); if (c.R > threshold || c.G > threshold || c.B > threshold) { hit = true; break; } } if (hit) { if (detector.Hit()) { return(from - detector.HitPosition); } } else { detector.Miss(); } } } return(from); }