private void SpawnRandomObstacle() { // TODO: Create instance of obstacle and add it to entity manager Obstacle obstacle = null; int cactusGroupSpawnRate = 75; int flyingDinoSpawnRate = _scoreBoard.Score >= FLYING_DINO_SPAWN_SCORE_MIN ? 25 : 0; int rng = _random.Next(0, cactusGroupSpawnRate + flyingDinoSpawnRate + 1); if (rng <= cactusGroupSpawnRate) { CactusGroup.GroupSize randomGroupSize = (CactusGroup.GroupSize)_random.Next((int)CactusGroup.GroupSize.Small, (int)CactusGroup.GroupSize.Large + 1); bool isLarge = _random.NextDouble() > 0.5f; float posY = isLarge ? LARGE_CACTUS_POS_Y : SMALL_CACTUS_POS_Y; obstacle = new CactusGroup(_spriteSheet, isLarge, randomGroupSize, _trex, new Vector2(TRexRunnerGame.WINDOW_WIDTH, posY)); } else { int verticalPosIndex = _random.Next(0, FLYING_DINO_Y_POSITIONS.Length); float posY = FLYING_DINO_Y_POSITIONS[verticalPosIndex]; obstacle = new FlyingDino(_trex, new Vector2(TRexRunnerGame.WINDOW_WIDTH, posY), _spriteSheet); } obstacle.DrawOrder = OBSTACLE_DRAW_ORDER; _entityManager.AddEntity(obstacle); }
private void SpawnRandomObstacle() { //TODO: Object instance creation, add to em Obstacle obstacle = null; float cactusGroupSpawnRate = 0.7f; float dinoSpawnRate = _scoreBoard.Score >= FLYING_DINO_SCORE_MIN ? 0.25f : 0; float spawnGroup = (float)_random.NextDouble(); if (spawnGroup <= cactusGroupSpawnRate || dinoSpawnRate == 0) { CactusGroup.GroupSize randomGroupSize = (CactusGroup.GroupSize)_random.Next((int)CactusGroup.GroupSize.Small, (int)CactusGroup.GroupSize.Large + 1); bool cactusType = _random.NextDouble() > 0.5; obstacle = new CactusGroup(_spriteSheet, cactusType, randomGroupSize, _trex, new Vector2(TrexRunner.WINDOW_WIDTH, SPAWN_Y_LEVEL), _gd); } else if (spawnGroup > cactusGroupSpawnRate && spawnGroup < 1f) { int vertialPosIndex = _random.Next(0, FLYING_DINO_Y_POSITIONS.Length); float posY = FLYING_DINO_Y_POSITIONS[vertialPosIndex]; obstacle = new FlyingDino(_trex, new Vector2(TrexRunner.WINDOW_WIDTH, posY), _spriteSheet); } obstacle.DrawOrder = OBSTACLE_DRAW_ORDER; _entityManager.AddEntity(obstacle); }
private void SpawnRandomObstacle() { Obstacle obstacle; CactusGroup.GroupSize randomGroupSize = (CactusGroup.GroupSize)_random.Next((int)CactusGroup.GroupSize.Small, (int)CactusGroup.GroupSize.Large + 1); bool isLarge = _random.NextDouble() > 0.5f; float posY = isLarge ? LARGE_CACTUS_POS_Y : SMALL_CACTUS_POS_Y; obstacle = new CactusGroup(_spriteSheet, isLarge, randomGroupSize, _trex, new Vector2(TRexRunnerGame.WINDOW_WIDTH, posY)); obstacle.DrawOrder = OBSTACLE_DRAW_ORDER; _entityManager.AddEntity(obstacle); }