Throw coffe with rotation and time stop with clock sound
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ data/config.bin
|
||||
data/score.bin
|
||||
*.opk
|
||||
coffee_crisis
|
||||
.vscode
|
||||
BIN
media/.DS_Store
vendored
BIN
media/.DS_Store
vendored
Binary file not shown.
BIN
media/sound/clock.wav
Normal file
BIN
media/sound/clock.wav
Normal file
Binary file not shown.
@@ -57,3 +57,7 @@ JailDoctor
|
||||
|
||||
bubble4.wav
|
||||
JailDoctor
|
||||
|
||||
clock.wav
|
||||
kenney_digitalaudio/switch2.ogg
|
||||
www.kenney.nl
|
||||
@@ -38,8 +38,9 @@
|
||||
#define SOUND_PLAYER_COLLISION 13
|
||||
#define SOUND_STAGE_CHANGE 14
|
||||
#define SOUND_TITLE 15
|
||||
#define SOUND_CLOCK 16
|
||||
|
||||
#define TOTAL_SOUND 16
|
||||
#define TOTAL_SOUND 17
|
||||
|
||||
#define TEXTURE_BALLOON 0
|
||||
#define TEXTURE_BULLET 1
|
||||
|
||||
@@ -47,8 +47,12 @@ GameDirector::GameDirector(std::string path)
|
||||
|
||||
#ifdef __MIPSEL__
|
||||
DIR *dir = opendir("/media/data/local/home/.coffee_crisis");
|
||||
if (dir) { closedir(dir); }
|
||||
else if (ENOENT == errno) {
|
||||
if (dir)
|
||||
{
|
||||
closedir(dir);
|
||||
}
|
||||
else if (ENOENT == errno)
|
||||
{
|
||||
int status = mkdir("/media/data/local/home/.coffee_crisis", 755);
|
||||
}
|
||||
#endif
|
||||
@@ -1041,6 +1045,7 @@ bool GameDirector::loadMediaGame()
|
||||
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_BUBBLE4].sound = JA_LoadSound(mSound[SOUND_BUBBLE4].file.c_str());
|
||||
mSound[SOUND_CLOCK].sound = JA_LoadSound(mSound[SOUND_CLOCK].file.c_str());
|
||||
|
||||
// Musicas
|
||||
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_BUBBLE3].sound);
|
||||
JA_DeleteSound(mSound[SOUND_BUBBLE4].sound);
|
||||
JA_DeleteSound(mSound[SOUND_CLOCK].sound);
|
||||
|
||||
// Musicas
|
||||
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_STAGE_CHANGE].file = mProg.executablePath + "/" + "../media/sound/stage_change.wav";
|
||||
mSound[SOUND_TITLE].file = mProg.executablePath + "/" + "../media/sound/title.wav";
|
||||
mSound[SOUND_CLOCK].file = mProg.executablePath + "/" + "../media/sound/clock.wav";
|
||||
|
||||
// Texturas
|
||||
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
|
||||
Uint8 GameDirector::dropItem()
|
||||
{
|
||||
//return ITEM_COFFEE;
|
||||
return ITEM_COFFEE;
|
||||
|
||||
Uint8 luckyNumber = rand() % 99;
|
||||
Uint8 item = rand() % 7;
|
||||
@@ -3151,6 +3158,9 @@ void GameDirector::throwCoffee(int x, int y)
|
||||
mGame.smartSprite[index]->setEnabled(true);
|
||||
mGame.smartSprite[index]->setEnabledTimer(1);
|
||||
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
|
||||
@@ -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.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
|
||||
|
||||
@@ -37,6 +37,9 @@ void MovingSprite::init(float x, float y, int w, int h, float velx, float vely,
|
||||
setZoomW(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
|
||||
setTexture(texture);
|
||||
|
||||
@@ -61,57 +64,63 @@ void MovingSprite::move()
|
||||
void MovingSprite::render()
|
||||
{
|
||||
//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()
|
||||
{
|
||||
return mPosX;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getPosY()
|
||||
{
|
||||
return mPosY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelX()
|
||||
{
|
||||
return mVelX;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getVelY()
|
||||
{
|
||||
return mVelY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelX()
|
||||
{
|
||||
return mAccelX;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getAccelY()
|
||||
{
|
||||
return mAccelY;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomW()
|
||||
{
|
||||
return mZoomW;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
// Obtiene el valor de la variable
|
||||
float MovingSprite::getZoomH()
|
||||
{
|
||||
return mZoomH;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
double MovingSprite::getAngle()
|
||||
{
|
||||
return mAngle;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void MovingSprite::setPosX(float x)
|
||||
{
|
||||
@@ -159,3 +168,21 @@ void MovingSprite::setZoomH(float 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;
|
||||
}
|
||||
@@ -21,6 +21,8 @@ private:
|
||||
float mZoomW; // Zoom aplicado a la anchura
|
||||
float mZoomH; // Zoom aplicado a la altura
|
||||
|
||||
double mAngle; // Angulo para dibujarlo
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite();
|
||||
@@ -61,6 +63,9 @@ public:
|
||||
// Obten el valor de la variable
|
||||
float getZoomH();
|
||||
|
||||
// Obten el valor de la variable
|
||||
double getAngle();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float x);
|
||||
|
||||
@@ -84,6 +89,15 @@ public:
|
||||
|
||||
// Establece el valor de la variable
|
||||
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
|
||||
|
||||
@@ -38,6 +38,12 @@ void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
||||
mDestX = 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
|
||||
mId = -1;
|
||||
|
||||
@@ -65,13 +71,13 @@ void SmartSprite::setEnabled(bool state)
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 SmartSprite::getEnabledTimer()
|
||||
{
|
||||
return mEnabledTimer;
|
||||
return mEnabledCounter;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setEnabledTimer(Uint16 time)
|
||||
{
|
||||
mEnabledTimer = time;
|
||||
mEnabledCounter = time;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -86,6 +92,24 @@ void SmartSprite::setDestY(int 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
|
||||
int SmartSprite::getDestX()
|
||||
{
|
||||
@@ -98,12 +122,37 @@ int SmartSprite::getDestY()
|
||||
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
|
||||
bool SmartSprite::update()
|
||||
{
|
||||
if (mEnabled)
|
||||
{
|
||||
move();
|
||||
rotate();
|
||||
|
||||
// Comprueba si se desplaza en el eje X hacia la derecha
|
||||
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
||||
@@ -178,12 +227,12 @@ bool SmartSprite::update()
|
||||
if (mIsOnDestination)
|
||||
{
|
||||
// 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
|
||||
else if (mEnabledTimer == 0)
|
||||
else if (mEnabledCounter == 0)
|
||||
{
|
||||
if (mId < 0)
|
||||
{
|
||||
@@ -195,6 +244,9 @@ bool SmartSprite::update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mCounter++;
|
||||
mCounter %= 65000;
|
||||
}
|
||||
|
||||
return mIsOnDestination;
|
||||
|
||||
@@ -8,6 +8,19 @@
|
||||
// Clase SmartSprite
|
||||
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:
|
||||
// Constructor
|
||||
SmartSprite();
|
||||
@@ -39,12 +52,30 @@ public:
|
||||
// Establece el valor de la variable
|
||||
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
|
||||
int getDestX();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
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
|
||||
bool update();
|
||||
|
||||
@@ -59,26 +90,6 @@ public:
|
||||
|
||||
// Establece el valor de la variable
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user