// Metodo de inserção aleatoria de tipo e rua dos obstaculos public void spawnNewObstacle(GraphicsDevice device, List <Obstacles> obstacles, List <float> validLines, float aceleretionToRigth, float acelerationToLeft) { Obstacles cart; // Seleciona aleatoriamente um tipo de carroça int typeOfCart = random.Next(Constants.beginType, Constants.endType); switch (typeOfCart) { case 1: cart = new Obstacles(device, Constants.redCartSprites, scale); break; case 2: cart = new Obstacles(device, Constants.greenCartSprites, scale); break; default: cart = new Obstacles(device, Constants.purpleCartSprites, scale); break; } int streeat = random.Next(Constants.beginStreat, Constants.endStreat); //Seleciona aleatoriamente uma rua para a coarroça // Cuida pra não por duas carroças seguidas na mesma rua if (lastInserts.Count != Constants.zero) { while (lastInserts[lastInserts.Count - Constants.one] == streeat) { streeat = random.Next(Constants.beginStreat, Constants.endStreat); } } cart.setStreat(streeat); cart.setY(validLines[streeat - Constants.one]); if (streeat % Constants.two != Constants.zero) { cart.setX(streeLeftLimit); cart.setDx((float)(aceleretionToRigth * (Constants.acelerationFactor * (streeat + Constants.two)))); cart.setAngle(Constants.angleObstacleToRigth); } else { cart.setX(streeRigthLimit); cart.setDx((float)(acelerationToLeft * (Constants.acelerationFactor * (streeat + Constants.two)))); cart.setAngle(Constants.angleObstacleToLeft); } if (validLines.Contains(cart.getY())) { lastInserts.Add(streeat); obstacles.Add(cart); } }
// Metodo que realiza a troca de pista de um determinado obstaculo de forma aleatoria private void changeStreet(List <Obstacles> obstacles, List <float> validLines, float aceleretionToRigth, float acelerationToLeft) { int limit = obstacles.Count; if (limit > Constants.lessNumberToChangeStreat) { int position = random.Next(Constants.beginStreat, limit); int streeat = random.Next(Constants.beginStreat, Constants.endStreat); Obstacles obstacle = obstacles[position]; int originalstreat = obstacle.getStreat(); float originalY = obstacle.getY(); float originalDx = obstacle.getDx(); float originalAngle = obstacle.getAngle(); while (obstacle.getStreat() == streeat) { streeat = random.Next(Constants.beginStreat, Constants.endStreat); } obstacle.setStreat(streeat); obstacle.setY(validLines[streeat - Constants.one]); if (streeat % 2 != 0) { obstacle.setDx((float)(aceleretionToRigth * (Constants.acelerationFactor * (streeat + Constants.two)))); obstacle.setAngle(Constants.angleObstacleToRigth); } else { obstacle.setDx((float)(acelerationToLeft * (Constants.acelerationFactor * (streeat + Constants.two)))); obstacle.setAngle(Constants.angleObstacleToLeft); } if (obstacle.verifyColisionObsttacleWithObstacles(obstacles, position)) { obstacle.setStreat(originalstreat); obstacle.setY(originalY); obstacle.setDx(originalDx); obstacle.setAngle(originalAngle); } } }
// Verifica colisão do player com um determido obstaculo private bool verifyColisionWithSpecificObstacle(Obstacles obstaclesSprite) { if (this.x + this.texture.Width * this.scale * Constants.HitBoxPlayer / Constants.two < obstaclesSprite.getX() - obstaclesSprite.getTexture().Width *obstaclesSprite.getScale() / Constants.two) { return(false); } if (this.y + this.texture.Height * this.scale * Constants.HitBoxPlayer / Constants.two < obstaclesSprite.getY() - obstaclesSprite.getTexture().Height *obstaclesSprite.getScale() / Constants.two) { return(false); } if (this.x - this.texture.Width * this.scale * Constants.HitBoxPlayer / Constants.two > obstaclesSprite.getX() + obstaclesSprite.getTexture().Width *obstaclesSprite.getScale() / Constants.two) { return(false); } if (this.y - this.texture.Height * this.scale * Constants.HitBoxPlayer / Constants.two > obstaclesSprite.getY() + obstaclesSprite.getTexture().Height *obstaclesSprite.getScale() / Constants.two) { return(false); } return(true); }