private void setPosition(Vector2 blackHolePosition, Vector2 playerPosition, int levelWidth, int levelHeight) { //set bounds on new spawn location bool leftSide = (XnaHelper.RandomInt(0, 1) == 0); _position.X = leftSide ? 0 : levelWidth; _hitRect.X = leftSide ? 0 : levelWidth - _hitRect.Width; _sprite.FlipH = !leftSide; _position.Y = XnaHelper.RandomInt(0, levelHeight); _hitRect.Y = (int)_position.Y; }
private void setPosition(Vector2 blackHolePosition, int levelWidth, int levelHeight) { //set bounds on new spawn location int minX, maxX, minY, maxY; //spawn in bounds -- default for burst wave minX = 0; maxX = levelWidth; minY = 0; maxY = levelHeight; if (_isTrickleWave) //spawn out of bounds { switch (XnaHelper.RandomInt(0, 3)) { case 0: //top minX = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER; minY = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxY = 0; break; case 1: //right minX = levelWidth; maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER; minY = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER; break; case 2: //bottom minX = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER; minY = levelHeight; maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER; break; case 3: //left minX = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxX = 0; minY = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER; break; } } XnaHelper.RandomizeVector(ref _spawnLocation, minX, maxX, minY, maxY); //if spawned too close to black hole, try again if ((_spawnLocation - blackHolePosition).Length() < MIN_BLACKHOLE_SPAWN_DISTANCE) { setPosition(blackHolePosition, _levelBounds.Width, _levelBounds.Height); } }
private void setPosition(Vector2 blackHolePosition, int levelWidth, int levelHeight) { //set bounds on new spawn location int minX, maxX, minY, maxY; //spawn in bounds -- default for burst wave minX = 0; maxX = levelWidth; minY = 0; maxY = levelHeight; switch (XnaHelper.RandomInt(0, 3)) { case 0: //top minX = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER; minY = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxY = 0; break; case 1: //right minX = levelWidth; maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER; minY = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER; break; case 2: //bottom minX = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxX = levelWidth + OUT_OF_BOUNDS_SPAWN_BUFFER; minY = levelHeight; maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER; break; case 3: //left minX = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxX = 0; minY = -OUT_OF_BOUNDS_SPAWN_BUFFER; maxY = levelHeight + OUT_OF_BOUNDS_SPAWN_BUFFER; break; } do { XnaHelper.RandomizeVector(ref _position, minX, maxX, minY, maxY); }while (Vector2.Distance(blackHolePosition, _position) < MIN_BLACKHOLE_DISTANCE); }