diff --git a/data/gfx/new_player1_body.ani b/data/gfx/new_player1_body.ani index 4b3b378..8ef25af 100644 --- a/data/gfx/new_player1_body.ani +++ b/data/gfx/new_player1_body.ani @@ -52,7 +52,7 @@ frames=24,25,26,27 [animation] name=centershoot -speed=10 +speed=5 loop=0 frames=28,29,30,31 [/animation] @@ -66,7 +66,7 @@ frames=32,33,34,35 [animation] name=centershoot_1C -speed=10 +speed=5 loop=0 frames=36,37,38,39 [/animation] @@ -80,7 +80,7 @@ frames=40,41,42,43 [animation] name=centershoot_2C -speed=10 +speed=5 loop=0 frames=44,45,46,47 [/animation] \ No newline at end of file diff --git a/data/gfx/new_player1_head.ani b/data/gfx/new_player1_head.ani index c0f6e45..45986ed 100644 --- a/data/gfx/new_player1_head.ani +++ b/data/gfx/new_player1_head.ani @@ -66,7 +66,7 @@ frames=32,33,34,35 [animation] name=centershoot -speed=10 +speed=5 loop=0 frames=36,37,38,39 [/animation] @@ -80,7 +80,7 @@ frames=40,41,42,43 [animation] name=centershoot_1C -speed=10 +speed=5 loop=0 frames=44,45,46,47 [/animation] @@ -94,7 +94,7 @@ frames=48,49,50,51 [animation] name=centershoot_pwr -speed=10 +speed=5 loop=0 frames=52,53,54,55 [/animation] @@ -108,7 +108,7 @@ frames=56,57,58,59 [animation] name=centershoot_1C_pwr -speed=10 +speed=5 loop=0 frames=60,61,62,63 [/animation] \ No newline at end of file diff --git a/source/balloon.cpp b/source/balloon.cpp index 392fcea..c5941ea 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -210,7 +210,14 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c // Añade rotación al sprite sprite->setRotate(false); sprite->setRotateSpeed(0); - sprite->setRotateAmount(2.0); + if (velX > 0.0f) + { + sprite->setRotateAmount(2.0); + } + else + { + sprite->setRotateAmount(-2.0); + } break; @@ -258,15 +265,16 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c creationCounterIni = creationtimer; popping = false; + // Actualiza valores + beingCreated = creationCounter == 0 ? false : true; + invulnerable = beingCreated == false ? false : true; + counter = 0; travelY = 1.0f; this->speed = speed; // Tipo this->kind = kind; - - // Selecciona un frame para pintar - sprite->setSpriteClip(sprite->getAnimationClip(0, 0)); } // Destructor @@ -505,7 +513,6 @@ void Balloon::updateState() { disable(); } - } // Si se está creando @@ -552,28 +559,32 @@ void Balloon::updateState() if (kind == POWER_BALL) { sprite->setRotate(true); - if (velX > 0.0f) - { - sprite->setRotateAmount(2.0); - } - else - { - sprite->setRotateAmount(-2.0); - } } } } // Solo comprueba el estado detenido cuando no se está creando else if (isStopped()) { - // Si está detenido, reduce el contador + // Si es una powerball deja de rodar + if (kind == POWER_BALL) + { + sprite->setRotate(false); + } + + // Reduce el contador if (stoppedCounter > 0) { stoppedCounter--; } - // Si el contador ha llegado a cero, ya no está detenido + // Quitarles el estado "detenido" si no estan explosionando else if (!isPopping()) - { // Quitarles el estado "detenido" si no estan explosionando + { + // Si es una powerball vuelve a rodar + if (kind == POWER_BALL) + { + sprite->setRotate(true); + } + setStop(false); } } @@ -680,7 +691,7 @@ Uint8 Balloon::getClass() { return BALLOON_CLASS; } - + else if ((kind >= HEXAGON_1) && (kind <= HEXAGON_4)) { return HEXAGON_CLASS; diff --git a/source/game.cpp b/source/game.cpp index 563b49e..9364e04 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -15,7 +15,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr // Pasa variables mDemo.enabled = demo; mNumPlayers = numPlayers; - mCurrentStage = currentStage; + this->mCurrentStage = 5; // currentStage; mLastStageReached = currentStage; if (mNumPlayers == 1) { @@ -24,21 +24,6 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr mDifficulty = mOptions->difficulty; // Crea los objetos - // Vector de jugadores - if (mNumPlayers == 1) - { - Player *player = new Player(mRenderer, mAsset, PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24); - players.push_back(player); - } - - else if (mNumPlayers == 2) - { - Player *player1 = new Player(mRenderer, mAsset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24); - Player *player2 = new Player(mRenderer, mAsset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24); - players.push_back(player1); - players.push_back(player2); - } - balloon1Texture = new LTexture(mRenderer, mAsset->get("balloon1.png")); balloon2Texture = new LTexture(mRenderer, mAsset->get("balloon2.png")); balloon3Texture = new LTexture(mRenderer, mAsset->get("balloon3.png")); @@ -85,6 +70,9 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr mSpriteGrass = new Sprite(0, 85, GAME_WIDTH, 6, mTextureGameBG, mRenderer); mSpritePowerMeter = new Sprite(PLAY_AREA_CENTER_X - 20, 170, 40, 8, mTextureGameBG, mRenderer); mSpriteScoreBoard = new Sprite(0, 160, GAME_WIDTH, 32, mTextureGameBG, mRenderer); + + // Inicializa las variables necesarias para la sección 'Game' + init(); } Game::~Game() @@ -94,30 +82,8 @@ Game::~Game() mOptions->input[0].deviceType = mOnePlayerControl; - for (auto player : players) - { - delete player; - }; - - for (auto ballon : balloons) - { - delete ballon; - }; - - for (auto bullet : bullets) - { - delete bullet; - }; - - for (auto item : items) - { - delete item; - }; - - for (auto smartSprite : smartSprites) - { - delete smartSprite; - }; + // Elimina todos los objetos contenidos en vectores + deleteAllVectorObjects(); balloon1Texture->unload(); delete balloon1Texture; @@ -213,6 +179,27 @@ void Game::init() mTicks = 0; mTicksSpeed = 15; + // Crea los jugadores + for (auto player : players) + { + delete player; + }; + players.clear(); + + if (mNumPlayers == 1) + { + Player *player = new Player(mRenderer, mAsset, PLAY_AREA_CENTER_X - 11, PLAY_AREA_BOTTOM - 24); + players.push_back(player); + } + + else if (mNumPlayers == 2) + { + Player *player1 = new Player(mRenderer, mAsset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((0 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24); + Player *player2 = new Player(mRenderer, mAsset, (PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24); + players.push_back(player1); + players.push_back(player2); + } + // Inicializa las variables switch (mDifficulty) { @@ -241,7 +228,6 @@ void Game::init() mMenaceCurrent = 0; mMenaceThreshold = 0; mHiScoreAchieved = false; - // mCurrentStage = 0; mStageBitmapCounter = STAGE_COUNTER; mDeathCounter = DEATH_COUNTER; mTimeStopped = false; @@ -267,7 +253,6 @@ void Game::init() mPowerBallCounter = 0; mCoffeeMachineEnabled = false; mPostFade = 0; - // mLastStageReached = 0; if (mDemo.enabled) { @@ -309,35 +294,6 @@ void Game::init() // Inicializa el objeto para el fundido mFade->init(0x27, 0x27, 0x36); - // Inicializa el objeto con el menu de pausa - // mMenuPause->setName("PAUSE"); - // mMenuPause->setPos(0, 12 * BLOCK); - // mMenuPause->setBackgroundType(MENU_BACKGROUND_SOLID); - // mMenuPause->addItem(mLang->getText(46), 2); - // mMenuPause->addItem(mLang->getText(47), 0); - // mMenuPause->setDefaultActionWhenCancel(0); - // mMenuPause->setBackgroundColor({0x29, 0x39, 0x41}, 240); - // mMenuPause->setSelectorColor({0xFF, 0x7A, 0x00}, 255); - // mMenuPause->setSelectorTextColor({0xFF, 0xFF, 0xFF}); - // mMenuPause->centerMenuOnX(SCREEN_CENTER_X); - // mMenuPause->centerMenuElementsOnX(); - - // Inicializa el objeto con el menu de la pantalla de game over - // mMenuGameOver->setName("GAME OVER"); - // mMenuGameOver->setPos(0, PLAY_AREA_CENTER_Y + BLOCK * 4); - // mMenuGameOver->setBackgroundType(MENU_BACKGROUND_TRANSPARENT); - // mMenuGameOver->addItem(mLang->getText(48), 2); - // mMenuGameOver->addItem(mLang->getText(49)); - // mMenuGameOver->setDefaultActionWhenCancel(1); - // mMenuGameOver->setBackgroundColor({0, 0, 0}, 255); - // mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 255); - // mMenuGameOver->setSelectorColor({0x54, 0x6e, 0x7a}, 0); - // mMenuGameOver->setSelectorTextColor({0xFF, 0xFF, 0xFF}); - // mMenuGameOver->setSelectorTextColor({0xFF, 0xF1, 0x76}); - // mMenuGameOver->setSelectorTextColor({0xFF, 0x7A, 0x00}); - // mMenuGameOver->centerMenuOnX(SCREEN_CENTER_X); - // mMenuGameOver->centerMenuElementsOnX(); - // Sprites mClouds1a->setSpriteClip(256, 0, 256, 52); mClouds1b->setSpriteClip(256, 0, 256, 52); @@ -1469,21 +1425,21 @@ void Game::renderScoreBoard() // PLAYER1 - SCORE mTextScoreBoard->writeCentered(offsetLeft, offset1, mLang->getText(53)); - mTextScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players[0]->getScore())); + mTextScoreBoard->writeCentered(offsetLeft, offset2, updateScoreText(players.at(0)->getScore())); // PLAYER1 - MULT mTextScoreBoard->writeCentered(offsetLeft, offset3, mLang->getText(55)); - mTextScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players[0]->getScoreMultiplier()).substr(0, 3)); + mTextScoreBoard->writeCentered(offsetLeft, offset4, std::to_string(players.at(0)->getScoreMultiplier()).substr(0, 3)); if (mNumPlayers == 2) { // PLAYER2 - SCORE mTextScoreBoard->writeCentered(offsetRight, offset1, mLang->getText(54)); - mTextScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players[1]->getScore())); + mTextScoreBoard->writeCentered(offsetRight, offset2, updateScoreText(players.at(1)->getScore())); // PLAYER2 - MULT mTextScoreBoard->writeCentered(offsetRight, offset3, mLang->getText(55)); - mTextScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players[1]->getScoreMultiplier()).substr(0, 3)); + mTextScoreBoard->writeCentered(offsetRight, offset4, std::to_string(players.at(1)->getScoreMultiplier()).substr(0, 3)); } else { @@ -1744,10 +1700,11 @@ void Game::createPowerBall() const int center = PLAY_AREA_CENTER_X - (BALLOON_WIDTH_4 / 2); const int right = PLAY_AREA_RIGHT - BALLOON_WIDTH_4; + const int luck =rand() % 3; const int x[3] = {left, center, right}; - const int posX = x[rand() % 3]; + const float vx[3] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE}; - Balloon *b = new Balloon(posX, posY, POWER_BALL, BALLOON_VELX_POSITIVE * (((rand() % 2) * 2) - 1), mEnemySpeed, 100, balloon4Texture, balloon4Animation, mRenderer); + Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], mEnemySpeed, 100, balloon4Texture, balloon4Animation, mRenderer); balloons.push_back(b); mPowerBallEnabled = true; @@ -2224,7 +2181,7 @@ void Game::checkBulletBalloonCollision() mCoffeeMachineEnabled = true; } } - + break; } } @@ -3163,8 +3120,6 @@ void Game::shakeScreen() // Bucle para el juego section_t Game::run() { - init(); - while (mSection.name == PROG_SECTION_GAME) { // Sección juego en pausa @@ -3351,17 +3306,9 @@ void Game::runGameOverScreen() { case 0: // YES mSection.name = PROG_SECTION_GAME; - - if (mNumPlayers == 1) - { - mSection.subsection = GAME_SECTION_PLAY_1P; - } - else - { - mSection.subsection = GAME_SECTION_PLAY_2P; - } - + deleteAllVectorObjects(); init(); + mSection.subsection = mNumPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P; break; case 1: // NO @@ -3387,13 +3334,13 @@ void Game::runGameOverScreen() if (mNumPlayers == 1) { mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), mLang->getText(43)); - mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 1), mLang->getText(44) + std::to_string(players[0]->getScore())); + mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 1), mLang->getText(44) + std::to_string(players.at(0)->getScore())); } else { mTextBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 36, mLang->getText(43)); - mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 12, mLang->getText(77) + std::to_string(players[0]->getScore())); - mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y, mLang->getText(78) + std::to_string(players[1]->getScore())); + mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - 12, mLang->getText(77) + std::to_string(players.at(0)->getScore())); + mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y, mLang->getText(78) + std::to_string(players.at(1)->getScore())); } mText->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y + BLOCK * 2, mLang->getText(45)); mMenuGameOver->render(); @@ -3437,7 +3384,7 @@ void Game::renderDebugInfo() mText->writeShadowed(2, 2 + 3 * BLOCK, "mCounter: " + std::to_string(mCounter), color); mText->writeShadowed(2, 2 + 4 * BLOCK, "(R)enemyset: " + std::to_string(mDebug.enemySet), color); mText->writeShadowed(2, 2 + 5 * BLOCK, "RGB: " + std::to_string(mDebug.gradR) + "," + std::to_string(mDebug.gradG) + "," + std::to_string(mDebug.gradB), color); - mText->writeShadowed(2, 2 + 6 * BLOCK, "(I)invuln: " + std::to_string(players[0]->getInvulnerableCounter()), color); + mText->writeShadowed(2, 2 + 6 * BLOCK, "(I)invuln: " + std::to_string(players.at(0)->getInvulnerableCounter()), color); mText->writeShadowed(2, 2 + 7 * BLOCK, "balloons: " + std::to_string(countBalloons()), color); mText->writeShadowed(2, 2 + 8 * BLOCK, "balloonsPop: " + std::to_string(mBalloonsPopped), color); mText->writeShadowed(2, 2 + 9 * BLOCK, "(Z-X)ballSped:" + std::to_string(mEnemySpeed), color); @@ -3611,6 +3558,10 @@ void Game::checkEventHandler() createPowerBall(); break; + case SDL_SCANCODE_O: + stopAllBalloons(200); + break; + default: break; } @@ -3633,4 +3584,38 @@ void Game::loadAnimations(std::string filePath, std::vector *buffer } file.close(); } +} + +// Elimina todos los objetos contenidos en vectores +void Game::deleteAllVectorObjects() +{ + for (auto player : players) + { + delete player; + }; + players.clear(); + + for (auto ballon : balloons) + { + delete ballon; + }; + balloons.clear(); + + for (auto bullet : bullets) + { + delete bullet; + }; + bullets.clear(); + + for (auto item : items) + { + delete item; + }; + items.clear(); + + for (auto smartSprite : smartSprites) + { + delete smartSprite; + }; + smartSprites.clear(); } \ No newline at end of file diff --git a/source/game.h b/source/game.h index d7f7460..f627b98 100644 --- a/source/game.h +++ b/source/game.h @@ -512,6 +512,9 @@ private: // Carga las animaciones void loadAnimations(std::string filePath, std::vector *buffer); + // Elimina todos los objetos contenidos en vectores + void deleteAllVectorObjects(); + public: // Constructor Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *mAsset, Lang *lang, Input *input, bool demo, options_t *options); diff --git a/source/item.cpp b/source/item.cpp index bab95ba..634704f 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -2,11 +2,11 @@ #include "item.h" // Constructor -Item::Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y) +Item::Item(SDL_Renderer *renderer, Asset *asset, Uint8 kind, float x, float y) { std::string filePNG; std::string fileANI; - switch (type) + switch (kind) { case ITEM_POINTS_1_DISK: filePNG = asset->get("item_points1_disk.png"); @@ -45,13 +45,13 @@ Item::Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y) texture = new LTexture(renderer, filePNG); sprite = new AnimatedSprite(texture, renderer, fileANI); - this->type = type; + this->kind = kind; enabled = true; timeToLive = 600; accelX = 0.0f; floorCollision = false; - if (type == ITEM_COFFEE_MACHINE) + if (kind == ITEM_COFFEE_MACHINE) { width = 23; height = 29; @@ -148,10 +148,10 @@ void Item::move() } // Si se sale por arriba rebota (excepto la maquina de café) - if ((posY < PLAY_AREA_TOP) && !(type == ITEM_COFFEE_MACHINE)) + if ((posY < PLAY_AREA_TOP) && !(kind == ITEM_COFFEE_MACHINE)) { // Corrige - posY = PLAY_AREA_TOP; + posY -= velY; // Invierte el sentido velY = -velY; @@ -169,7 +169,7 @@ void Item::move() accelX = 0; accelY = 0; posY = PLAY_AREA_BOTTOM - height; - if (type == ITEM_COFFEE_MACHINE) + if (kind == ITEM_COFFEE_MACHINE) { floorCollision = true; } @@ -239,7 +239,7 @@ int Item::getHeight() // Obtiene del valor de la variable int Item::getClass() { - return type; + return kind; } // Obtiene el valor de la variable diff --git a/source/item.h b/source/item.h index 96c5f98..1609f23 100644 --- a/source/item.h +++ b/source/item.h @@ -34,7 +34,7 @@ private: float accelX; // Aceleración en el eje X float accelY; // Aceleración en el eje Y bool floorCollision; // Indica si el objeto colisiona con el suelo - Uint8 type; // Especifica el tipo de objeto que es + Uint8 kind; // Especifica el tipo de objeto que es bool enabled; // Especifica si el objeto está habilitado circle_t collider; // Circulo de colisión del objeto @@ -47,7 +47,7 @@ public: Uint16 timeToLive; // Temporizador con el tiempo que el objeto está presente // Constructor - Item(SDL_Renderer *renderer, Asset *asset, Uint8 type, float x, float y); + Item(SDL_Renderer *renderer, Asset *asset, Uint8 kind, float x, float y); // Destructor ~Item(); diff --git a/source/player.cpp b/source/player.cpp index 5b7efd8..1584721 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -233,7 +233,7 @@ void Player::setAnimation() { // No esta disparando bodySprite->setCurrentAnimation(aWalking + aBodyCoffees); bodySprite->setFlip(flipWalk); - headSprite->setCurrentAnimation(aWalking + aHeadCoffees); + headSprite->setCurrentAnimation(aWalking + aHeadCoffees+ aPowerUp); headSprite->setFlip(flipWalk); } else diff --git a/todo.txt b/todo.txt index d402d62..949adae 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,6 @@ -los items se quedan pegados en el techo +los items se quedan pegados en el techo (comprobar si sigue pasando, he cambiado la coreción al chocar arriba. Si sigue fallando se quita la comprobación superior) x la maquina de cafe no toca el suelo -las bolas verdes nacen naranja al explotarlas +x las bolas verdes nacen naranja al explotarlas falta el aura de superguerrero al pillar la maquina de cafe x la powerball deja la mascara al explotarlas los menus de pausa y game over falta poner bien los textos @@ -14,4 +14,10 @@ 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 x las balas deberian llegar a salir de la pantalla hacer desaparecer los accesos a disco en el juego. cargar todos los recursos previamente y pasarlos por punteros -la powerball nace rodando \ No newline at end of file +x la powerball se para con el reloj y sigue rodando +x acelerar la animacion de disparar recto +x no pone la animacion corecta al no disparar con el powerup +que grite "yiiijaa!" o algo parecido al coger la maquina de cafe +o que diga DIMONIS! en un globo de texto que se evapore +podrian salir comentarios aleatoriamente o con ciertos eventos (falta ver si no estorbará) +que se vea el nivel de dificultad \ No newline at end of file