Throw coffe with rotation and time stop with clock sound

This commit is contained in:
2021-04-04 12:31:48 +02:00
parent 4980c0f712
commit d84137daa7
10 changed files with 172 additions and 41 deletions

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ data/config.bin
data/score.bin data/score.bin
*.opk *.opk
coffee_crisis coffee_crisis
.vscode

BIN
media/.DS_Store vendored

Binary file not shown.

BIN
media/sound/clock.wav Normal file

Binary file not shown.

View File

@@ -57,3 +57,7 @@ JailDoctor
bubble4.wav bubble4.wav
JailDoctor JailDoctor
clock.wav
kenney_digitalaudio/switch2.ogg
www.kenney.nl

View File

@@ -38,8 +38,9 @@
#define SOUND_PLAYER_COLLISION 13 #define SOUND_PLAYER_COLLISION 13
#define SOUND_STAGE_CHANGE 14 #define SOUND_STAGE_CHANGE 14
#define SOUND_TITLE 15 #define SOUND_TITLE 15
#define SOUND_CLOCK 16
#define TOTAL_SOUND 16 #define TOTAL_SOUND 17
#define TEXTURE_BALLOON 0 #define TEXTURE_BALLOON 0
#define TEXTURE_BULLET 1 #define TEXTURE_BULLET 1

View File

@@ -46,9 +46,13 @@ GameDirector::GameDirector(std::string path)
initJailAudio(); initJailAudio();
#ifdef __MIPSEL__ #ifdef __MIPSEL__
DIR* dir = opendir("/media/data/local/home/.coffee_crisis"); DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
if (dir) { closedir(dir); } if (dir)
else if (ENOENT == errno) { {
closedir(dir);
}
else if (ENOENT == errno)
{
int status = mkdir("/media/data/local/home/.coffee_crisis", 755); int status = mkdir("/media/data/local/home/.coffee_crisis", 755);
} }
#endif #endif
@@ -1041,6 +1045,7 @@ bool GameDirector::loadMediaGame()
mSound[SOUND_BUBBLE2].sound = JA_LoadSound(mSound[SOUND_BUBBLE2].file.c_str()); mSound[SOUND_BUBBLE2].sound = JA_LoadSound(mSound[SOUND_BUBBLE2].file.c_str());
mSound[SOUND_BUBBLE3].sound = JA_LoadSound(mSound[SOUND_BUBBLE3].file.c_str()); mSound[SOUND_BUBBLE3].sound = JA_LoadSound(mSound[SOUND_BUBBLE3].file.c_str());
mSound[SOUND_BUBBLE4].sound = JA_LoadSound(mSound[SOUND_BUBBLE4].file.c_str()); mSound[SOUND_BUBBLE4].sound = JA_LoadSound(mSound[SOUND_BUBBLE4].file.c_str());
mSound[SOUND_CLOCK].sound = JA_LoadSound(mSound[SOUND_CLOCK].file.c_str());
// Musicas // Musicas
mMusic[MUSIC_PLAYING].music = JA_LoadMusic(mMusic[MUSIC_PLAYING].file.c_str()); mMusic[MUSIC_PLAYING].music = JA_LoadMusic(mMusic[MUSIC_PLAYING].file.c_str());
@@ -1075,6 +1080,7 @@ void GameDirector::quitGame()
JA_DeleteSound(mSound[SOUND_BUBBLE2].sound); JA_DeleteSound(mSound[SOUND_BUBBLE2].sound);
JA_DeleteSound(mSound[SOUND_BUBBLE3].sound); JA_DeleteSound(mSound[SOUND_BUBBLE3].sound);
JA_DeleteSound(mSound[SOUND_BUBBLE4].sound); JA_DeleteSound(mSound[SOUND_BUBBLE4].sound);
JA_DeleteSound(mSound[SOUND_CLOCK].sound);
// Musicas // Musicas
JA_DeleteMusic(mMusic[MUSIC_PLAYING].music); JA_DeleteMusic(mMusic[MUSIC_PLAYING].music);
@@ -1182,6 +1188,7 @@ void GameDirector::setFileList()
mSound[SOUND_PLAYER_COLLISION].file = mProg.executablePath + "/" + "../media/sound/player_collision.wav"; mSound[SOUND_PLAYER_COLLISION].file = mProg.executablePath + "/" + "../media/sound/player_collision.wav";
mSound[SOUND_STAGE_CHANGE].file = mProg.executablePath + "/" + "../media/sound/stage_change.wav"; mSound[SOUND_STAGE_CHANGE].file = mProg.executablePath + "/" + "../media/sound/stage_change.wav";
mSound[SOUND_TITLE].file = mProg.executablePath + "/" + "../media/sound/title.wav"; mSound[SOUND_TITLE].file = mProg.executablePath + "/" + "../media/sound/title.wav";
mSound[SOUND_CLOCK].file = mProg.executablePath + "/" + "../media/sound/clock.wav";
// Texturas // Texturas
mTexture[TEXTURE_BALLOON].file = mProg.executablePath + "/" + "../media/gfx/balloon.png"; mTexture[TEXTURE_BALLOON].file = mProg.executablePath + "/" + "../media/gfx/balloon.png";
@@ -3043,7 +3050,7 @@ void GameDirector::resetItems()
// Devuelve un item en función del azar // Devuelve un item en función del azar
Uint8 GameDirector::dropItem() Uint8 GameDirector::dropItem()
{ {
//return ITEM_COFFEE; return ITEM_COFFEE;
Uint8 luckyNumber = rand() % 99; Uint8 luckyNumber = rand() % 99;
Uint8 item = rand() % 7; Uint8 item = rand() % 7;
@@ -3151,6 +3158,9 @@ void GameDirector::throwCoffee(int x, int y)
mGame.smartSprite[index]->setEnabled(true); mGame.smartSprite[index]->setEnabled(true);
mGame.smartSprite[index]->setEnabledTimer(1); mGame.smartSprite[index]->setEnabledTimer(1);
mGame.smartSprite[index]->setSpriteClip(80, 16, 16, 16); mGame.smartSprite[index]->setSpriteClip(80, 16, 16, 16);
mGame.smartSprite[index]->setRotate(true);
mGame.smartSprite[index]->setRotateSpeed(1);
mGame.smartSprite[index]->setRotateAmount(5.0);
} }
// Crea un SmartSprite para arrojar el item café al recibir un impacto // Crea un SmartSprite para arrojar el item café al recibir un impacto
@@ -4010,6 +4020,17 @@ void GameDirector::renderMessages()
mText.black->writeCentered(PLAY_AREA_CENTER_X + 1, PLAY_AREA_FIRST_QUARTER_Y + 1, "Time Stopped: " + std::to_string(mGame.timeStoppedCounter / 10)); mText.black->writeCentered(PLAY_AREA_CENTER_X + 1, PLAY_AREA_FIRST_QUARTER_Y + 1, "Time Stopped: " + std::to_string(mGame.timeStoppedCounter / 10));
mText.white->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, "Time Stopped: " + std::to_string(mGame.timeStoppedCounter / 10)); mText.white->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, "Time Stopped: " + std::to_string(mGame.timeStoppedCounter / 10));
} }
if (mGame.timeStoppedCounter > 100)
{
if (mGame.timeStoppedCounter % 30 == 0)
JA_PlaySound(mSound[SOUND_CLOCK].sound, false);
}
else
{
if (mGame.timeStoppedCounter % 15 == 0)
JA_PlaySound(mSound[SOUND_CLOCK].sound, false);
}
} }
// D E M O // D E M O

View File

@@ -37,6 +37,9 @@ void MovingSprite::init(float x, float y, int w, int h, float velx, float vely,
setZoomW(1); setZoomW(1);
setZoomH(1); setZoomH(1);
// Establece el angulo con el que se dibujará
setAngle(0.0);
// Establece la textura donde están los gráficos para el sprite // Establece la textura donde están los gráficos para el sprite
setTexture(texture); setTexture(texture);
@@ -61,57 +64,63 @@ void MovingSprite::move()
void MovingSprite::render() void MovingSprite::render()
{ {
//mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip); //mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip);
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH); mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH, mAngle);
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getPosX() float MovingSprite::getPosX()
{ {
return mPosX; return mPosX;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getPosY() float MovingSprite::getPosY()
{ {
return mPosY; return mPosY;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getVelX() float MovingSprite::getVelX()
{ {
return mVelX; return mVelX;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getVelY() float MovingSprite::getVelY()
{ {
return mVelY; return mVelY;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getAccelX() float MovingSprite::getAccelX()
{ {
return mAccelX; return mAccelX;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getAccelY() float MovingSprite::getAccelY()
{ {
return mAccelY; return mAccelY;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getZoomW() float MovingSprite::getZoomW()
{ {
return mZoomW; return mZoomW;
} }
// Establece el valor de la variable // Obtiene el valor de la variable
float MovingSprite::getZoomH() float MovingSprite::getZoomH()
{ {
return mZoomH; return mZoomH;
} }
// Obtiene el valor de la variable
double MovingSprite::getAngle()
{
return mAngle;
}
// Establece el valor de la variable // Establece el valor de la variable
void MovingSprite::setPosX(float x) void MovingSprite::setPosX(float x)
{ {
@@ -159,3 +168,21 @@ void MovingSprite::setZoomH(float h)
{ {
mZoomH = h; mZoomH = h;
} }
// Establece el valor de la variable
void MovingSprite::setAngle(double a)
{
mAngle = a;
}
// Incrementa el valor de la variable
void MovingSprite::incAngle(double inc)
{
mAngle += inc;
}
// Decrementa el valor de la variable
void MovingSprite::decAngle(double dec)
{
mAngle -= dec;
}

View File

@@ -21,6 +21,8 @@ private:
float mZoomW; // Zoom aplicado a la anchura float mZoomW; // Zoom aplicado a la anchura
float mZoomH; // Zoom aplicado a la altura float mZoomH; // Zoom aplicado a la altura
double mAngle; // Angulo para dibujarlo
public: public:
// Constructor // Constructor
MovingSprite(); MovingSprite();
@@ -61,6 +63,9 @@ public:
// Obten el valor de la variable // Obten el valor de la variable
float getZoomH(); float getZoomH();
// Obten el valor de la variable
double getAngle();
// Establece el valor de la variable // Establece el valor de la variable
void setPosX(float x); void setPosX(float x);
@@ -84,6 +89,15 @@ public:
// Establece el valor de la variable // Establece el valor de la variable
void setZoomH(float h); void setZoomH(float h);
// Establece el valor de la variable
void setAngle(double a);
// Incrementa el valor de la variable
void incAngle(double inc);
// Decrementa el valor de la variable
void decAngle(double dec);
}; };
#endif #endif

View File

@@ -38,6 +38,12 @@ void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
mDestX = 0; mDestX = 0;
mDestY = 0; mDestY = 0;
setRotate(false);
setRotateSpeed(0);
setRotateAmount(0.0);
mCounter = 0;
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo // El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
mId = -1; mId = -1;
@@ -65,13 +71,13 @@ void SmartSprite::setEnabled(bool state)
// Obtiene el valor de la variable // Obtiene el valor de la variable
Uint16 SmartSprite::getEnabledTimer() Uint16 SmartSprite::getEnabledTimer()
{ {
return mEnabledTimer; return mEnabledCounter;
} }
// Establece el valor de la variable // Establece el valor de la variable
void SmartSprite::setEnabledTimer(Uint16 time) void SmartSprite::setEnabledTimer(Uint16 time)
{ {
mEnabledTimer = time; mEnabledCounter = time;
} }
// Establece el valor de la variable // Establece el valor de la variable
@@ -86,6 +92,24 @@ void SmartSprite::setDestY(int value)
mDestY = value; mDestY = value;
} }
// Establece el valor de la variable
void SmartSprite::setRotate(bool value)
{
mRotate = value;
}
// Establece el valor de la variable
void SmartSprite::setRotateSpeed(Uint16 value)
{
mRotateSpeed = value;
}
// Establece el valor de la variable
void SmartSprite::setRotateAmount(double value)
{
mRotateAmount = value;
}
// Obtiene el valor de la variable // Obtiene el valor de la variable
int SmartSprite::getDestX() int SmartSprite::getDestX()
{ {
@@ -98,12 +122,37 @@ int SmartSprite::getDestY()
return mDestY; return mDestY;
} }
// Obtiene el valor de la variable
bool SmartSprite::getRotate()
{
return mRotate;
}
// Obtiene el valor de la variable
Uint16 SmartSprite::getRotateSpeed()
{
return mRotateSpeed;
}
// Establece la rotacion
void SmartSprite::rotate()
{
if (mRotate)
{
if (mCounter % mRotateSpeed == 0)
{
incAngle(mRotateAmount);
}
}
}
// Actualiza la posición y comprueba si ha llegado a su destino // Actualiza la posición y comprueba si ha llegado a su destino
bool SmartSprite::update() bool SmartSprite::update()
{ {
if (mEnabled) if (mEnabled)
{ {
move(); move();
rotate();
// Comprueba si se desplaza en el eje X hacia la derecha // Comprueba si se desplaza en el eje X hacia la derecha
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0))) if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
@@ -178,12 +227,12 @@ bool SmartSprite::update()
if (mIsOnDestination) if (mIsOnDestination)
{ {
// Si el contador es mayor que cero, lo decrementa // Si el contador es mayor que cero, lo decrementa
if (mEnabledTimer > 0) if (mEnabledCounter > 0)
{ {
--mEnabledTimer; --mEnabledCounter;
} }
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id // Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
else if (mEnabledTimer == 0) else if (mEnabledCounter == 0)
{ {
if (mId < 0) if (mId < 0)
{ {
@@ -195,6 +244,9 @@ bool SmartSprite::update()
} }
} }
} }
mCounter++;
mCounter %= 65000;
} }
return mIsOnDestination; return mIsOnDestination;

View File

@@ -8,6 +8,19 @@
// Clase SmartSprite // Clase SmartSprite
class SmartSprite : public AnimatedSprite class SmartSprite : public AnimatedSprite
{ {
private:
bool mEnabled; // Indica si esta habilitado
bool mIsOnDestination; // Indica si está en el destino
bool mRotate; // Indica si ha de rotar
int mDestX; // Posicion de destino en el eje X
int mDestY; // Posicion de destino en el eje Y
int mId; // Identificador
Uint16 mCounter; // Contador interno
Uint16 mEnabledCounter; // Contador para deshabilitarlo
Uint16 mRotateSpeed; // Velocidad de giro
Uint8 *mIntroEvents; // Dirección del array de eventos donde notificar el estado
double mRotateAmount; // Cantidad de grados a girar en cada iteración
public: public:
// Constructor // Constructor
SmartSprite(); SmartSprite();
@@ -39,12 +52,30 @@ public:
// Establece el valor de la variable // Establece el valor de la variable
void setDestY(int value); void setDestY(int value);
// Establece el valor de la variable
void setRotate(bool value);
// Establece el valor de la variable
void setRotateSpeed(Uint16 value);
// Establece el valor de la variable
void setRotateAmount(double value);
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getDestX(); int getDestX();
// Obtiene el valor de la variable // Obtiene el valor de la variable
int getDestY(); int getDestY();
// Obtiene el valor de la variable
bool getRotate();
// Obtiene el valor de la variable
Uint16 getRotateSpeed();
// Establece la rotacion
void rotate();
// Actualiza la posición y comprueba si ha llegado a su destino // Actualiza la posición y comprueba si ha llegado a su destino
bool update(); bool update();
@@ -59,26 +90,6 @@ public:
// Establece el valor de la variable // Establece el valor de la variable
void setIntroEvents(Uint8 *value); void setIntroEvents(Uint8 *value);
private:
// Indica si esta habilitado
bool mEnabled;
// Contador
Uint16 mEnabledTimer;
// Indica si está en el destino
bool mIsOnDestination;
// Posicion de destino
int mDestX;
int mDestY;
// Identificador
int mId;
// Dirección del array de eventos donde notificar el estado
Uint8 *mIntroEvents;
}; };
#endif #endif