From 26ac51b1beeafd6d356633ddf5a9a671fd9b5e69 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 23 Aug 2021 13:44:05 +0200 Subject: [PATCH] working on 2players --- source/bullet.h | 45 +++++++++++++++++---------------------------- source/game.cpp | 20 +++++++++++++------- source/ifdefs.h | 4 ++-- source/main.cpp | 4 +++- source/title.cpp | 2 +- 5 files changed, 36 insertions(+), 39 deletions(-) diff --git a/source/bullet.h b/source/bullet.h index 4f31fb1..0f775c8 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -8,6 +8,20 @@ // Clase bala class Bullet { +private: + int mPosX; // Posición en el eje X + int mPosY; // Posición en el eje Y + Uint8 mWidth; // Ancho del objeto + Uint8 mHeight; // Alto del objeto + int mVelX; // Velocidad en el eje X + int mVelY; // Velocidad en el eje Y + int mKind; // Tipo de objeto + Sprite *mSprite; // Sprite con los graficos y métodos de pintado + circle_t mCollider; // Circulo de colisión del objeto + + // Alinea el circulo de colisión con el objeto + void shiftColliders(); + public: // Constructor Bullet(); @@ -16,11 +30,11 @@ public: ~Bullet(); // Iniciador - void init(int x, int y, int kind, bool poweredUp, LTexture* texture, SDL_Renderer *renderer); - + void init(int x, int y, int kind, bool poweredUp, LTexture *texture, SDL_Renderer *renderer); + // Pinta el objeto en pantalla void render(); - + // Actualiza la posición y estado del objeto Uint8 move(); @@ -50,31 +64,6 @@ public: // Obtiene el circulo de colisión circle_t &getCollider(); - -private: - // Posición X/Y del objeto - int mPosX; - int mPosY; - - // Alto y ancho el objeto - Uint8 mWidth; - Uint8 mHeight; - - // Velocidad del objeto - int mVelX; - int mVelY; - - // Tipo de objeto - int mKind; - - // Sprite con los graficos y métodos de pintado - Sprite *mSprite; - - // Balloon's collision circle - circle_t mCollider; - - // Alinea el circulo de colisión con el objeto - void shiftColliders(); }; #endif diff --git a/source/game.cpp b/source/game.cpp index a31084d..573c7c7 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -254,7 +254,7 @@ void Game::initSin() { // Vector con los valores del seno para 360 grados for (int i = 0; i < 360; i++) - mSin[i] = sin((float)i * 3.14f / 180.0f); + mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f); } // Inicializa las variables necesarias para la sección 'Game' @@ -1863,11 +1863,6 @@ void Game::updateBalloonSpeed() // Explosiona un globo. Lo destruye y crea otros dos si es el caso void Game::popBalloon(Uint8 index) { - // Otorga los puntos correspondientes al globo - mPlayer[0]->addScore(Uint32(mBalloon[index]->getScore() * mPlayer[0]->getScoreMultiplier())); - setScore(mPlayer[0]->getScore()); - updateHiScore(); - // Aumenta el poder de la fase increaseStageCurrentPower(1); mBalloonsPopped++; @@ -2107,12 +2102,23 @@ void Game::checkBulletBalloonCollision() if (mBalloon[i]->isEnabled() && (!mBalloon[i]->isInvulnerable()) && mBullet[j]->isActive()) if (checkCollision(mBalloon[i]->getCollider(), mBullet[j]->getCollider())) { + // Otorga los puntos correspondientes al globo mPlayer[0]->incScoreMultiplier(); + mPlayer[0]->addScore(Uint32(mBalloon[i]->getScore() * mPlayer[0]->getScoreMultiplier())); + setScore(mPlayer[0]->getScore()); + updateHiScore(); + + // Explota el globo popBalloon(i); + + // Si no es el modo demo, genera un sonido if (!mDemo.enabled) JA_PlaySound(mSoundBalloon); + + // Destruye la bala mBullet[j]->erase(); - evaluateAndSetMenace(); + + // Suelta el item en caso de que salga uno const Uint8 droppeditem = dropItem(); if ((droppeditem != NO_KIND) && !(mDemo.enabled) && !(mDemo.recording)) { diff --git a/source/ifdefs.h b/source/ifdefs.h index a9322d8..ffa925d 100644 --- a/source/ifdefs.h +++ b/source/ifdefs.h @@ -1,9 +1,9 @@ #ifdef _WIN64 -#include "C:\mingw_dev_lib\include\SDL2\SDL.h" +#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\SDL2\SDL.h" #endif #ifdef _WIN32 -#include "C:\mingw_dev_lib\include\SDL2\SDL.h" +#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\SDL2\SDL.h" #endif #ifdef __APPLE__ diff --git a/source/main.cpp b/source/main.cpp index e1b72d3..e5d15fd 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -37,11 +37,13 @@ un tipo asociado diferente a NO_KIND #include "director.h" #include #include +#include int main(int argc, char *args[]) { // Inicia el generador de numeros aleatorios - srand(time(nullptr)); + //srand(time(nullptr)); + std::srand(static_cast(std::time(nullptr))); // Crea el objeto mDirector Director *mDirector = new Director(args[0]); diff --git a/source/title.cpp b/source/title.cpp index 3cfedee..864427d 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -220,7 +220,7 @@ void Title::init(bool demo, Uint8 subsection) // Inicializa los valores del vector con los valores del seno for (int i = 0; i < 360; i++) { - mSin[i] = sin((float)i * 3.14f / 180.0f); + mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f); } // Inicializa los objetos de menu