añadido a param.txt los parametros de los globos para velocidad y gravedad
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
#include "balloon.h"
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer)
|
||||
Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, param_t *param)
|
||||
{
|
||||
this->param = param;
|
||||
sprite = new AnimatedSprite(texture, "", animation);
|
||||
disable();
|
||||
|
||||
@@ -22,8 +23,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
|
||||
this->velX = velx;
|
||||
velY = 0;
|
||||
maxVelY = 3.0f;
|
||||
gravity = 0.09f;
|
||||
defaultVelY = 2.6f;
|
||||
gravity = param->balloon1.grav;
|
||||
defaultVelY = param->balloon1.vel;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score = BALLOON_SCORE_1;
|
||||
@@ -44,8 +45,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
|
||||
this->velX = velx;
|
||||
velY = 0;
|
||||
maxVelY = 3.0f;
|
||||
gravity = 0.10f;
|
||||
defaultVelY = 3.5f;
|
||||
gravity = param->balloon2.grav;
|
||||
defaultVelY = param->balloon2.vel;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score = BALLOON_SCORE_2;
|
||||
@@ -66,8 +67,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
|
||||
this->velX = velx;
|
||||
velY = 0;
|
||||
maxVelY = 3.0f;
|
||||
gravity = 0.10f;
|
||||
defaultVelY = 4.50f;
|
||||
gravity = param->balloon3.grav;
|
||||
defaultVelY = param->balloon3.vel;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score = BALLOON_SCORE_3;
|
||||
@@ -88,8 +89,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
|
||||
this->velX = velx;
|
||||
velY = 0;
|
||||
maxVelY = 3.0f;
|
||||
gravity = 0.10f;
|
||||
defaultVelY = 4.95f;
|
||||
gravity = param->balloon4.grav;
|
||||
defaultVelY = param->balloon4.vel;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score = BALLOON_SCORE_4;
|
||||
|
||||
@@ -85,6 +85,7 @@ private:
|
||||
|
||||
// Objetos y punteros
|
||||
AnimatedSprite *sprite; // Sprite del objeto globo
|
||||
param_t *param; // Puntero con todos los parametros del programa
|
||||
|
||||
// Variables
|
||||
float posX; // Posición en el eje X
|
||||
@@ -139,7 +140,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, SDL_Renderer *renderer);
|
||||
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, std::vector<std::string> *animation, param_t *param);
|
||||
|
||||
// Destructor
|
||||
~Balloon();
|
||||
|
||||
@@ -171,6 +171,13 @@ struct options_t
|
||||
std::vector<op_controller_t> controller; // Opciones con las asignaciones del mando para cada jugador
|
||||
};
|
||||
|
||||
// Estructura para guardar los parametros de un globo
|
||||
struct balloon_t
|
||||
{
|
||||
float grav; // Aceleración en el eje Y. Modifica la velocidad
|
||||
float vel; // Velocidad inicial que tienen al rebotar contra el suelo
|
||||
};
|
||||
|
||||
// Estructura para almacenar todos los parámetros del juego
|
||||
struct param_t
|
||||
{
|
||||
@@ -199,6 +206,9 @@ struct param_t
|
||||
// BACKGROUND
|
||||
color_t backgroundAttenuateColor;
|
||||
int backgroundAttenuateAlpha;
|
||||
|
||||
// BALLOONS
|
||||
balloon_t balloon1, balloon2, balloon3, balloon4; // Parametros de velocidad y gravedad de cada tipo de globo
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros de sonido y su nombre
|
||||
|
||||
@@ -1071,7 +1071,7 @@ void Game::renderBalloons()
|
||||
int Game::createBalloon(float x, int y, int kind, float velx, float speed, int creationtimer)
|
||||
{
|
||||
const int index = (kind - 1) % 4;
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index], renderer);
|
||||
Balloon *b = new Balloon(x, y, kind, velx, speed, creationtimer, balloonTextures[index], balloonAnimations[index], param);
|
||||
balloons.push_back(b);
|
||||
return (int)(balloons.size() - 1);
|
||||
}
|
||||
@@ -1089,7 +1089,7 @@ void Game::createPowerBall()
|
||||
const int x[3] = {left, center, right};
|
||||
const float vx[3] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE};
|
||||
|
||||
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloonTextures[4], balloonAnimations[4], renderer);
|
||||
Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloonTextures[4], balloonAnimations[4], param);
|
||||
balloons.push_back(b);
|
||||
|
||||
powerBallEnabled = true;
|
||||
|
||||
@@ -33,6 +33,16 @@ void initParam(param_t *param)
|
||||
// BACKGROUND
|
||||
param->backgroundAttenuateColor = {255, 255, 255};
|
||||
param->backgroundAttenuateAlpha = 32;
|
||||
|
||||
// BALLOONS
|
||||
param->balloon1.vel = 2.60f;
|
||||
param->balloon1.grav = 0.09f;
|
||||
param->balloon2.vel = 3.50f;
|
||||
param->balloon2.grav = 0.10f;
|
||||
param->balloon3.vel = 4.50f;
|
||||
param->balloon3.grav = 0.10f;
|
||||
param->balloon4.vel = 4.95f;
|
||||
param->balloon4.grav = 0.10f;
|
||||
}
|
||||
|
||||
// Establece valores para los parametros a partir de un fichero de texto
|
||||
@@ -238,6 +248,47 @@ bool setOptions(param_t *param, std::string var, std::string value)
|
||||
param->backgroundAttenuateAlpha = std::stoi(value);
|
||||
}
|
||||
|
||||
// BALLOON
|
||||
else if (var == "balloon1.vel")
|
||||
{
|
||||
param->balloon1.vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon1.grav")
|
||||
{
|
||||
param->balloon1.grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon2.vel")
|
||||
{
|
||||
param->balloon2.vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon2.grav")
|
||||
{
|
||||
param->balloon2.grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon3.vel")
|
||||
{
|
||||
param->balloon3.vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon3.grav")
|
||||
{
|
||||
param->balloon3.grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon4.vel")
|
||||
{
|
||||
param->balloon4.vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon4.grav")
|
||||
{
|
||||
param->balloon4.grav = std::stof(value);
|
||||
}
|
||||
|
||||
// RESTO
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user