diff --git a/source/balloon.cpp b/source/balloon.cpp index b25659c..392fcea 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -4,213 +4,213 @@ // Constructor Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, std::vector *buffer, SDL_Renderer *renderer) { - mSprite = new AnimatedSprite(texture, renderer, "", buffer); + sprite = new AnimatedSprite(texture, renderer, "", buffer); disable(); - mEnabled = true; + enabled = true; switch (kind) { case BALLOON_1: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_1; - mHeight = BALLOON_WIDTH_1; - mSize = BALLOON_SIZE_1; - mPower = 1; + width = BALLOON_WIDTH_1; + height = BALLOON_WIDTH_1; + size = BALLOON_SIZE_1; + power = 1; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = 0; - mMaxVelY = 3.0f; - mGravity = 0.09f; - mDefaultVelY = 2.6f; + this->velX = velx; + velY = 0; + maxVelY = 3.0f; + gravity = 0.09f; + defaultVelY = 2.6f; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_1; + score = BALLOON_SCORE_1; // Amenaza que genera el globo - mMenace = 1; + menace = 1; break; case BALLOON_2: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_2; - mHeight = BALLOON_WIDTH_2; - mSize = BALLOON_SIZE_2; - mPower = 3; + width = BALLOON_WIDTH_2; + height = BALLOON_WIDTH_2; + size = BALLOON_SIZE_2; + power = 3; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = 0; - mMaxVelY = 3.0f; - mGravity = 0.10f; - mDefaultVelY = 3.5f; + this->velX = velx; + velY = 0; + maxVelY = 3.0f; + gravity = 0.10f; + defaultVelY = 3.5f; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_2; + score = BALLOON_SCORE_2; // Amenaza que genera el globo - mMenace = 2; + menace = 2; break; case BALLOON_3: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_3; - mHeight = BALLOON_WIDTH_3; - mSize = BALLOON_SIZE_3; - mPower = 7; + width = BALLOON_WIDTH_3; + height = BALLOON_WIDTH_3; + size = BALLOON_SIZE_3; + power = 7; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = 0; - mMaxVelY = 3.0f; - mGravity = 0.10f; - mDefaultVelY = 4.50f; + this->velX = velx; + velY = 0; + maxVelY = 3.0f; + gravity = 0.10f; + defaultVelY = 4.50f; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_3; + score = BALLOON_SCORE_3; // Amenaza que genera el globo - mMenace = 4; + menace = 4; break; case BALLOON_4: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_4; - mHeight = BALLOON_WIDTH_4; - mSize = BALLOON_SIZE_4; - mPower = 15; + width = BALLOON_WIDTH_4; + height = BALLOON_WIDTH_4; + size = BALLOON_SIZE_4; + power = 15; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = 0; - mMaxVelY = 3.0f; - mGravity = 0.10f; - mDefaultVelY = 4.95f; + this->velX = velx; + velY = 0; + maxVelY = 3.0f; + gravity = 0.10f; + defaultVelY = 4.95f; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_4; + score = BALLOON_SCORE_4; // Amenaza que genera el globo - mMenace = 8; + menace = 8; break; case HEXAGON_1: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_1; - mHeight = BALLOON_WIDTH_1; - mSize = BALLOON_SIZE_1; - mPower = 1; + width = BALLOON_WIDTH_1; + height = BALLOON_WIDTH_1; + size = BALLOON_SIZE_1; + power = 1; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = abs(velx) * 2; - mMaxVelY = abs(velx) * 2; - mGravity = 0.00f; - mDefaultVelY = abs(velx) * 2; + this->velX = velx; + velY = abs(velx) * 2; + maxVelY = abs(velx) * 2; + gravity = 0.00f; + defaultVelY = abs(velx) * 2; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_1; + score = BALLOON_SCORE_1; // Amenaza que genera el globo - mMenace = 1; + menace = 1; break; case HEXAGON_2: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_2; - mHeight = BALLOON_WIDTH_2; - mSize = BALLOON_SIZE_2; - mPower = 3; + width = BALLOON_WIDTH_2; + height = BALLOON_WIDTH_2; + size = BALLOON_SIZE_2; + power = 3; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = abs(velx) * 2; - mMaxVelY = abs(velx) * 2; - mGravity = 0.00f; - mDefaultVelY = abs(velx) * 2; + this->velX = velx; + velY = abs(velx) * 2; + maxVelY = abs(velx) * 2; + gravity = 0.00f; + defaultVelY = abs(velx) * 2; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_2; + score = BALLOON_SCORE_2; // Amenaza que genera el globo - mMenace = 2; + menace = 2; break; case HEXAGON_3: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_3; - mHeight = BALLOON_WIDTH_3; - mSize = BALLOON_SIZE_3; - mPower = 7; + width = BALLOON_WIDTH_3; + height = BALLOON_WIDTH_3; + size = BALLOON_SIZE_3; + power = 7; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = abs(velx) * 2; - mMaxVelY = abs(velx) * 2; - mGravity = 0.00f; - mDefaultVelY = abs(velx) * 2; + this->velX = velx; + velY = abs(velx) * 2; + maxVelY = abs(velx) * 2; + gravity = 0.00f; + defaultVelY = abs(velx) * 2; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_3; + score = BALLOON_SCORE_3; // Amenaza que genera el globo - mMenace = 4; + menace = 4; break; case HEXAGON_4: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_4; - mHeight = BALLOON_WIDTH_4; - mSize = BALLOON_SIZE_4; - mPower = 15; + width = BALLOON_WIDTH_4; + height = BALLOON_WIDTH_4; + size = BALLOON_SIZE_4; + power = 15; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = abs(velx) * 2; - mMaxVelY = abs(velx) * 2; - mGravity = 0.00f; - mDefaultVelY = abs(velx) * 2; + this->velX = velx; + velY = abs(velx) * 2; + maxVelY = abs(velx) * 2; + gravity = 0.00f; + defaultVelY = abs(velx) * 2; // Puntos que da el globo al ser destruido - mScore = BALLOON_SCORE_4; + score = BALLOON_SCORE_4; // Amenaza que genera el globo - mMenace = 8; + menace = 8; break; case POWER_BALL: // Alto y ancho del objeto - mWidth = BALLOON_WIDTH_4; - mHeight = BALLOON_WIDTH_4; - mSize = 4; - mPower = 0; + width = BALLOON_WIDTH_4; + height = BALLOON_WIDTH_4; + size = 4; + power = 0; // Inicializa los valores de velocidad y gravedad - mVelX = velx; - mVelY = 0; - mMaxVelY = 3.0f; - mGravity = 0.10f; - mDefaultVelY = 4.95f; + this->velX = velx; + velY = 0; + maxVelY = 3.0f; + gravity = 0.10f; + defaultVelY = 4.95f; // Puntos que da el globo al ser destruido - mScore = 0; + score = 0; // Amenaza que genera el globo - mMenace = 0; + menace = 0; // Añade rotación al sprite - mSprite->setRotate(false); - mSprite->setRotateSpeed(0); - mSprite->setRotateAmount(2.0); + sprite->setRotate(false); + sprite->setRotateSpeed(0); + sprite->setRotateAmount(2.0); break; @@ -219,75 +219,75 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c } // Posición inicial - mPosX = x; - mPosY = y; + posX = x; + posY = y; // Valores para el efecto de rebote - mBouncing.enabled = false; - mBouncing.counter = 0; - mBouncing.speed = 2; - mBouncing.zoomW = 1.0f; - mBouncing.zoomH = 1.0f; - mBouncing.despX = 0.0f; - mBouncing.despY = 0.0f; - mBouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f}; - mBouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f}; + bouncing.enabled = false; + bouncing.counter = 0; + bouncing.speed = 2; + bouncing.zoomW = 1.0f; + bouncing.zoomH = 1.0f; + bouncing.despX = 0.0f; + bouncing.despY = 0.0f; + bouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f}; + bouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f}; // Alto y ancho del sprite - mSprite->setWidth(mWidth); - mSprite->setHeight(mHeight); + sprite->setWidth(width); + sprite->setHeight(height); // Posición X,Y del sprite - mSprite->setPosX((int)mPosX); - mSprite->setPosY((int)mPosY); + sprite->setPosX((int)posX); + sprite->setPosY((int)posY); // Tamaño del circulo de colisión - mCollider.r = mWidth / 2; + collider.r = width / 2; // Alinea el circulo de colisión con el objeto updateColliders(); // Inicializa variables - mStopped = true; - mStoppedCounter = 0; - mBlinking = false; - mVisible = true; - mInvulnerable = true; - mBeingCreated = true; - mCreationCounter = creationtimer; - mCreationCounterIni = creationtimer; - mPopping = false; + stopped = true; + stoppedCounter = 0; + blinking = false; + visible = true; + invulnerable = true; + beingCreated = true; + creationCounter = creationtimer; + creationCounterIni = creationtimer; + popping = false; - mCounter = 0; - mTravelY = 1.0f; - mSpeed = speed; + counter = 0; + travelY = 1.0f; + this->speed = speed; // Tipo - mKind = kind; + this->kind = kind; // Selecciona un frame para pintar - mSprite->setSpriteClip(mSprite->getAnimationClip(0, 0)); + sprite->setSpriteClip(sprite->getAnimationClip(0, 0)); } // Destructor Balloon::~Balloon() { - delete mSprite; + delete sprite; } // Centra el globo en la posición X void Balloon::allignTo(int x) { - mPosX = float(x - (mWidth / 2)); + posX = float(x - (width / 2)); - if (mPosX < PLAY_AREA_LEFT) - mPosX = PLAY_AREA_LEFT + 1; - else if ((mPosX + mWidth) > PLAY_AREA_RIGHT) - mPosX = float(PLAY_AREA_RIGHT - mWidth - 1); + if (posX < PLAY_AREA_LEFT) + posX = PLAY_AREA_LEFT + 1; + else if ((posX + width) > PLAY_AREA_RIGHT) + posX = float(PLAY_AREA_RIGHT - width - 1); // Posición X,Y del sprite - mSprite->setPosX(getPosX()); - mSprite->setPosY(getPosY()); + sprite->setPosX(getPosX()); + sprite->setPosY(getPosY()); // Alinea el circulo de colisión con el objeto updateColliders(); @@ -296,41 +296,41 @@ void Balloon::allignTo(int x) // Pinta el globo en la pantalla void Balloon::render() { - if ((mVisible) && (mEnabled)) + if ((visible) && (enabled)) { - if (mBouncing.enabled) + if (bouncing.enabled) { - if (mKind != POWER_BALL) + if (kind != POWER_BALL) { // Aplica desplazamiento para el zoom - mSprite->setPosX(getPosX() + mBouncing.despX); - mSprite->setPosY(getPosY() + mBouncing.despY); - mSprite->render(); - mSprite->setPosX(getPosX() - mBouncing.despX); - mSprite->setPosY(getPosY() - mBouncing.despY); + sprite->setPosX(getPosX() + bouncing.despX); + sprite->setPosY(getPosY() + bouncing.despY); + sprite->render(); + sprite->setPosX(getPosX() - bouncing.despX); + sprite->setPosY(getPosY() - bouncing.despY); } } else if (isBeingCreated()) { // Aplica alpha blending - mSprite->getTexture()->setAlpha(255 - (int)((float)mCreationCounter * (255.0f / (float)mCreationCounterIni))); - mSprite->render(); - if (mKind == POWER_BALL) + sprite->getTexture()->setAlpha(255 - (int)((float)creationCounter * (255.0f / (float)creationCounterIni))); + sprite->render(); + if (kind == POWER_BALL) { - Sprite *sp = new Sprite(mSprite->getRect(), mSprite->getTexture(), mSprite->getRenderer()); + Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture(), sprite->getRenderer()); sp->setSpriteClip(370, 148, 37, 37); sp->render(); delete sp; } - mSprite->getTexture()->setAlpha(255); + sprite->getTexture()->setAlpha(255); } else { - mSprite->render(); + sprite->render(); - if (mKind == POWER_BALL and !mPopping) + if (kind == POWER_BALL and !popping) { - Sprite *sp = new Sprite(mSprite->getRect(), mSprite->getTexture(), mSprite->getRenderer()); + Sprite *sp = new Sprite(sprite->getRect(), sprite->getTexture(), sprite->getRenderer()); sp->setSpriteClip(370, 148, 37, 37); sp->render(); delete sp; @@ -346,57 +346,57 @@ void Balloon::move() if (!isStopped()) { // Lo mueve a izquierda o derecha - mPosX += (mVelX * mSpeed); + posX += (velX * speed); // Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido - if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT)) + if ((posX < PLAY_AREA_LEFT) || (posX + width > PLAY_AREA_RIGHT)) { // Corrige posición - mPosX -= (mVelX * mSpeed); + posX -= (velX * speed); // Invierte sentido - mVelX = -mVelX; + velX = -velX; // Invierte la rotación - mSprite->switchRotate(); + sprite->switchRotate(); // Activa el efecto de rebote - if (mKind != POWER_BALL) + if (kind != POWER_BALL) { bounceStart(); } } // Mueve el globo hacia arriba o hacia abajo - mPosY += (mVelY * mSpeed); + posY += (velY * speed); // Si se sale por arriba - if (mPosY < PLAY_AREA_TOP) + if (posY < PLAY_AREA_TOP) { // Corrige - mPosY = PLAY_AREA_TOP; + posY = PLAY_AREA_TOP; // Invierte sentido - mVelY = -mVelY; + velY = -velY; // Activa el efecto de rebote - if (mKind != POWER_BALL) + if (kind != POWER_BALL) { bounceStart(); } } // Si el globo se sale por la parte inferior - if (mPosY + mHeight > PLAY_AREA_BOTTOM) + if (posY + height > PLAY_AREA_BOTTOM) { // Corrige - mPosY = PLAY_AREA_BOTTOM - mHeight; + posY = PLAY_AREA_BOTTOM - height; // Invierte colocando una velocidad por defecto - mVelY = -mDefaultVelY; + velY = -defaultVelY; // Activa el efecto de rebote - if (mKind != POWER_BALL) + if (kind != POWER_BALL) { bounceStart(); } @@ -412,85 +412,84 @@ void Balloon::move() */ // Incrementa la variable que calcula la distancia acumulada en Y - mTravelY += mSpeed; + travelY += speed; // Si la distancia acumulada en Y es igual a la velocidad, se aplica la gravedad - if (mTravelY >= 1.0f) + if (travelY >= 1.0f) { // Quita el excedente - mTravelY -= 1.0f; + travelY -= 1.0f; // Aplica la gravedad al objeto sin pasarse de una velocidad máxima - mVelY += mGravity; - std::min(mVelY, mMaxVelY); + velY += gravity; + std::min(velY, maxVelY); } // Actualiza la posición del sprite - mSprite->setPosX(getPosX()); - mSprite->setPosY(getPosY()); + sprite->setPosX(getPosX()); + sprite->setPosY(getPosY()); } } // Deshabilita el globo y pone a cero todos los valores void Balloon::disable() { - mBeingCreated = false; - mBlinking = false; - mCollider.r = 0; - mCollider.x = 0; - mCollider.y = 0; - mCounter = 0; - mCreationCounter = 0; - mCreationCounterIni = 0; - mDefaultVelY = 0.0f; - mEnabled = false; - mGravity = 0.0f; - mHeight = 0; - mInvulnerable = false; - mKind = 0; - mMaxVelY = 0.0f; - mMenace = 0; - mPopping = false; - mPosX = 0.0f; - mPosY = 0.0f; - mPower = 0; - mScore = 0; - mSize = 0; - mSpeed = 0; - mStopped = false; - mStoppedCounter = 0; - // mTimeToLive = 0; - mTravelY = 0; - mVelX = 0.0f; - mVelY = 0.0f; - mVisible = false; - mWidth = 0; - mSprite->clear(); + beingCreated = false; + blinking = false; + collider.r = 0; + collider.x = 0; + collider.y = 0; + counter = 0; + creationCounter = 0; + creationCounterIni = 0; + defaultVelY = 0.0f; + enabled = false; + gravity = 0.0f; + height = 0; + invulnerable = false; + kind = 0; + maxVelY = 0.0f; + menace = 0; + popping = false; + posX = 0.0f; + posY = 0.0f; + power = 0; + score = 0; + size = 0; + speed = 0; + stopped = false; + stoppedCounter = 0; + travelY = 0; + velX = 0.0f; + velY = 0.0f; + visible = false; + width = 0; + sprite->clear(); } // Explosiona el globo void Balloon::pop() { setPopping(true); - mSprite->disableRotate(); + sprite->disableRotate(); setStop(true); setStoppedTimer(2000); setInvulnerable(true); - mMenace = 0; + menace = 0; } // Actualiza al globo a su posicion, animación y controla los contadores void Balloon::update() { - if (mEnabled) + if (enabled) { - mSprite->MovingSprite::update(); + sprite->MovingSprite::update(); move(); updateAnimation(); updateColliders(); updateState(); updateBounce(); - mCounter++; + counter++; } } @@ -502,20 +501,11 @@ void Balloon::updateState() { setInvulnerable(true); setStop(true); - if (mSprite->animationIsCompleted()) - { - // mSprite->setAnimationCompleted(BALLOON_POP_ANIMATION, false); - // mTimeToLive = 0; - disable(); - } - /*else if (mTimeToLive > 0) - { - mTimeToLive--; - } - else + if (sprite->animationIsCompleted()) { disable(); - }*/ + } + } // Si se está creando @@ -526,31 +516,31 @@ void Balloon::updateState() setInvulnerable(true); // Todavia tiene tiempo en el contador - if (mCreationCounter > 0) + if (creationCounter > 0) { // Desplaza lentamente el globo hacia abajo y hacia un lado - if (mCreationCounter % 10 == 0) + if (creationCounter % 10 == 0) { - mPosY++; - mPosX += mVelX; + posY++; + posX += velX; // Comprueba no se salga por los laterales - if ((mPosX < PLAY_AREA_LEFT) || (mPosX > (PLAY_AREA_RIGHT - mWidth))) + if ((posX < PLAY_AREA_LEFT) || (posX > (PLAY_AREA_RIGHT - width))) { // Corrige y cambia el sentido de la velocidad - mPosX -= mVelX; - mVelX = -mVelX; + posX -= velX; + velX = -velX; } // Actualiza la posición del sprite - mSprite->setPosX(getPosX()); - mSprite->setPosY(getPosY()); + sprite->setPosX(getPosX()); + sprite->setPosY(getPosY()); // Actualiza la posición del circulo de colisión updateColliders(); } - mCreationCounter--; + creationCounter--; } // El contador ha llegado a cero else @@ -559,16 +549,16 @@ void Balloon::updateState() setStop(false); setVisible(true); setInvulnerable(false); - if (mKind == POWER_BALL) + if (kind == POWER_BALL) { - mSprite->setRotate(true); - if (mVelX > 0.0f) + sprite->setRotate(true); + if (velX > 0.0f) { - mSprite->setRotateAmount(2.0); + sprite->setRotateAmount(2.0); } else { - mSprite->setRotateAmount(-2.0); + sprite->setRotateAmount(-2.0); } } } @@ -577,9 +567,9 @@ void Balloon::updateState() else if (isStopped()) { // Si está detenido, reduce el contador - if (mStoppedCounter > 0) + if (stoppedCounter > 0) { - mStoppedCounter--; + stoppedCounter--; } // Si el contador ha llegado a cero, ya no está detenido else if (!isPopping()) @@ -595,7 +585,7 @@ void Balloon::updateAnimation() std::string creatingAnimation = "blue"; std::string normalAnimation = "orange"; - if (mKind == POWER_BALL) + if (kind == POWER_BALL) { creatingAnimation = "powerball"; normalAnimation = "powerball"; @@ -609,88 +599,89 @@ void Balloon::updateAnimation() // Establece el frame de animación if (isPopping()) { - mSprite->setCurrentAnimation("pop"); + sprite->setCurrentAnimation("pop"); } else if (isBeingCreated()) { - mSprite->setCurrentAnimation(creatingAnimation); + sprite->setCurrentAnimation(creatingAnimation); } else { - mSprite->setCurrentAnimation(normalAnimation); + sprite->setCurrentAnimation(normalAnimation); } - mSprite->animate(); + sprite->animate(); } // Comprueba si el globo está habilitado bool Balloon::isEnabled() { - return mEnabled; + return enabled; } // Obtiene del valor de la variable float Balloon::getPosX() { - return mPosX; + return posX; } // Obtiene del valor de la variable float Balloon::getPosY() { - return mPosY; + return posY; } // Obtiene del valor de la variable float Balloon::getVelY() { - return mVelY; + return velY; } // Obtiene del valor de la variable int Balloon::getWidth() { - return mWidth; + return width; } // Obtiene del valor de la variable int Balloon::getHeight() { - return mHeight; + return height; } // Establece el valor de la variable void Balloon::setVelY(float velY) { - mVelY = velY; + this->velY = velY; } // Establece el valor de la variable void Balloon::setSpeed(float speed) { - mSpeed = speed; + this->speed = speed; } // Obtiene del valor de la variable int Balloon::getKind() { - return mKind; + return kind; } // Obtiene del valor de la variable Uint8 Balloon::getSize() { - return mSize; + return size; } // Obtiene la clase a la que pertenece el globo Uint8 Balloon::getClass() { - if ((mKind >= BALLOON_1) && (mKind <= BALLOON_4)) + if ((kind >= BALLOON_1) && (kind <= BALLOON_4)) { return BALLOON_CLASS; } - else if ((mKind >= HEXAGON_1) && (mKind <= HEXAGON_4)) + + else if ((kind >= HEXAGON_1) && (kind <= HEXAGON_4)) { return HEXAGON_CLASS; } @@ -701,104 +692,104 @@ Uint8 Balloon::getClass() // Establece el valor de la variable void Balloon::setStop(bool state) { - mStopped = state; + stopped = state; } // Obtiene del valor de la variable bool Balloon::isStopped() { - return mStopped; + return stopped; } // Establece el valor de la variable -void Balloon::setBlink(bool state) +void Balloon::setBlink(bool value) { - mBlinking = state; + blinking = value; } // Obtiene del valor de la variable bool Balloon::isBlinking() { - return mBlinking; + return blinking; } // Establece el valor de la variable -void Balloon::setVisible(bool state) +void Balloon::setVisible(bool value) { - mVisible = state; + visible = value; } // Obtiene del valor de la variable bool Balloon::isVisible() { - return mVisible; + return visible; } // Establece el valor de la variable -void Balloon::setInvulnerable(bool state) +void Balloon::setInvulnerable(bool value) { - mInvulnerable = state; + invulnerable = value; } // Obtiene del valor de la variable bool Balloon::isInvulnerable() { - return mInvulnerable; + return invulnerable; } // Establece el valor de la variable -void Balloon::setBeingCreated(bool state) +void Balloon::setBeingCreated(bool value) { - mBeingCreated = state; + beingCreated = value; } // Obtiene del valor de la variable bool Balloon::isBeingCreated() { - return mBeingCreated; + return beingCreated; } // Establece el valor de la variable -void Balloon::setPopping(bool state) +void Balloon::setPopping(bool value) { - mPopping = state; + popping = value; } // Obtiene del valor de la variable bool Balloon::isPopping() { - return mPopping; + return popping; } // Establece el valor de la variable void Balloon::setStoppedTimer(Uint16 time) { - mStoppedCounter = time; + stoppedCounter = time; } // Obtiene del valor de la variable Uint16 Balloon::getStoppedTimer() { - return mStoppedCounter; + return stoppedCounter; } // Obtiene del valor de la variable Uint16 Balloon::getScore() { - return mScore; + return score; } // Obtiene el circulo de colisión circle_t &Balloon::getCollider() { - return mCollider; + return collider; } // Alinea el circulo de colisión con la posición del objeto globo void Balloon::updateColliders() { - mCollider.x = Uint16(mPosX + mCollider.r); - mCollider.y = mPosY + mCollider.r; + collider.x = Uint16(posX + collider.r); + collider.y = posY + collider.r; } // Obtiene le valor de la variable @@ -806,7 +797,7 @@ Uint8 Balloon::getMenace() { if (isEnabled()) { - return mMenace; + return menace; } else { @@ -817,44 +808,44 @@ Uint8 Balloon::getMenace() // Obtiene le valor de la variable Uint8 Balloon::getPower() { - return mPower; + return power; } void Balloon::bounceStart() { - mBouncing.enabled = true; - mBouncing.zoomW = 1; - mBouncing.zoomH = 1; - mSprite->setZoomW(mBouncing.zoomW); - mSprite->setZoomH(mBouncing.zoomH); - mBouncing.despX = 0; - mBouncing.despY = 0; + bouncing.enabled = true; + bouncing.zoomW = 1; + bouncing.zoomH = 1; + sprite->setZoomW(bouncing.zoomW); + sprite->setZoomH(bouncing.zoomH); + bouncing.despX = 0; + bouncing.despY = 0; } void Balloon::bounceStop() { - mBouncing.enabled = false; - mBouncing.counter = 0; - mBouncing.zoomW = 1.0f; - mBouncing.zoomH = 1.0f; - mSprite->setZoomW(mBouncing.zoomW); - mSprite->setZoomH(mBouncing.zoomH); - mBouncing.despX = 0.0f; - mBouncing.despY = 0.0f; + bouncing.enabled = false; + bouncing.counter = 0; + bouncing.zoomW = 1.0f; + bouncing.zoomH = 1.0f; + sprite->setZoomW(bouncing.zoomW); + sprite->setZoomH(bouncing.zoomH); + bouncing.despX = 0.0f; + bouncing.despY = 0.0f; } void Balloon::updateBounce() { - if (mBouncing.enabled) + if (bouncing.enabled) { - mBouncing.zoomW = mBouncing.w.at(mBouncing.counter / mBouncing.speed); - mBouncing.zoomH = mBouncing.h.at(mBouncing.counter / mBouncing.speed); - mSprite->setZoomW(mBouncing.zoomW); - mSprite->setZoomH(mBouncing.zoomH); - mBouncing.despX = (mSprite->getSpriteClip().w - (mSprite->getSpriteClip().w * mBouncing.zoomW)); - mBouncing.despY = (mSprite->getSpriteClip().h - (mSprite->getSpriteClip().h * mBouncing.zoomH)); - mBouncing.counter++; - if ((mBouncing.counter / mBouncing.speed) > (MAX_BOUNCE - 1)) + bouncing.zoomW = bouncing.w.at(bouncing.counter / bouncing.speed); + bouncing.zoomH = bouncing.h.at(bouncing.counter / bouncing.speed); + sprite->setZoomW(bouncing.zoomW); + sprite->setZoomH(bouncing.zoomH); + bouncing.despX = (sprite->getSpriteClip().w - (sprite->getSpriteClip().w * bouncing.zoomW)); + bouncing.despY = (sprite->getSpriteClip().h - (sprite->getSpriteClip().h * bouncing.zoomH)); + bouncing.counter++; + if ((bouncing.counter / bouncing.speed) > (MAX_BOUNCE - 1)) { bounceStop(); } diff --git a/source/balloon.h b/source/balloon.h index e19f6d7..f093918 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -86,37 +86,39 @@ private: std::vector h; // Vector con los valores de zoom para el alto del globo }; - float mPosX; // Posición en el eje X - float mPosY; // Posición en el eje Y - Uint8 mWidth; // Ancho - Uint8 mHeight; // Alto - float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse - float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse - float mGravity; // Aceleración en el eje Y. Modifica la velocidad - float mDefaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo - float mMaxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y - AnimatedSprite *mSprite; // Sprite del objeto globo - bool mBeingCreated; // Indica si el globo se está creando - bool mBlinking; // Indica si el globo está intermitente - bool mEnabled; // Indica si el globo esta activo - bool mInvulnerable; // Indica si el globo es invulnerable - bool mPopping; // Indica si el globo está explotando - bool mStopped; // Indica si el globo está parado - bool mVisible; // Indica si el globo es visible - circle_t mCollider; // Circulo de colisión del objeto - Uint16 mCreationCounter; // Temporizador para controlar el estado "creandose" - Uint16 mCreationCounterIni; // Valor inicial para el temporizador para controlar el estado "creandose" - Uint16 mScore; // Puntos que da el globo al ser destruido - Uint16 mStoppedCounter; // Contador para controlar el estado "parado" - // Uint16 mTimeToLive; // Indica el tiempo de vida que le queda al globo - Uint8 mKind; // Tipo de globo - Uint8 mMenace; // Cantidad de amenaza que genera el globo - Uint32 mCounter; // Contador interno - float mTravelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad - float mSpeed; // Velocidad a la que se mueven los globos - Uint8 mSize; // Tamaño del globo - Uint8 mPower; // Cantidad de poder que alberga el globo - bouncing mBouncing; // Contiene las variables para el efecto de rebote + // Objetos + AnimatedSprite *sprite; // Sprite del objeto globo + + // Variables + float posX; // Posición en el eje X + float posY; // Posición en el eje Y + Uint8 width; // Ancho + Uint8 height; // Alto + float velX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse + float velY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse + float gravity; // Aceleración en el eje Y. Modifica la velocidad + float defaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo + float maxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y + bool beingCreated; // Indica si el globo se está creando + bool blinking; // Indica si el globo está intermitente + bool enabled; // Indica si el globo esta activo + bool invulnerable; // Indica si el globo es invulnerable + bool popping; // Indica si el globo está explotando + bool stopped; // Indica si el globo está parado + bool visible; // Indica si el globo es visible + circle_t collider; // Circulo de colisión del objeto + Uint16 creationCounter; // Temporizador para controlar el estado "creandose" + Uint16 creationCounterIni; // Valor inicial para el temporizador para controlar el estado "creandose" + Uint16 score; // Puntos que da el globo al ser destruido + Uint16 stoppedCounter; // Contador para controlar el estado "parado" + Uint8 kind; // Tipo de globo + Uint8 menace; // Cantidad de amenaza que genera el globo + Uint32 counter; // Contador interno + float travelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad + float speed; // Velocidad a la que se mueven los globos + Uint8 size; // Tamaño del globo + Uint8 power; // Cantidad de poder que alberga el globo + bouncing bouncing; // Contiene las variables para el efecto de rebote // Alinea el circulo de colisión con la posición del objeto globo void updateColliders(); @@ -137,7 +139,7 @@ private: void updateAnimation(); // Establece el valor de la variable - void setBeingCreated(bool state); + void setBeingCreated(bool value); public: // Constructor @@ -198,25 +200,25 @@ public: Uint8 getClass(); // Establece el valor de la variable - void setStop(bool state); + void setStop(bool value); // Obtiene del valor de la variable bool isStopped(); // Establece el valor de la variable - void setBlink(bool state); + void setBlink(bool value); // Obtiene del valor de la variable bool isBlinking(); // Establece el valor de la variable - void setVisible(bool state); + void setVisible(bool value); // Obtiene del valor de la variable bool isVisible(); // Establece el valor de la variable - void setInvulnerable(bool state); + void setInvulnerable(bool value); // Obtiene del valor de la variable bool isInvulnerable(); @@ -225,7 +227,7 @@ public: bool isBeingCreated(); // Establece el valor de la variable - void setPopping(bool state); + void setPopping(bool value); // Obtiene del valor de la variable bool isPopping(); diff --git a/source/bullet.cpp b/source/bullet.cpp index 3937a0a..0fb500a 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -104,7 +104,7 @@ Uint8 Bullet::move() posX += velX; // Si el objeto se sale del area de juego por los laterales - if ((posX < PLAY_AREA_LEFT) || (posX + width > PLAY_AREA_RIGHT)) + if ((posX < PLAY_AREA_LEFT - width) || (posX > PLAY_AREA_RIGHT)) { // Se deshabilita kind = NO_KIND; @@ -116,8 +116,8 @@ Uint8 Bullet::move() // Mueve el objeto a su nueva posición en vertical posY += int(velY); - // Si el objeto se sale del area de juego por la parte superior o inferior - if ((posY < PLAY_AREA_TOP) || (posY + height > PLAY_AREA_BOTTOM)) + // Si el objeto se sale del area de juego por la parte superior + if (posY < PLAY_AREA_TOP - height) { // Se deshabilita kind = NO_KIND; diff --git a/todo.txt b/todo.txt index f59af29..77a3f41 100644 --- a/todo.txt +++ b/todo.txt @@ -11,4 +11,5 @@ arreglar los items de las instrucciones que cicle la musica en el titulo, demo, instrucciones que guarde el progreso del juego que aumente la velocidad de las nubes conforme avanzas -retocar un poco la distancia entre los cambios de color del cielo, se llega al oscuro muy pronto \ No newline at end of file +retocar un poco la distancia entre los cambios de color del cielo, se llega al oscuro muy pronto +las balas deberian llegar a salir de la pantalla \ No newline at end of file