10 Commits

46 changed files with 5203 additions and 3226 deletions

13
.gitignore vendored Normal file
View File

@@ -0,0 +1,13 @@
bin
dll
icon
media_work
releases
resources
scripts
.DS_Store
todo.txt
data/config.bin
data/score.bin
*.opk
coffee_crisis

19
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"intelliSenseMode": "macos-clang-x64",
"cStandard": "c11",
"cppStandard": "c++11"
}
],
"version": 4
}

21
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/coffee_crisis_macos_debug",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bin",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: g++ build"
}
]
}

19
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"files.associations": {
"cstddef": "cpp",
"__tuple": "cpp",
"array": "cpp",
"algorithm": "cpp",
"__bit_reference": "cpp",
"__hash_table": "cpp",
"__split_buffer": "cpp",
"initializer_list": "cpp",
"iterator": "cpp",
"string": "cpp",
"string_view": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"iosfwd": "cpp",
"stdexcept": "cpp"
}
}

31
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build",
"command": "/usr/bin/g++",
"args": [
"-g",
"${workspaceFolder}/source/*.cpp",
"-std=c++11",
"-Wall",
"-O2",
"-lSDL2",
"-o",
"${workspaceFolder}/bin/coffee_crisis_macos_debug"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}

9
default.gcw0.desktop Normal file
View File

@@ -0,0 +1,9 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=Coffee Crisis
Comment=Coffee Crisis
Icon=icon
Exec=bin/coffee_crisis
Categories=games;Game;SDL;
Terminal=false

7
generate_opendingux Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/bash
mkdir -p bin
cd source
/opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ -g -D_GCWZERO -O2 -I/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/sysroot/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -lSDL2_mixer -std=c++11 *.cpp -o ../bin/coffee_crisis
cd ..
/opt/gcw0-toolchain/usr/bin/mksquashfs ./default.gcw0.desktop ./icon.png ./bin ./data ./media coffee_crisis.opk -all-root -noappend -no-exports -no-xattrs

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
media/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 57 KiB

BIN
media/gfx/font_black_x2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
media/gfx/font_white_x2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@@ -39,8 +39,7 @@ kenney_digitalaudio/lowDown.ogg
www.kenney.nl
stage_change.wav
kenney_digitalaudio/phaserUp2.ogg
www.kenney.nl
JailDoctor
menu_cancel.wav
kenney_digitalaudio/lowRandom.ogg

Binary file not shown.

View File

@@ -24,6 +24,7 @@ void AnimatedSprite::init(LTexture *texture, SDL_Renderer *renderer)
mAnimation[i].numFrames = 0;
mAnimation[i].speed = 0;
mAnimation[i].loop = true;
mAnimation[i].completed = false;
for (Uint8 j = 0; i < 20; i++)
{
mAnimation[i].frames[j].x = 0;
@@ -105,6 +106,18 @@ void AnimatedSprite::setAnimationLoop(Uint8 index, bool loop)
mAnimation[index].loop = loop;
}
// Establece el valor de la variable
void AnimatedSprite::setCompleted(Uint8 index, bool value)
{
mAnimation[index].completed = value;
}
// Comprueba si ha terminado la animación
bool AnimatedSprite::isCompleted(Uint8 index)
{
return mAnimation[index].completed;
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(Uint8 index_animation, Uint8 index_frame)
{

View File

@@ -5,9 +5,26 @@
#ifndef ANIMATEDSPRITE_H
#define ANIMATEDSPRITE_H
#define MAX_FRAMES 30
#define MAX_ANIMATIONS 20
// Clase AnimatedSprite
class AnimatedSprite : public MovingSprite
{
private:
struct sAnimation
{
SDL_Rect frames[MAX_FRAMES]; // Cada uno de los frames que componen la animación
Uint8 numFrames; // Numero de frames que componen la animación
Uint8 speed; // Velocidad de la animación
bool loop; // Indica si la animación se reproduce en bucle
bool completed; // Indica si ha finalizado la animación
};
sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las diferentes animaciones
Uint8 mCurrentFrame; // Frame actual
Uint16 mAnimationCounter; // Contador para las animaciones
public:
// Constructor
AnimatedSprite();
@@ -39,26 +56,14 @@ public:
// Establece si la animación se reproduce en bucle
void setAnimationLoop(Uint8 index, bool loop);
// Establece el valor de la variable
void setCompleted(Uint8 index, bool value);
// Comprueba si ha terminado la animación
bool isCompleted(Uint8 index);
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
private:
struct sAnimation
{
SDL_Rect frames[20]; // Hasta 20 frames
Uint8 numFrames;
Uint8 speed;
bool loop;
};
// Vector con las diferentes animaciones y los diferentes frames de cada animación
sAnimation mAnimation[20]; // Hasta 20 animaciones
// Frame actual
Uint8 mCurrentFrame;
// Contador para las animaciones
Uint16 mAnimationCounter;
};
#endif
#endif

View File

@@ -5,7 +5,7 @@
Balloon::Balloon()
{
mSprite = new AnimatedSprite();
init(0, 0, NO_KIND, BALLON_VELX_POSITIVE, 0, nullptr, nullptr);
disable();
}
// Destructor
@@ -15,29 +15,34 @@ Balloon::~Balloon()
}
// Inicializador
void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer)
{
const Uint8 NUM_FRAMES_BALLON = 10;
const Uint8 NUM_FRAMES_BALLON_POP = 12;
const Uint8 NUM_FRAMES_BALLON_BORN = 10;
const Uint8 OFFSET_ORANGE_BALLOONS = 58 * 0;
const Uint8 OFFSET_BLUE_BALLOONS = 58 * 1;
const Uint8 OFFSET_GREEN_BALLOONS = 58 * 2;
const Uint8 OFFSET_PURPLE_BALLOONS = 58 * 3;
const Uint8 OFFSET_POWER_BALL = 58 * 4;
const int OFFSET_EXPLOSIONS = 58 * 5;
switch (kind)
{
case BALLOON_1:
// Posición inicial
mPosX = x;
mPosY = y;
mEnabled = true;
// Alto y ancho del objeto
mWidth = 8;
mHeight = mWidth;
mWidth = BALLOON_SIZE_1;
mHeight = BALLOON_SIZE_1;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = 0;
mMaxVelY = 3;
mMaxVelY = 3.0f;
mGravity = 0.09f;
mDefaultVelY = 3;
mDefaultVelY = 2.6f;
// Puntos que da el globo al ser destruido
mScore = 50;
@@ -47,35 +52,29 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
{
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50, 21 + (37 * i), getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
{
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + 58, 21 + (37 * i), getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
{
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + 58 + 58, 21 + (37 * i), getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
break;
case BALLOON_2:
// Posición inicial
mPosX = x;
mPosY = y;
mEnabled = true;
// Alto y ancho del objeto
mWidth = 13;
mHeight = mWidth;
mWidth = BALLOON_SIZE_2;
mHeight = BALLOON_SIZE_2;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = 0;
mMaxVelY = 3;
mMaxVelY = 3.0f;
mGravity = 0.10f;
mDefaultVelY = 4;
mDefaultVelY = 3.5f;
// Puntos que da el globo al ser destruido
mScore = 100;
@@ -85,35 +84,29 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
{
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37, 21 + (37 * i), getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
{
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + 58, 21 + (37 * i), getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
{
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + 58 + 58, 21 + (37 * i), getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
break;
case BALLOON_3:
// Posición inicial
mPosX = x;
mPosY = y;
mEnabled = true;
// Alto y ancho del objeto
mWidth = 21;
mHeight = mWidth;
mWidth = BALLOON_SIZE_3;
mHeight = BALLOON_SIZE_3;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = 0;
mMaxVelY = 3;
mMaxVelY = 3.0f;
mGravity = 0.10f;
mDefaultVelY = 4.5;
mDefaultVelY = 4.50f;
// Puntos que da el globo al ser destruido
mScore = 200;
@@ -123,35 +116,29 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
{
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37, 37 * i, getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
{
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + 58, 37 * i, getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
{
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + 58 + 58, 37 * i, getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
case BALLOON_4:
// Posición inicial
mPosX = x;
mPosY = y;
mEnabled = true;
// Alto y ancho del objeto
mWidth = 37;
mHeight = mWidth;
mWidth = BALLOON_SIZE_4;
mHeight = BALLOON_SIZE_4;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = 0;
mMaxVelY = 3;
mMaxVelY = 3.0f;
mGravity = 0.10f;
mDefaultVelY = 5;
mDefaultVelY = 4.95f;
// Puntos que da el globo al ser destruido
mScore = 400;
@@ -161,35 +148,157 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
{
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 0, 37 * i, getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_ORANGE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
{
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 58, 37 * i, getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
{
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 58 + 58, 37 * i, getWidth(), getHeight());
}
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
default:
// Posición inicial
mPosX = x;
mPosY = y;
case HEXAGON_1:
mEnabled = true;
// Alto y ancho del objeto
mWidth = 0;
mHeight = mWidth;
mWidth = BALLOON_SIZE_1;
mHeight = BALLOON_SIZE_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;
// Puntos que da el globo al ser destruido
mScore = 50;
// Amenaza que genera el globo
mMenace = 1;
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 50 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 50 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 50 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
break;
case HEXAGON_2:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_SIZE_2;
mHeight = BALLOON_SIZE_2;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = abs(velx) * 2;
mMaxVelY = abs(velx) * 2;
mGravity = 0.00f;
mDefaultVelY = abs(velx) * 2;
// Puntos que da el globo al ser destruido
mScore = 100;
// Amenaza que genera el globo
mMenace = 2;
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 21 + (37 * i), getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 21 + (37 * i), getWidth(), getHeight());
break;
case HEXAGON_3:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_SIZE_3;
mHeight = BALLOON_SIZE_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;
// Puntos que da el globo al ser destruido
mScore = 200;
// Amenaza que genera el globo
mMenace = 4;
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, 37 + OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, 37 + OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, 37 + OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
case HEXAGON_4:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_SIZE_4;
mHeight = BALLOON_SIZE_4;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = abs(velx) * 2;
mMaxVelY = abs(velx) * 2;
mGravity = 0.00f;
mDefaultVelY = abs(velx) * 2;
// Puntos que da el globo al ser destruido
mScore = 400;
// Amenaza que genera el globo
mMenace = 8;
// Establece los frames de cada animación
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_GREEN_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_PURPLE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
case POWER_BALL:
mEnabled = true;
// Alto y ancho del objeto
mWidth = BALLOON_SIZE_4;
mHeight = BALLOON_SIZE_4;
// Inicializa los valores de velocidad y gravedad
mVelX = velx;
mVelY = 0;
mMaxVelY = 0;
mGravity = 0;
mDefaultVelY = 0;
mMaxVelY = 3.0f;
mGravity = 0.10f;
mDefaultVelY = 4.95f;
// Puntos que da el globo al ser destruido
mScore = 0;
@@ -198,13 +307,35 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
mMenace = 0;
// Establece los frames de cada animación
mSprite->setAnimationFrames(0, 0, 0, 0, getWidth(), getHeight());
mSprite->setAnimationFrames(1, 0, 0, 0, getWidth(), getHeight());
mSprite->setAnimationFrames(2, 0, 0, 0, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON; i++)
mSprite->setAnimationFrames(BALLOON_MOVING_ANIMATION, i, OFFSET_POWER_BALL, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_BORN; i++)
mSprite->setAnimationFrames(BALLOON_BORN_ANIMATION, i, OFFSET_BLUE_BALLOONS, 37 * i, getWidth(), getHeight());
for (Uint8 i = 0; i < NUM_FRAMES_BALLON_POP; i++)
mSprite->setAnimationFrames(BALLOON_POP_ANIMATION, i, OFFSET_EXPLOSIONS, 37 * i, getWidth(), getHeight());
break;
default:
mEnabled = false;
mMenace = 0;
break;
}
// Posición inicial
mPosX = x;
mPosY = y;
mBouncing.enabled = false; // Si el efecto está activo
mBouncing.counter = 0; // Countador para el efecto
mBouncing.speed = 0; // Velocidad a la que transcurre el efecto
mBouncing.zoomW = 1.0f; // Zoom aplicado a la anchura
mBouncing.zoomH = 1.0f; // Zoom aplicado a la altura
mBouncing.despX = 0.0f; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
mBouncing.despY = 0.0f;
// Textura con los gráficos del sprite
mSprite->setTexture(texture);
@@ -216,24 +347,35 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
mSprite->setHeight(mHeight);
// Posición X,Y del sprite
mSprite->setPosX(int(mPosX));
mSprite->setPosY(mPosY);
mSprite->setPosX((int)mPosX);
mSprite->setPosY((int)mPosY);
// Tamaño del circulo de colisión
mCollider.r = mWidth / 2;
// Alinea el circulo de colisión con el objeto
shiftColliders();
updateColliders();
// Inicializa variables
mStopped = true;
mStoppedTimer = 0;
mStoppedCounter = 0;
mBlinking = false;
mVisible = true;
mInvulnerable = false;
mBeingCreated = true;
mCreationTimer = creationtimer;
mCreationCounter = creationtimer;
mCreationCounterIni = creationtimer;
mPopping = false;
mBouncing.enabled = false;
mBouncing.counter = 0;
mBouncing.speed = 2;
mBouncing.zoomW = 1;
mBouncing.zoomH = 1;
mBouncing.despX = 0;
mBouncing.despY = 0;
mCounter = 0;
mTravelY = 1.0f;
mSpeed = speed;
// Tipo
mKind = kind;
@@ -280,139 +422,150 @@ void Balloon::allignTo(int x)
mSprite->setPosY(getPosY());
// Alinea el circulo de colisión con el objeto
shiftColliders();
updateColliders();
}
// Pinta el globo en la pantalla
void Balloon::render()
{
if (mVisible)
if ((mVisible) && (mEnabled))
{
mSprite->render();
if (mBouncing.enabled)
{
// 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);
}
else if (isBeingCreated())
{
// Aplica alpha blending
mSprite->getTexture()->setAlpha(255 - (int)((float)mCreationCounter * (255.0f / (float)mCreationCounterIni)));
mSprite->render();
mSprite->getTexture()->setAlpha(255);
}
else
{
mSprite->render();
}
}
}
// Actualiza la posición y estados del globo
void Balloon::move()
{
// Comprobamos si se puede mover
if (isStopped() == false)
// Comprueba si se puede mover
if (!isStopped())
{
// Lo movemos a izquierda o derecha
mPosX += mVelX;
// Lo mueve a izquierda o derecha
mPosX += (mVelX * mSpeed);
// Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
{
// Corregir posición
mPosX -= mVelX;
// Corrige posición
mPosX -= (mVelX * mSpeed);
// Invertir sentido
// Invierte sentido
mVelX = -mVelX;
// Activa el efecto de rebote
bounceStart();
}
// Mueve el globo hacia arriba o hacia abajo
mPosY += int(mVelY);
mPosY += (mVelY * mSpeed);
// Si se sale por arriba
if (mPosY < PLAY_AREA_TOP)
{
// Corregimos
mPosY -= int(mVelY);
// Corrige
mPosY = PLAY_AREA_TOP;
// Invertimos sentido
// Invierte sentido
mVelY = -mVelY;
// Activa el efecto de rebote
bounceStart();
}
// Si el globo se sale por la parte inferior
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
{
// Corregimos
mPosY -= int(mVelY);
// Corrige
mPosY = PLAY_AREA_BOTTOM - mHeight;
// Invertimos colocando una velocidad por defecto
// Invierte colocando una velocidad por defecto
mVelY = -mDefaultVelY;
// Activa el efecto de rebote
bounceStart();
}
// Aplica gravedad al objeto, sin pasarse de un limite establecido
if (int(mVelY) > mMaxVelY)
{
mVelY = float(mMaxVelY);
}
else
/*
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle
Al añadir el modificador de velocidad se reduce la distancia que recorre el objeto y por
tanto recibe mas gravedad. Para solucionarlo se va a aplicar la gravedad cuando se haya
recorrido una distancia igual a la velocidad en Y, que era el cálculo inicial
*/
// Incrementa la variable que calcula la distancia acumulada en Y
mTravelY += mSpeed;
// Si la distancia acumulada en Y es igual a la velocidad, se aplica la gravedad
if (mTravelY >= 1.0f)
{
// Quita el excedente
mTravelY -= 1.0f;
// Aplica la gravedad al objeto sin pasarse de una velocidad máxima
mVelY += mGravity;
std::min(mVelY, mMaxVelY);
}
// Aplica la gravedad al objeto
//if (mVelY > mMaxVelY)
// mVelY = mMaxVelY;
//else if (mCounter % 1 == 0)
// mVelY += mGravity;
// Actualiza la posición del sprite
mSprite->setPosX(getPosX());
mSprite->setPosY(mPosY);
}
// Si no se puede mover:
// Comprobar si se está creando
else if (isBeingCreated() == true)
{
// Actualiza el valor de las variables
setStop(true);
setInvulnerable(true);
// Todavia tiene tiempo en el contador
if (mCreationTimer > 0)
{
// Desplaza lentamente el globo hacia abajo y hacia un lado
if (mCreationTimer % 10 == 0)
{
++mPosY;
mPosX += mVelX;
// Actualiza la posición del sprite
mSprite->setPosX(getPosX());
mSprite->setPosY(mPosY);
// Actualiza la posición del circulo de colisión
shiftColliders();
}
// Hace visible el globo de forma intermitente
if (mCreationTimer > 100)
{
setVisible(mCreationTimer / 10 % 2 == 0);
}
else
{
setVisible(mCreationTimer / 5 % 2 == 0);
}
--mCreationTimer;
}
// El contador ha llegado a cero
else
{
setBeingCreated(false);
setStop(false);
setVisible(true);
setInvulnerable(false);
}
}
// Comprobar si está detenido
else if (isStopped() == true)
{
// Si todavía está detenido, reduce el contador
if (mStoppedTimer > 0)
{
--mStoppedTimer;
} // Si el contador ha llegado a cero, ya no está detenido
else
{
setStop(false);
}
mSprite->setPosY(getPosY());
}
}
// Pone a cero todos los valores del globo
void Balloon::erase()
// Deshabilita el globo y pone a cero todos los valores
void Balloon::disable()
{
init(0, 0, NO_KIND, 0, 0, nullptr, nullptr);
mEnabled = false;
mPosX = 0.0f;
mPosY = 0.0f;
mWidth = 0;
mHeight = 0;
mVelX = 0.0f;
mVelY = 0.0f;
mGravity = 0.0f;
mDefaultVelY = 0.0f;
mMaxVelY = 0.0f;
mBeingCreated = false;
mBlinking = false;
mInvulnerable = false;
mPopping = false;
mStopped = false;
mVisible = false;
mCollider.x = 0;
mCollider.y = 0;
mCollider.r = 0;
mCreationCounter = 0;
mCreationCounterIni = 0;
mScore = 0;
mStoppedCounter = 0;
mTimeToLive = 0;
mKind = 0;
mMenace = 0;
}
// Explosiona el globo
@@ -430,63 +583,124 @@ void Balloon::pop()
// Actualiza al globo a su posicion, animación y controla los contadores
void Balloon::update()
{
move();
setAnimation();
shiftColliders();
if (mEnabled)
{
move();
updateAnimation();
updateColliders();
updateState();
updateBounce();
mCounter++;
}
}
// Actualiza los estados del globo
void Balloon::updateState()
{
// Si está explotando
if (isPopping())
{
setInvulnerable(true);
setStop(true);
if (mTimeToLive > 0)
if (mSprite->isCompleted(BALLOON_POP_ANIMATION))
{
--mTimeToLive;
mSprite->setCompleted(BALLOON_POP_ANIMATION, false);
mTimeToLive = 0;
disable();
}
else if (mTimeToLive > 0)
mTimeToLive--;
else
disable();
}
// Si se está creando
if (isBeingCreated())
{
// Actualiza el valor de las variables
setStop(true);
setInvulnerable(true);
// Todavia tiene tiempo en el contador
if (mCreationCounter > 0)
{
// Desplaza lentamente el globo hacia abajo y hacia un lado
if (mCreationCounter % 10 == 0)
{
mPosY++;
mPosX += mVelX;
// Comprueba no se salga por los laterales
if ((mPosX < PLAY_AREA_LEFT) || (mPosX > (PLAY_AREA_RIGHT - mWidth)))
{
// Corrige y cambia el sentido de la velocidad
mPosX -= mVelX;
mVelX = -mVelX;
}
// Actualiza la posición del sprite
mSprite->setPosX(getPosX());
mSprite->setPosY(getPosY());
// Actualiza la posición del circulo de colisión
updateColliders();
}
// Hace visible el globo de forma intermitente
//if (mCreationCounter > 100)
// setVisible(mCreationCounter / 10 % 2 == 0);
//else
// setVisible(mCreationCounter / 5 % 2 == 0);
mCreationCounter--;
}
// El contador ha llegado a cero
else
{
erase();
setBeingCreated(false);
setStop(false);
setVisible(true);
setInvulnerable(false);
}
}
// Solo comprueba el estado detenido cuando no se está creando
else if (isStopped())
{
// Si está detenido, reduce el contador
if (mStoppedCounter > 0)
mStoppedCounter--;
// Si el contador ha llegado a cero, ya no está detenido
else if (!isPopping()) // Quitarles el estado "detenido" si no estan explosionandoxq
setStop(false);
}
}
// Establece la animación correspondiente al estado
void Balloon::setAnimation()
void Balloon::updateAnimation()
{
// Establece el frame de animación
if (isPopping())
{
mSprite->animate(BALLOON_POP_ANIMATION);
}
else if (isBeingCreated())
{
mSprite->animate(BALLOON_BORN_ANIMATION);
}
else
{
mSprite->animate(BALLOON_MOVING_ANIMATION);
}
}
// Comprueba si el globo tiene algun tipo asignado
bool Balloon::isActive()
// Comprueba si el globo está habilitado
bool Balloon::isEnabled()
{
if (mKind == NO_KIND)
{
return false;
}
else
{
return true;
}
return mEnabled;
}
// Obtiene del valor de la variable
int Balloon::getPosX()
float Balloon::getPosX()
{
return int(mPosX);
return mPosX;
}
// Obtiene del valor de la variable
int Balloon::getPosY()
float Balloon::getPosY()
{
return mPosY;
}
@@ -515,12 +729,29 @@ void Balloon::setVelY(float velY)
mVelY = velY;
}
// Establece el valor de la variable
void Balloon::setSpeed(float speed)
{
mSpeed = speed;
}
// Obtiene del valor de la variable
int Balloon::getKind()
{
return mKind;
}
// Obtiene la clase a la que pertenece el globo
Uint8 Balloon::getClass()
{
if ((mKind >= BALLOON_1) && (mKind <= BALLOON_4))
return BALLOON_CLASS;
else if ((mKind >= HEXAGON_1) && (mKind <= HEXAGON_4))
return HEXAGON_CLASS;
else
return 0;
}
// Establece el valor de la variable
void Balloon::setStop(bool state)
{
@@ -608,13 +839,13 @@ Uint16 Balloon::getTimeToLive()
// Establece el valor de la variable
void Balloon::setStoppedTimer(Uint16 time)
{
mStoppedTimer = time;
mStoppedCounter = time;
}
// Obtiene del valor de la variable
Uint16 Balloon::getStoppedTimer()
{
return mStoppedTimer;
return mStoppedCounter;
}
// Obtiene del valor de la variable
@@ -624,13 +855,13 @@ Uint16 Balloon::getScore()
}
// Obtiene el circulo de colisión
Circle &Balloon::getCollider()
circle_t &Balloon::getCollider()
{
return mCollider;
}
// Alinea el circulo de colisión con la posición del objeto globo
void Balloon::shiftColliders()
void Balloon::updateColliders()
{
// Align collider to center of balloon
mCollider.x = Uint16(mPosX + mCollider.r);
@@ -640,5 +871,45 @@ void Balloon::shiftColliders()
// Obtiene le valor de la variable
Uint8 Balloon::getMenace()
{
return mMenace;
if (isEnabled())
return mMenace;
else
return 0;
}
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;
}
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;
}
void Balloon::updateBounce()
{
if (mBouncing.enabled)
{
mBouncing.zoomW = mBouncing.w[mBouncing.counter / mBouncing.speed];
mBouncing.zoomH = mBouncing.h[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))
bounceStop();
}
}

View File

@@ -1,13 +1,71 @@
#pragma once
#include "struct.h"
#include "utils.h"
#include "animatedsprite.h"
#ifndef BALLOON_H
#define BALLOON_H
#define MAX_BOUNCE 10
// Clase globo
class Balloon
{
private:
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
struct bouncing // Estructura para las variables para el efecto de los rebotes
{
bool enabled; // Si el efecto está activo
Uint8 counter; // Countador para el efecto
Uint8 speed; // Velocidad a la que transcurre el efecto
float zoomW; // Zoom aplicado a la anchura
float zoomH; // Zoom aplicado a la altura
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
float despY; // idem
// Vector con los valores de zoom para el ancho y alto del globo
float w[MAX_BOUNCE] = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
float h[MAX_BOUNCE] = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
};
bouncing mBouncing;
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo
void bounceStart(); // Activa el efecto
void bounceStop(); // Detiene el efecto
void updateBounce(); // Aplica el efecto
void updateState(); // Actualiza los estados del globo
void updateAnimation(); // Establece la animación correspondiente
void setBeingCreated(bool state); // Establece el valor de la variable
void setTimeToLive(Uint16 time); // Establece el valor de la variable
Uint16 getTimeToLive(); // Obtiene del valor de la variable
public:
// Constructor
Balloon();
@@ -16,7 +74,7 @@ public:
~Balloon();
// Inicializador
void init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer, LTexture* texture, SDL_Renderer *renderer);
void init(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
// Centra el globo en la posición X
void allignTo(int x);
@@ -27,8 +85,8 @@ public:
// Actualiza la posición y estados del globo
void move();
// Pone a cero todos los valores del globo
void erase();
// Deshabilita el globo y pone a cero todos los valores
void disable();
// Explosiona el globo
void pop();
@@ -36,17 +94,14 @@ public:
// Actualiza al globo a su posicion, animación y controla los contadores
void update();
// Establece la animación correspondiente
void setAnimation();
// Comprueba si el globo tiene algun tipo asignado
bool isActive();
// Comprueba si el globo está habilitado
bool isEnabled();
// Obtiene del valor de la variable
int getPosX();
float getPosX();
// Obtiene del valor de la variable
int getPosY();
float getPosY();
// Obtiene del valor de la variable
float getVelY();
@@ -60,9 +115,15 @@ public:
// Establece el valor de la variable
void setVelY(float velY);
// Establece el valor de la variable
void setSpeed(float speed);
// Obtiene del valor de la variable
int getKind();
// Obtiene la clase a la que pertenece el globo
Uint8 getClass();
// Establece el valor de la variable
void setStop(bool state);
@@ -87,9 +148,6 @@ public:
// Obtiene del valor de la variable
bool isInvulnerable();
// Establece el valor de la variable
void setBeingCreated(bool state);
// Obtiene del valor de la variable
bool isBeingCreated();
@@ -99,12 +157,6 @@ public:
// Obtiene del valor de la variable
bool isPopping();
// Establece el valor de la variable
void setTimeToLive(Uint16 time);
// Obtiene del valor de la variable
Uint16 getTimeToLive();
// Establece el valor de la variable
void setStoppedTimer(Uint16 time);
@@ -115,71 +167,10 @@ public:
Uint16 getScore();
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
// Obtiene le valor de la variable
Uint8 getMenace();
private:
// Posición X,Y del objeto globo
float mPosX;
int mPosY;
// Alto y ancho del objeto globo
Uint8 mWidth;
Uint8 mHeight;
// Variables para controlar la velocidad del globo
float mVelX;
float mVelY;
float mGravity;
float mDefaultVelY;
int mMaxVelY;
// Puntos que da el globo al ser destruido
Uint16 mScore;
// Nivel de amenaza del globo
Uint8 mMenace;
// Indica si el globo está parado
bool mStopped;
// Temporizador para controlar el estado "parado"
Uint16 mStoppedTimer;
// Indica si el globo está intermitente
bool mBlinking;
// Indica si el globo es visible
bool mVisible;
// Indica si el globo es invulnerable
bool mInvulnerable;
// Indica si el globo se está creando
bool mBeingCreated;
// Indica si el globo está explotando
bool mPopping;
// Indica el tiempo de vida que le queda al globo
Uint16 mTimeToLive;
// Temporizador para controlar el estado "creandose"
Uint16 mCreationTimer;
// Tipo de globo
Uint8 mKind;
// Sprite del objeto globo
AnimatedSprite *mSprite;
// Circulo de colisión del objeto
Circle mCollider;
// Alinea el circulo de colisión con la posición del objeto globo
void shiftColliders();
};
#endif

View File

@@ -200,7 +200,7 @@ int Bullet::getKind()
}
// Obtiene el circulo de colisión
Circle &Bullet::getCollider()
circle_t &Bullet::getCollider()
{
return mCollider;
}

View File

@@ -1,5 +1,5 @@
#pragma once
#include "struct.h"
#include "utils.h"
#include "sprite.h"
#ifndef BULLET_H
@@ -49,7 +49,7 @@ public:
int getKind();
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
private:
// Posición X/Y del objeto
@@ -71,7 +71,7 @@ private:
Sprite *mSprite;
// Balloon's collision circle
Circle mCollider;
circle_t mCollider;
// Alinea el circulo de colisión con el objeto
void shiftColliders();

89
source/coffeedrop.cpp Normal file
View File

@@ -0,0 +1,89 @@
#include "const.h"
#include "coffeedrop.h"
#ifndef UNUSED
// Constructor
CoffeeDrop::CoffeeDrop()
{
mPosX = 0;
mPosY = 0;
mWidth = 8;
mHeight = 8;
mVelX = 0;
mVelY = 0;
mGravity = 0.1f;
mFloor = 0;
mEnabled = false;
mSprite = new Sprite();
mAlpha = 128;
}
// Destructor
CoffeeDrop::~CoffeeDrop()
{
delete mSprite;
}
// Inicializador
void CoffeeDrop::init(LTexture *texture, SDL_Renderer *renderer, float x, float y, float velX, float velY, int floor)
{
mEnabled = true;
mPosX = x;
mPosY = y;
mVelX = velX;
mVelY = velY;
mFloor = floor;
mSprite->setRenderer(renderer);
mSprite->setTexture(texture);
mSprite->setSpriteClip(256, 97, mWidth, mHeight);
mSprite->setPosX(x);
mSprite->setPosY(y);
}
// Actualiza las variables del objeto
void CoffeeDrop::update()
{
if (mEnabled)
{
mVelY += mGravity;
mPosX += mVelX;
mPosY += mVelY;
mSprite->setPosX((int)mPosX);
mSprite->setPosY((int)mPosY);
if ((mPosY > mFloor) || (mPosX > PLAY_AREA_RIGHT) || ((mPosX - mWidth) < PLAY_AREA_LEFT))
mEnabled = false;
mAlpha -= 2;
if (mAlpha == 0)
mEnabled = false;
}
}
// Pinta el objeto
void CoffeeDrop::render()
{
if (mEnabled)
{
mSprite->getTexture()->setAlpha(mAlpha);
mSprite->render();
mSprite->getTexture()->setAlpha(255);
}
}
// Deshabilita el objeto
void CoffeeDrop::disable()
{
mEnabled = false;
}
// Comprueba si està habilitado
bool CoffeeDrop::isEnabled()
{
return mEnabled;
}
#endif

50
source/coffeedrop.h Normal file
View File

@@ -0,0 +1,50 @@
#pragma once
#include "sprite.h"
#ifndef COFFEEDROP_H
#define COFFEEDROP_H
#ifndef UNUSED
// Clase CoffeeDrop. Gotas de café que aparecen al explotar un globo
class CoffeeDrop
{
private:
float mPosX; // Posicion en el eje X del objeto
float mPosY; // Posicion en el eje Y del objeto
Uint8 mWidth; // Ancho del sprite
Uint8 mHeight; // Alto del sprite
float mVelX; // Velocidad en el eje X
float mVelY; // Velocidad en el eje Y
float mGravity; // Aceleración en el eje Y
int mFloor; // Punto donde se encuentra el suelo y desaparecen
bool mEnabled; // Si esta habilitado. Sirve para saber si se pinta, se actualiza o se puede usar
Sprite *mSprite; // Puntero al sprite con los graficos
Uint8 mAlpha;
public:
// Constructor
CoffeeDrop();
// Destructor
~CoffeeDrop();
// Inicializador
void init(LTexture *texture, SDL_Renderer *renderer, float x, float y, float velX, float velY, int floor);
// Actualiza las variables del objeto
void update();
// Pinta el objeto
void render();
// Deshabilita el objeto
void disable();
// Comprueba si està habilitado
bool isEnabled();
};
#endif
#endif

View File

@@ -7,73 +7,75 @@
// Textos
#define WINDOW_CAPTION "Coffee Crisis"
#define TEXT_COPYRIGHT "@2020,2021 JAILDESIGNER (V1.3*)"
#define TEXT_COPYRIGHT "@2020,2021 JAILDESIGNER (V1.4)"
// Recursos
const Uint8 BINFILE_SCORE = 0;
const Uint8 BINFILE_DEMO = 1;
const Uint8 BINFILE_CONFIG = 2;
#define BINFILE_SCORE 0
#define BINFILE_DEMO 1
#define BINFILE_CONFIG 2
const Uint8 TOTAL_BINFILE = 3;
#define TOTAL_BINFILE 3
const Uint8 MUSIC_INTRO = 0;
const Uint8 MUSIC_PLAYING = 1;
const Uint8 MUSIC_TITLE = 2;
#define MUSIC_INTRO 0
#define MUSIC_PLAYING 1
#define MUSIC_TITLE 2
const Uint8 TOTAL_MUSIC = 3;
#define TOTAL_MUSIC 3
const Uint8 SOUND_BALLON = 0;
const Uint8 SOUND_BULLET = 1;
const Uint8 SOUND_MENU_SELECT = 2;
const Uint8 SOUND_MENU_CANCEL = 3;
const Uint8 SOUND_MENU_MOVE = 4;
const Uint8 SOUND_TITLE = 5;
const Uint8 SOUND_PLAYER_COLLISION = 6;
const Uint8 SOUND_HISCORE = 7;
const Uint8 SOUND_ITEM_DROP = 8;
const Uint8 SOUND_ITEM_PICKUP = 9;
const Uint8 SOUND_COFFEE_OUT = 10;
const Uint8 SOUND_STAGE_CHANGE = 11;
const Uint8 SOUND_BUBBLE1 = 12;
const Uint8 SOUND_BUBBLE2 = 13;
const Uint8 SOUND_BUBBLE3 = 14;
const Uint8 SOUND_BUBBLE4 = 15;
#define SOUND_BALLOON 0
#define SOUND_BUBBLE1 1
#define SOUND_BUBBLE2 2
#define SOUND_BUBBLE3 3
#define SOUND_BUBBLE4 4
#define SOUND_BULLET 5
#define SOUND_COFFEE_OUT 6
#define SOUND_HISCORE 7
#define SOUND_ITEM_DROP 8
#define SOUND_ITEM_PICKUP 9
#define SOUND_MENU_CANCEL 10
#define SOUND_MENU_MOVE 11
#define SOUND_MENU_SELECT 12
#define SOUND_PLAYER_COLLISION 13
#define SOUND_STAGE_CHANGE 14
#define SOUND_TITLE 15
const Uint8 TOTAL_SOUND = 16;
#define TOTAL_SOUND 16
const Uint8 TEXTURE_BALLOON = 0;
const Uint8 TEXTURE_BULLET = 1;
const Uint8 TEXTURE_FONT_BLACK = 2;
const Uint8 TEXTURE_FONT_NOKIA = 3;
const Uint8 TEXTURE_FONT_WHITE = 4;
const Uint8 TEXTURE_GAME_BG = 5;
const Uint8 TEXTURE_GAME_TEXT = 6;
const Uint8 TEXTURE_INTRO = 7;
const Uint8 TEXTURE_ITEMS = 8;
const Uint8 TEXTURE_LOGO = 9;
const Uint8 TEXTURE_MENU = 10;
const Uint8 TEXTURE_PLAYER_BODY = 11;
const Uint8 TEXTURE_PLAYER_LEGS = 12;
const Uint8 TEXTURE_PLAYER_DEATH = 13;
const Uint8 TEXTURE_TITLE = 14;
#define TEXTURE_BALLOON 0
#define TEXTURE_BULLET 1
#define TEXTURE_FONT_BLACK 2
#define TEXTURE_FONT_BLACK_X2 3
#define TEXTURE_FONT_NOKIA 4
#define TEXTURE_FONT_WHITE 5
#define TEXTURE_FONT_WHITE_X2 6
#define TEXTURE_GAME_BG 7
#define TEXTURE_GAME_TEXT 8
#define TEXTURE_INTRO 9
#define TEXTURE_ITEMS 10
#define TEXTURE_LOGO 11
#define TEXTURE_MENU 12
#define TEXTURE_PLAYER_BODY 13
#define TEXTURE_PLAYER_DEATH 14
#define TEXTURE_PLAYER_LEGS 15
#define TEXTURE_TITLE 16
const Uint8 TOTAL_TEXTURE = 15;
#define TOTAL_TEXTURE 17
// Tamaño de bloque
const Uint8 BLOCK = 8;
const Uint8 HALF_BLOCK = BLOCK / 2;
#define BLOCK 8
#define HALF_BLOCK BLOCK / 2
// Tamaño de la pantalla real
const int SCREEN_WIDTH = 256;
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4; // 192
#define SCREEN_WIDTH 256
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4;
// Tamaño de la pantalla que se muestra
const int VIEW_WIDTH = SCREEN_WIDTH * 3; // 768
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; // 576
const int VIEW_WIDTH = SCREEN_WIDTH * 3;
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
// Cantidad de enteros a escribir en los ficheros de datos
const Uint8 TOTAL_SCORE_DATA = 3;
const Uint16 TOTAL_DEMO_DATA = 2000;
#define TOTAL_SCORE_DATA 3
#define TOTAL_DEMO_DATA 2000
// Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK);
@@ -82,7 +84,9 @@ const int PLAY_AREA_LEFT = (0 * BLOCK);
const int PLAY_AREA_RIGHT = SCREEN_WIDTH - (0 * BLOCK);
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
@@ -95,95 +99,86 @@ const int SCREEN_CENTER_Y = SCREEN_HEIGHT / 2;
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
// Color transparente para los sprites
const Uint8 COLOR_KEY_R = 0xff;
const Uint8 COLOR_KEY_G = 0x00;
const Uint8 COLOR_KEY_B = 0xff;
// Opciones de menu
const int MENU_NO_OPTION = -1;
const int MENU_OPTION_START = 0;
const int MENU_OPTION_QUIT = 1;
const int MENU_OPTION_TOTAL = 2;
// Selector de menu
const int MENU_SELECTOR_BLACK = (BLOCK * 0);
const int MENU_SELECTOR_WHITE = (BLOCK * 1);
#define MENU_NO_OPTION -1
#define MENU_OPTION_START 0
#define MENU_OPTION_QUIT 1
#define MENU_OPTION_TOTAL 2
// Tipos de fondos para el menu
const int MENU_BACKGROUND_TRANSPARENT = 0;
const int MENU_BACKGROUND_SOLID = 1;
#define MENU_BACKGROUND_TRANSPARENT 0
#define MENU_BACKGROUND_SOLID 1
// Estados del jugador
const Uint8 PLAYER_STATUS_WALKING_LEFT = 0;
const Uint8 PLAYER_STATUS_WALKING_RIGHT = 1;
const Uint8 PLAYER_STATUS_WALKING_STOP = 2;
#define PLAYER_STATUS_WALKING_LEFT 0
#define PLAYER_STATUS_WALKING_RIGHT 1
#define PLAYER_STATUS_WALKING_STOP 2
const Uint8 PLAYER_STATUS_FIRING_UP = 0;
const Uint8 PLAYER_STATUS_FIRING_LEFT = 1;
const Uint8 PLAYER_STATUS_FIRING_RIGHT = 2;
const Uint8 PLAYER_STATUS_FIRING_NO = 3;
#define PLAYER_STATUS_FIRING_UP 0
#define PLAYER_STATUS_FIRING_LEFT 1
#define PLAYER_STATUS_FIRING_RIGHT 2
#define PLAYER_STATUS_FIRING_NO 3
const Uint8 PLAYER_ANIMATION_LEGS_WALKING_LEFT = 0;
const Uint8 PLAYER_ANIMATION_LEGS_WALKING_RIGHT = 1;
const Uint8 PLAYER_ANIMATION_LEGS_WALKING_STOP = 2;
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
const Uint8 PLAYER_ANIMATION_BODY_WALKING_LEFT = 0;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_LEFT = 1;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_RIGHT = 2;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_RIGHT = 3;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_STOP = 4;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_UP = 5;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT = 6;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT = 7;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT = 8;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT = 9;
const Uint8 PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT = 10;
const Uint8 PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT = 11;
#define PLAYER_ANIMATION_BODY_WALKING_LEFT 0
#define PLAYER_ANIMATION_BODY_FIRING_LEFT 1
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT 2
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT 3
#define PLAYER_ANIMATION_BODY_WALKING_STOP 4
#define PLAYER_ANIMATION_BODY_FIRING_UP 5
// Variables del jugador
const Uint16 PLAYER_INVULNERABLE_TIMER = 200;
#define PLAYER_INVULNERABLE_COUNTER 200
// Estados del juego
const Uint8 GAME_STATE_TITLE = 0;
const Uint8 GAME_STATE_PLAYING = 1;
const Uint8 GAME_STATE_QUIT = 2;
const Uint8 GAME_STATE_GAME_OVER_SCREEN = 3;
const Uint8 GAME_STATE_INTRO = 4;
const Uint8 GAME_STATE_DEMO = 5;
const Uint8 GAME_STATE_INSTRUCTIONS = 6;
const Uint8 GAME_STATE_LOGO = 7;
const Uint8 GAME_STATE_INIT = 8;
// Secciones del programa
#define PROG_SECTION_LOGO 0
#define PROG_SECTION_INTRO 1
#define PROG_SECTION_TITLE 2
#define PROG_SECTION_GAME 3
// Secciones del juego
#define GAME_SECTION_PLAY 0
#define GAME_SECTION_PAUSE 1
#define GAME_SECTION_GAMEOVER 2
// Secciones del titulo
#define TITLE_SECTION_1 0
#define TITLE_SECTION_2 1
#define TITLE_SECTION_3 2
#define TITLE_SECTION_INSTRUCTIONS 3
// Estados de cada elemento que pertenece a un evento
const Uint8 EVENT_WAITING = 1;
const Uint8 EVENT_RUNNING = 2;
const Uint8 EVENT_COMPLETED = 3;
#define EVENT_WAITING 1
#define EVENT_RUNNING 2
#define EVENT_COMPLETED 3
// Cantidad de eventos de la intro
const Uint8 INTRO_TOTAL_BITMAPS = 6;
const Uint8 INTRO_TOTAL_TEXTS = 9;
const Uint8 INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
#define INTRO_TOTAL_BITMAPS 6
#define INTRO_TOTAL_TEXTS 9
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
// Cantidad de eventos de la pantalla de titulo
const Uint8 TITLE_TOTAL_EVENTS = 2;
#define TITLE_TOTAL_EVENTS 2
// Relaciones de Id con nomnbres
const Uint8 BITMAP0 = 0;
const Uint8 BITMAP1 = 1;
const Uint8 BITMAP2 = 2;
const Uint8 BITMAP3 = 3;
const Uint8 BITMAP4 = 4;
const Uint8 BITMAP5 = 5;
const Uint8 TEXT0 = 6;
const Uint8 TEXT1 = 7;
const Uint8 TEXT2 = 8;
const Uint8 TEXT3 = 9;
const Uint8 TEXT4 = 10;
const Uint8 TEXT5 = 11;
const Uint8 TEXT6 = 12;
const Uint8 TEXT7 = 13;
const Uint8 TEXT8 = 14;
#define BITMAP0 0
#define BITMAP1 1
#define BITMAP2 2
#define BITMAP3 3
#define BITMAP4 4
#define BITMAP5 5
#define TEXT0 6
#define TEXT1 7
#define TEXT2 8
#define TEXT3 9
#define TEXT4 10
#define TEXT5 11
#define TEXT6 12
#define TEXT7 13
#define TEXT8 14
// Anclajes para el marcador de puntos
const int SCORE_WORD_X = (SCREEN_WIDTH / 4) - ((5 * BLOCK) / 2);
@@ -198,85 +193,112 @@ const int HISCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
const int MULTIPLIER_WORD_X = (SCREEN_WIDTH / 2) - ((4 * BLOCK) / 2);
const int MULTIPLIER_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
const int MULTIPLIER_NUMBER_X = (SCREEN_WIDTH / 2) - ((3 * BLOCK) / 2);;
const int MULTIPLIER_NUMBER_X = (SCREEN_WIDTH / 2) - ((3 * BLOCK) / 2);
const int MULTIPLIER_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
// Ningun tipo
const Uint8 NO_KIND = 0;
#define NO_KIND 0
// Tipos de globo
const Uint8 BALLOON_1 = 1;
const Uint8 BALLOON_2 = 2;
const Uint8 BALLOON_3 = 3;
const Uint8 BALLOON_4 = 4;
#define BALLOON_1 1
#define BALLOON_2 2
#define BALLOON_3 3
#define BALLOON_4 4
#define HEXAGON_1 5
#define HEXAGON_2 6
#define HEXAGON_3 7
#define HEXAGON_4 8
#define POWER_BALL 9
// Clases de globo
#define BALLOON_CLASS 0
#define HEXAGON_CLASS 1
// Velocidad del globo
const float BALLON_VELX_POSITIVE = 0.7f;
const float BALLON_VELX_NEGATIVE = -0.7f;
#define BALLOON_VELX_POSITIVE 0.7f
#define BALLOON_VELX_NEGATIVE -0.7f
// Indice para las animaciones de los globos
const Uint8 BALLOON_MOVING_ANIMATION = 0;
const Uint8 BALLOON_POP_ANIMATION = 1;
const Uint8 BALLOON_BORN_ANIMATION = 2;
#define BALLOON_MOVING_ANIMATION 0
#define BALLOON_POP_ANIMATION 1
#define BALLOON_BORN_ANIMATION 2
// Cantidad posible de globos
const Uint8 MAX_BALLOONS = 75;
#define MAX_BALLOONS 100
// Velocidades a las que se mueven los enemigos
#define BALLOON_SPEED_1 0.60f
#define BALLOON_SPEED_2 0.70f
#define BALLOON_SPEED_3 0.80f
#define BALLOON_SPEED_4 0.90f
#define BALLOON_SPEED_5 1.00f
// Tamaño de los globos
#define BALLOON_SIZE_1 8
#define BALLOON_SIZE_2 13
#define BALLOON_SIZE_3 21
#define BALLOON_SIZE_4 37
// Tipos de bala
const Uint8 BULLET_UP = 1;
const Uint8 BULLET_LEFT = 2;
const Uint8 BULLET_RIGHT = 3;
#define BULLET_UP 1
#define BULLET_LEFT 2
#define BULLET_RIGHT 3
// Cantidad posible de globos
const Uint8 MAX_BULLETS = 50;
#define MAX_BULLETS 50
// Tipos de objetos
const Uint8 ITEM_POINTS_1_DISK = 1;
const Uint8 ITEM_POINTS_2_GAVINA = 2;
const Uint8 ITEM_POINTS_3_PACMAR = 3;
const Uint8 ITEM_CLOCK = 4;
const Uint8 ITEM_TNT = 5;
const Uint8 ITEM_COFFEE = 6;
#define ITEM_POINTS_1_DISK 1
#define ITEM_POINTS_2_GAVINA 2
#define ITEM_POINTS_3_PACMAR 3
#define ITEM_CLOCK 4
#define ITEM_TNT 5
#define ITEM_COFFEE 6
#define ITEM_POWER_BALL 7
// Cantidad de objetos simultaneos
const Uint8 MAX_ITEMS = 5;
#define MAX_ITEMS 5
// Valores para las variables asociadas a los objetos
const Uint8 REMAINING_EXPLOSIONS = 3;
const Uint8 REMAINING_EXPLOSIONS_TIMER = 50;
const Uint16 TIME_STOPPED_TIMER = 300;
#define REMAINING_EXPLOSIONS 3
#define REMAINING_EXPLOSIONS_COUNTER 50
#define TIME_STOPPED_COUNTER 300
// Estados de entrada
const Uint8 NO_INPUT = 0;
const Uint8 INPUT_UP = 1;
const Uint8 INPUT_DOWN = 2;
const Uint8 INPUT_LEFT = 3;
const Uint8 INPUT_RIGHT = 4;
const Uint8 INPUT_ACCEPT = 5;
const Uint8 INPUT_CANCEL = 6;
const Uint8 INPUT_FIRE_UP = 7;
const Uint8 INPUT_FIRE_LEFT = 8;
const Uint8 INPUT_FIRE_RIGHT = 9;
const Uint8 INPUT_PAUSE = 10;
#define NO_INPUT 0
#define INPUT_UP 1
#define INPUT_DOWN 2
#define INPUT_LEFT 3
#define INPUT_RIGHT 4
#define INPUT_ACCEPT 5
#define INPUT_CANCEL 6
#define INPUT_FIRE_UP 7
#define INPUT_FIRE_LEFT 8
#define INPUT_FIRE_RIGHT 9
#define INPUT_PAUSE 10
// Zona muerta del mando analógico
const int JOYSTICK_DEAD_ZONE = 8000;
#define JOYSTICK_DEAD_ZONE 8000
// Tipos de mensajes para el retorno de las funciones
const Uint8 MSG_OK = 0;
const Uint8 MSG_BULLET_OUT = 1;
#define MSG_OK 0
#define MSG_BULLET_OUT 1
// Tipos de texto
const Uint8 TEXT_FIXED = 0;
const Uint8 TEXT_VARIABLE = 1;
#define TEXT_FIXED 0
#define TEXT_VARIABLE 1
// Cantidad de elementos del vector de SmartSprites
const Uint8 MAX_SMART_SPRITES = 10;
#define MAX_SMART_SPRITES 10
// Cantidad máxima de gotas de café
#define MAX_COFFEE_DROPS 100
// Contadores
const Uint16 TITLE_TIMER = 800;
const Uint8 STAGE_COUNTER = 200;
const Uint16 INSTRUCTIONS_COUNTER = 600;
const Uint16 DEATH_COUNTER = 350;
#define TITLE_COUNTER 800
#define STAGE_COUNTER 200
#define INSTRUCTIONS_COUNTER 600
#define DEATH_COUNTER 350
#define SHAKE_COUNTER 10
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -6,12 +6,14 @@
#include "player.h"
#include "balloon.h"
#include "bullet.h"
#include "coffeedrop.h"
#include "item.h"
#include "text.h"
#include "text2.h"
#include "menu.h"
#include "const.h"
#include "jail_audio.h"
#include "utils.h"
#include <math.h>
#ifndef GAMEDIRECTOR_H
@@ -20,37 +22,350 @@
// GameDirector
class GameDirector
{
private:
SDL_Window *mWindow; // La ventana donde dibujamos
SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Event *mEventHandler; // Manejador de eventos
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
SDL_Texture *mTitleSurface; // Textura para dibujar el fondo de la pantalla de título
SDL_Texture *mInstructionsSurface; // Textura donde dibujar las instrucciones
SDL_Joystick *mGameController; // Manejador para el mando 1
SDL_Haptic *mControllerHaptic; // Manejador para el mando con vibración
bool mGameControllerFound; // Variable para saber si hay un mando conectado
#ifndef UNUSED
CoffeeDrop *mCoffeeDrop[MAX_COFFEE_DROPS]; // Vector con todas ls gotas de café;
#endif
struct text_t
{
Text *white; // Texto blanco de 8x8
Text *whiteX2; // Texto blanco de 16x16
Text *black; // Texto negro de 8x8
Text *blackX2; // Texto negro de 16x16
Text *nokia; // Texto de anchura variable y 10px de alto
};
text_t mText; // Variable con todos los objetos de texto
struct menu_t
{
Menu *title; // Menu de la pantalla de título
Menu *pause; // Menú de la pantalla de pausa
Menu *gameOver; // Menú de la pantalla de game over
Menu *options; // Menú de la pantalla de opciones
Menu *active; // Menu activo (de momento para la pantalla del titulo)
bool keyPressed; // Variable para evitar la repetición de teclas en los menus
};
menu_t mMenu; // Variable con todos los objetos menus y sus variables
struct intro_t
{
SmartSprite *bitmap[INTRO_TOTAL_BITMAPS]; // Vector con los sprites inteligentes para los dibujos de la intro
Text2 *text[INTRO_TOTAL_TEXTS]; // Textos de la intro
Uint8 events[INTRO_TOTAL_EVENTS]; // Vector para coordinar los eventos de la intro
};
intro_t mIntro; // Contiene todas las variables de la sección 'Intro'
struct enemyInits_t
{
int x; // Posición en el eje X donde crear al enemigo
int y; // Posición en el eje Y donde crear al enemigo
float velX; // Velocidad inicial en el eje X
Uint8 kind; // Tipo de enemigo
Uint16 creationCounter; // Temporizador para la creación del enemigo
};
struct enemyFormation_t // Contiene la información de una formación enemiga
{
Uint8 numberOfEnemies; // Cantidad de enemigos que forman la formación
enemyInits_t init[50]; // Vector con todas las inicializaciones de los enemigos de la formación
};
enemyFormation_t mEnemyFormation[100]; // Vector con todas las formaciones enemigas
struct enemyPool_t
{
enemyFormation_t *set[10]; // Conjunto de formaciones enemigas
};
enemyPool_t mEnemyPool[10]; // Variable con los diferentes conjuntos de formaciones enemigas
struct stage_t // Contiene todas las variables relacionadas con una fase
{
enemyPool_t *enemyPool; // El conjunto de formaciones enemigas de la fase
Uint16 currentPower; // Cantidad actual de poder
Uint16 powerToComplete; // Cantidad de poder que se necesita para completar la fase
Uint8 maxMenace; // Umbral máximo de amenaza de la fase
Uint8 minMenace; // Umbral mínimo de amenaza de la fase
Uint8 number; // Numero de fase
};
struct effect_t
{
bool flash; // Indica si se ha de pintar la pantalla de blanco
bool shake; // Indica si se ha de agitar la pantalla
Uint8 shakeCounter; // Contador para medir el tiempo que dura el efecto
};
struct game_t
{
Uint32 score; // Puntuación actual
Uint32 hiScore; // Puntuación máxima
Uint8 section; // Seccion actual dentro del juego
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
Uint8 currentStage; // Indica la fase actual
stage_t stage[10]; // Variable con los datos de cada pantalla
Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage
float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto
float getReadyBitmapPath[STAGE_COUNTER]; // Vector con los puntos X por donde se desplaza el texto
Uint16 deathCounter; // Contador para la animación de muerte del jugador
Uint8 deathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
Uint8 menaceCurrent; // Nivel de amenaza actual
Uint8 menaceThreshold; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el numero de globos
bool timeStopped; // Indica si el tiempo está detenido
Uint16 timeStoppedCounter; // Temporizador para llevar la cuenta del tiempo detenido
Uint8 remainingExplosions; // Cantidad de explosiones restantes
Uint16 remainingExplosionsCounter; // Temporizador para la cantidad de explosiones restantes
bool explosionTime; // Indica si las explosiones estan en marcha
Uint32 counter; // Contador para el juego
Uint32 scoreDataFile[TOTAL_SCORE_DATA]; // Datos del fichero de puntos
Sprite *getReadyBitmap; // Sprite para el texto de GetReady del principio de la partida
SmartSprite *_1000Bitmap; // Sprite con el texto 1.000
SmartSprite *_2500Bitmap; // Sprite con el texto 2.500
SmartSprite *_5000Bitmap; // Sprite con el texto 5.000
Sprite *background; // Sprite con los graficos frontales del fondo
Sprite *gradient; // Sprite con los graficos del degradado de color de fondo
SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 gradientes
Uint16 balloonsPopped; // Lleva la cuenta de los globos explotados
MovingSprite *clouds1a; // Sprite para las nubes superiores
MovingSprite *clouds1b; // Sprite para las nubes superiores
MovingSprite *clouds2a; // Sprite para las nubes inferiores
MovingSprite *clouds2b; // Sprite para las nubes inferiores
Sprite *grass; // Sprite para la hierba
Sprite *scoreBoard; // Sprite para el fondo del marcador
Sprite *powerMeter; // Sprite para el medidor de poder de la fase
Player *player; // El jugador
Balloon *balloon[MAX_BALLOONS]; // Vector con los objetos globo
Bullet *bullet[MAX_BULLETS]; // Vector con los objetos bala
Item *item[MAX_ITEMS]; // Vector con los objetos item
SmartSprite *smartSprite[MAX_SMART_SPRITES]; // Vector para almacenar y gestionar SmartSprites
Uint8 lastEnemyDeploy; // Guarda cual ha sido la última formación desplegada para no repetir;
Uint8 enemyDeployCounter; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero
float enemySpeed; // Velocidad a la que se mueven los enemigos
effect_t effect; // Variable para gestionar los efectos visuales
};
game_t mGame; // Variable con todas las variables usadas durante el juego
struct title_t
{
Uint16 counter; // Temporizador para la pantalla de titulo
Uint16 backgroundCounter; // Temporizador para el fondo de tiles de la pantalla de titulo
Uint8 backgroundMode; // Variable para almacenar el tipo de efecto que hará el fondo de la pantalla de titulo
bool menuVisible; // Indicador para saber si se muestra el menu del titulo o la frase intermitente
Sprite *tile; // Sprite para dibujar el fondo de pantalla del título
SDL_Rect backgroundWindow; // Ventana visible para la textura de fondo del titulo
Uint8 section; // Indicador para el bucle del titulo
Uint8 nextProgSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
Uint8 events[TITLE_TOTAL_EVENTS]; // Vector para coordinar los eventos de la pantalla de titulo
Uint16 instructionsCounter; // Contador para las instrucciones
SmartSprite *coffeeBitmap; // Sprite con la palabra COFFEE para la pantalla de titulo
SmartSprite *crisisBitmap; // Sprite con la palabra CRISIS para la pantalla de titulo
AnimatedSprite *dustBitmapL; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
AnimatedSprite *dustBitmapR; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo
};
title_t mTitle; // Variable con todas las variables de la pantalla de titulo
struct demo_t
{
bool enabled; // Indica si está activo el modo demo
bool recording; // Indica si está activado el modo para grabar la demo
Uint16 counter; // Contador para el modo demo
demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo
demoKeys_t dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
};
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
struct options_t
{
Uint32 fullScreenMode; // Contiene el valor del modo de pantalla completa
Uint32 fullScreenModePrevious;
Uint8 windowSize; // Contiene el valor del tamaño de la ventana
Uint8 windowSizePrevious;
bool displayCoffeeDrops; // Indica si se han de mostar las gotas de cafe
};
options_t mOptions; // Variable con todas las variables de las opciones del programa
struct logo_t
{
Uint16 counter; // Contador
Sprite *sprite; // Sprite con la textura del logo
};
logo_t mLogo; // Variable con las variables para el logo
struct prog_t
{
bool quit; // Indica si hay que salir del programa
input_t keyboard; // Almacena los códigos de teclado correspondientes
input_t keyboardBuffer; // Buffer para teclas pulsadas
std::string executablePath; // Path del ejecutable
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint8 section; // Sección actual del programa;
Uint8 subsection; // Subseccion dentro de la sección;
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
};
prog_t mProg; // Contiene todas las variables globales del programa
struct debug_t
{
bool enabled; // Indica si se va a mostrar la información de debug
Uint8 enemySet; // Escoge el set enemigo a generar
Uint8 gradR, gradG, gradB; // Colores RGB para modificar el color del gradiente de fondo
float hudW, hudH; // Multiplica el tamaño del hud de debug;
};
debug_t mDebug;
struct resourceBinFile_t
{
std::string file; // Ruta al fichero
};
resourceBinFile_t mBinFile[TOTAL_BINFILE]; // Todos los ficheros binarios
struct resourceSound_t
{
std::string file; // Ruta al fichero
JA_Sound sound; // Variable con el sonido
};
resourceSound_t mSound[TOTAL_SOUND]; // Todos los sonidos
struct resourceMusic_t
{
std::string file; // Ruta al fichero
JA_Music music; // Variable con la música
};
resourceMusic_t mMusic[TOTAL_MUSIC]; // Todas las músicas
struct resourceTexture_t
{
std::string file; // Ruta al fichero
LTexture *texture; // Variable con la textura
};
resourceTexture_t mTexture[TOTAL_TEXTURE]; // Todos los gráficos
public:
// Constructor
GameDirector();
GameDirector(std::string path);
// Destructor
~GameDirector();
// Iniciador
void init(bool reset);
// Inicia las variables necesarias para arrancar el programa
void initProg();
// Carga los recursos necesarios para el programa
bool loadMediaProg();
// Libera las variables del programa
void quitProg();
// Inicializa jail_audio
void initJailAudio();
// Arranca SDL y crea la ventana
bool initSDL();
// Inicializa el vector con los valores del seno
void initSin();
// Inicializa las variables que contienen puntos de ruta para mover objetos
void initPaths();
// Inicializa las variables necesarias para la sección 'Logo'
void initLogo();
// Carga los recursos necesarios para la sección 'Logo'
bool loadMediaLogo();
// Libera las variables necesarias para la sección 'Logo'
void quitLogo();
// Inicializa las variables necesarias para la sección 'Intro'
void initIntro();
// Carga los recursos necesarios para la sección 'Intro'
bool loadMediaIntro();
// Libera las variables necesarias para la sección 'Intro'
void quitIntro();
// Inicializa las variables necesarias para la sección 'Title'
void initTitle(Uint8 subsection = TITLE_SECTION_1);
// Carga los recursos necesarios para la sección 'Title'
bool loadMediaTitle();
// Libera las variables necesarias para la sección 'Title'
void quitTitle();
// Inicializa las variables necesarias para la sección 'Game'
void initGame();
// Inicializa las variables especificas de la sección 'Game' para empezar una nueva partida
void resetGame();
// Carga los recursos necesarios para la sección 'Game'
bool loadMediaGame();
// Libera las variables necesarias para la sección 'Game'
void quitGame();
// Crea el indice de ficheros
void setFileList();
// Comprueba que todos los ficheros existen
bool checkFileList();
// Carga el fichero de puntos
bool loadScoreFile();
// Carga el fichero de configuración
bool loadConfigFile();
// Carga el fichero de datos para la demo
bool loadDemoFile();
// Guarda el fichero de puntos
bool saveScoreFile();
// Guarda el fichero de configuración
bool saveConfigFile();
// Guarda el fichero de datos para la demo
bool saveDemoFile();
// Carga un archivo de imagen en una textura
bool loadTextureFromFile(LTexture *texture, std::string path, SDL_Renderer *renderer);
// Carga los recursos necesarios
bool loadMedia(Uint8 section);
// Descrga los recursos necesarios
bool unLoadMedia(Uint8 section);
// Comprueba el valor de la variable 'quit'
bool exit();
// Establece el valor de la variable
void setExecutablePath(std::string path);
// Inicializa las formaciones enemigas
void initEnemyFormations();
// Inicializa los conjuntos de formaciones
void initEnemyPools();
// Inicializa las fases del juego
void initGameStages();
// Crea una formación de enemigos
void deployEnemyFormation();
// Aumenta el poder de la fase
void increaseStageCurrentPower();
// Establece el valor de la variable
void setScore(Uint32 score);
@@ -66,7 +381,10 @@ public:
// Pinta el marcador en pantalla usando un objeto texto
void renderScoreBoard();
// Actualiza el valor de la variable mStage
// Actualiza las variables del jugador
void updatePlayer();
// Actualiza las variables de la fase
void updateStage();
// Actualiza el estado de muerte
@@ -75,26 +393,47 @@ public:
// Renderiza el fade final cuando se acaba la partida
void renderDeathFade();
// Mueve todos los globos activos
void moveBalloons();
// Actualiza los globos
void updateBalloons();
// Pinta en pantalla todos los globos activos
void renderBalloons();
// Devuelve el primer indice no activo del vector de globos
Uint8 getBallonFreeIndex();
Uint8 getBalloonFreeIndex();
// Crea un globo nuevo en el vector de globos
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, Uint16 stoppedtimer, LTexture *texture);
Uint8 createNewBalloon(float x, int y, Uint8 kind, float velx, float speed, Uint16 stoppedcounter, LTexture *texture);
// Crea una PowerBall
void createPowerBall();
// Establece a cero todos los valores del vector de objetos globo
void resetBalloons();
// Establece la velocidad de los globos
void setBalloonSpeed(float speed);
// Incrementa la velocidad de los globos
void incBalloonSpeed();
// Decrementa la velocidad de los globos
void decBalloonSpeed();
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void updateBalloonSpeed();
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
void popBalloon(Uint8 index);
// Explosiona un globo. Lo destruye
void destroyBalloon(Uint8 index);
// Explosiona todos los globos
void popAllBallons();
void popAllBalloons();
// Destruye todos los globos
void destroyAllBalloons();
// Detiene todos los globos
void stopAllBalloons(Uint16 time);
@@ -106,13 +445,13 @@ public:
Uint8 countBalloons();
// Comprueba la colisión entre el jugador y los globos activos
bool checkPlayerBallonCollision();
bool checkPlayerBalloonCollision();
// Comprueba la colisión entre el jugador y los items
void checkPlayerItemCollision();
// Comprueba la colisión entre las balas y los globos
void checkBulletBallonCollision();
void checkBulletBalloonCollision();
// Mueve las balas activas
void moveBullets();
@@ -150,6 +489,15 @@ public:
// Crea un objeto SmartSprite
void createItemScoreSprite(int x, int y, SmartSprite *sprite);
// Crea un objeto de bonus en función del azar
void dropBonus();
// Dibuja el efecto de flash
void renderFlashEffect();
// Actualiza el efecto de agitar la pantalla
void updateShakeEffect();
// Crea un SmartSprite para arrojar el item café al recibir un impacto
void throwCoffee(int x, int y);
@@ -168,20 +516,33 @@ public:
// Establece a cero todos los valores del vector de objetos SmafrtSprite
void resetSmartSprites();
#ifndef UNUSED
// Deshabilita todas las gotas de café
void resetCoffeeDrops();
// Actualiza las gotas de cafe
void updateCoffeeDrops();
// Dibuja las gotas de cafe
void renderCoffeeDrops();
// Devuelve el primer indice libre del vector de CoffeeDrops
Uint8 getCoffeDropFreeIndex();
// Crea un numero de gotas de cafe
void createCoffeDrops(Uint8 num, int x, int y);
#endif
// Acciones a realizar cuando el jugador muere
void killPlayer();
// Obtiene el valor de la variable
Uint8 getSubsection();
// Calcula y establece el valor de amenaza en funcion de los globos activos
void calculateMenaceLevel();
void setMenace();
// Obtiene el valor de la variable
Uint8 getMenaceLevel();
// Obtiene el valor de la variable
bool isPlayFieldDrawOnly();
// Establece el valor de la variable
void setPlayFieldDrawOnly(bool state);
Uint8 getMenace();
// Establece el valor de la variable
void setTimeStopped(bool value);
@@ -190,10 +551,13 @@ public:
bool isTimeStopped();
// Establece el valor de la variable
void setTimeStoppedTimer(Uint16 value);
void setTimeStoppedCounter(Uint16 value);
// Actualiza la variable EnemyDeployCounter
void updateEnemyDeployCounter();
// Actualiza y comprueba el valor de la variable
void updateTimeStoppedTimer();
void updateTimeStoppedCounter();
// Establece el valor de la variable
void setExplosionTime(bool value);
@@ -205,10 +569,13 @@ public:
void setRemainingExplosions(Uint8 value);
// Actualiza y comprueba el valor de la variable
void updateRemainingExplosionsTimer();
void updateRemainingExplosionsCounter();
// Gestiona el nivel de amenaza
void checkMenaceLevel();
void old_updateMenace();
// Gestiona el nivel de amenaza
void updateMenace();
// Actualiza el campo de juego
void updatePlayField();
@@ -232,10 +599,10 @@ public:
void checkMenuInput(Menu *menu);
// Obtiene el valor de la variable
Uint8 getGameStatus();
Uint8 getProgSection();
// Establece el valor de la variable
void setGameStatus(Uint8 status);
void setProgSection(Uint8 section, Uint8 subsection = 0);
// Pinta una transición en pantalla
void renderFade(Uint8 index);
@@ -258,6 +625,9 @@ public:
// Agita la pantalla
void shakeScreen();
// Agita la pantalla
void shakeScreen2();
// Bucle para el logo del juego
void runLogo();
@@ -265,7 +635,7 @@ public:
void runIntro();
// Bucle para el titulo del juego
void runTitle();
void runTitle(Uint8 subsection = TITLE_SECTION_1);
// Bucle para el juego
void runGame();
@@ -279,9 +649,6 @@ public:
// Bucle para la pantalla de game over
void runGameOverScreen();
// Dibuja la informacion de debug en pantalla
void renderDebugInfo();
// Activa el modo Demo
void enableDemoMode();
@@ -291,259 +658,8 @@ public:
// Intercambia el proximo estado del juego despues del titulo
void toogleTitleNextGS();
private:
// La ventana donde dibujamos
SDL_Window *mWindow;
// El renderizador de la ventana
SDL_Renderer *mRenderer;
// Texturas donde dibujar
SDL_Texture *mBackbuffer;
SDL_Texture *mTitleSurface;
SDL_Texture *mInstructionsSurface;
// Manejador para el mando 1
SDL_Joystick *mGameController;
bool mGameControllerFound;
SDL_Haptic *mControllerHaptic;
// Datos del fichero
Uint32 mScoreDataFile[TOTAL_SCORE_DATA];
DemoKeys mDemoDataFile[TOTAL_DEMO_DATA];
// Manejador de eventos
SDL_Event *mEventHandler;
// El jugador
Player *mPlayer;
// Vector con los objetos globo
Balloon *mBalloon[MAX_BALLOONS];
// Vector con los objetos bala
Bullet *mBullet[MAX_BULLETS];
// Vector con los objetos item
Item *mItem[MAX_ITEMS];
// Fondo del juego
Sprite *mGameBackgroundFront;
Sprite *mGameBackgroundSky;
MovingSprite *mGBClouds1;
MovingSprite *mGBClouds1b;
MovingSprite *mGBClouds2;
MovingSprite *mGBClouds2b;
Sprite *mGrass;
// Instrucciones
Sprite *mInstructions;
// Fondo de la pantalla de titulo
Sprite *mTitleTile;
// Ventana visible de la textura de fondo del titulo
SDL_Rect mBackgroundWindow;
// Vector con los valores del seno para 360 grados
double mSen[360];
// Texto
struct text
{
Text *white;
Text *black;
Text *nokia;
};
text mText;
// Variable con lkos menus del juego
struct menu
{
Menu *title; // Menu de la pantalla de título
Menu *pause; // Menú de la pantalla de pausa
Menu *gameOver; // Menú de la pantalla de game over
Menu *options; // Menú de la pantalla de opciones
Menu *active; // Menu activo (de momento para la pantalla del titulo)
};
menu mMenu;
// Notificación GetReady!
SmartSprite *mGetReadyBitmap;
// Dibujos de la intro
SmartSprite *mIntroBitmap[INTRO_TOTAL_BITMAPS];
// Sprites con el titulo del juego para la pantalla de titulo
SmartSprite *mCoffeeBitmap;
SmartSprite *mCrisisBitmap;
AnimatedSprite *mDustSpriteLeft;
AnimatedSprite *mDustSpriteRight;
// Sprites con los puntos de algunos objetos
SmartSprite *m1000Bitmap;
SmartSprite *m2500Bitmap;
SmartSprite *m5000Bitmap;
// Vector para almacenar y gestionar SmartSprites
SmartSprite *mSmartSprite[MAX_SMART_SPRITES];
// Textos de la intro
Text2 *mIntroText[INTRO_TOTAL_TEXTS];
// Vector para coordinar los eventos de la intro
Uint8 mIntroEvents[INTRO_TOTAL_EVENTS];
// Vector para coordinar los eventos de la pantalla de titulo
Uint8 mTitleEvents[TITLE_TOTAL_EVENTS];
// Indicador para el bucle del titulo
Uint8 mTitleStatus;
struct game
{
Uint32 score; // Puntuación actual
Uint32 hiScore; // Puntuación máxima
Uint8 status; // Indicador para el bucle principal
bool paused; // Idica si el juego está en pausa
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
Uint8 stage; // Pantalla actual
Uint8 stageCounter; // Contador para el tiempo visible del texto de Stage
double stagePath[STAGE_COUNTER]; // Vector con los puntos Y por donde pasará la etiqueta
Uint16 deathCounter; // Contador para la animación de muerte del jugador
Uint8 deathIndex; // Indice del vector de smartsprites que contiene el sprite del jugador
};
game mGame;
// Contador de ticks para ajustar la velocidad del juego
Uint32 mTicks;
// Velocidad a la que se repite el bucle de juego
Uint8 mTicksSpeed;
// Nivel de amenaza actual
Uint8 mMenaceLevel;
// Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral,
// se generan más globos. Si el umbral aumenta, aumenta el numero de globos
Uint8 mMenaceLevelThreshold;
// Indica si el bucle de juego avanza o solo pinta
bool mPlayFieldDrawOnly;
// Indica si se va a mostrar la información de debug
bool mDebug;
// Almacena los códigos de teclado correspondientes
Input mKeyboard;
// Buffer para teclas pulsadas
Input mKeyboardBuffer;
// Indica si el tiempo está detenido
bool mTimeStopped;
// Temporizador para llevar la cuenta del tiempo detenido
Uint16 mTimeStoppedTimer;
// Cantidad de explosiones restantes
Uint8 mRemainingExplosions;
// Temporizador para la cantidad de explosiones restantes
Uint16 mRemainingExplosionsTimer;
// Indica si las explosiones estan en marcha
bool mExplosionTime;
// Contador para las instrucciones
Uint16 mInstructionsCounter;
// Temporizador para la pantalla de titulo
Uint16 mTitleTimer;
// Temporizador para el fondo de tiles de la pantalla de titulo
Uint16 mTitleBackgroundTimer;
// Variable para almacenar el tipo de efecto que hará el foindo del titulo
Uint8 mTitleBackgroundMode;
// Indicador para saber si se muestra el menu del titulo o la frase intermitente
bool mTitleMenuVisible;
// Indica si está activo el modo demo
bool mDemo;
// Indica si está activado el modo para grabar la demo
bool mDemoRecording;
// Contador para el modo demo
Uint16 mDemoCounter;
DemoKeys mDemoKeys;
// Indica a que estado pasara el juego cuando acabe el temporizador del titulo
Uint8 mTiteNextGS;
// Contador para el juego
Uint32 mGameCounter;
// Variable para evitar la repetición de teclas en los menus
bool mMenuKeyPressed;
// Variables para el tamaño y modo de la ventana y variables para almacenar el valor si cancelamos en el menu de opciones
Uint32 mFullScreenMode;
Uint32 mFullScreenModePrevious;
Uint8 mWindowSize;
Uint8 mWindowSizePrevious;
// Variables para el logo
struct logo
{
Uint16 counter;
Sprite *sprite;
};
logo mLogo;
// Path del ejecutable
std::string mExecutablePath;
// Recursos
struct resourceBinFile
{
std::string file;
bool loaded;
};
resourceBinFile mBinFile[TOTAL_BINFILE];
struct resourceSound
{
std::string file;
bool loaded;
JA_Sound sound;
};
resourceSound mSound[TOTAL_SOUND];
struct resourceMusic
{
std::string file;
bool loaded;
JA_Music music;
};
resourceMusic mMusic[TOTAL_MUSIC];
struct resourceTexture
{
std::string file;
bool loaded;
LTexture *texture;
};
resourceTexture mTexture[TOTAL_TEXTURE];
// Dibuja la informacion de debug en pantalla
void renderDebugInfo();
};
#endif

View File

@@ -11,5 +11,11 @@
#endif
#ifdef __linux__
#include "/usr/include/SDL2/SDL.h"
#endif
#ifdef __MIPSEL__
#include "SDL.h"
#else
#include <SDL2/SDL.h>
#endif
#endif
#define UNUSED

View File

@@ -251,7 +251,7 @@ void Item::setEnabled(bool value)
}
// Obtiene el circulo de colisión
Circle &Item::getCollider()
circle_t &Item::getCollider()
{
return mCollider;
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include "ifdefs.h"
#include "animatedsprite.h"
#include "struct.h"
#include "utils.h"
#ifndef ITEM_H
#define ITEM_H
@@ -62,7 +62,7 @@ public:
void setEnabled(bool value);
// Obtiene el circulo de colisión
Circle &getCollider();
circle_t &getCollider();
// Temporizador con el tiempo que el objeto está presente
Uint16 mTimeToLive;
@@ -93,10 +93,8 @@ private:
// Especifica si está habilitado el objeto
bool mEnabled;
// Circulo de colisión del objeto
Circle mCollider;
circle_t mCollider;
// Alinea el circulo de colisión con la posición del objeto
void shiftColliders();

View File

@@ -1,6 +1,6 @@
#ifndef __MIPSEL__
#include "jail_audio.h"
#include "stb_vorbis.c"
//#include <SDL2/SDL.h>
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
@@ -210,4 +210,4 @@ JA_Channel_state JA_GetChannelState(const int channel) {
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
return channels[channel].state;
}
#endif

View File

@@ -0,0 +1,106 @@
#ifdef __MIPSEL__
#include "jail_audio.h"
#include "SDL_mixer.h"
struct JA_Sound_t {
Mix_Chunk *mix_chunk;
};
struct JA_Music_t {
Mix_Music* mix_music;
};
JA_Music current_music{NULL};
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
Mix_AllocateChannels(8);
}
JA_Music JA_LoadMusic(const char* filename) {
int chan, samplerate;
JA_Music music = new JA_Music_t();
music->mix_music = Mix_LoadMUS(filename);
return music;
}
void JA_PlayMusic(JA_Music music, const int loop) {
if (current_music == music) return;
if (current_music != NULL) {
Mix_HaltMusic();
}
current_music = music;
Mix_PlayMusic(music->mix_music, loop);
}
void JA_PauseMusic() {
Mix_PauseMusic();
}
void JA_ResumeMusic() {
Mix_ResumeMusic();
}
void JA_StopMusic() {
Mix_HaltMusic();
}
JA_Music_state JA_GetMusicState() {
if (current_music == NULL) return JA_MUSIC_INVALID;
if (Mix_PausedMusic()) {
return JA_MUSIC_PAUSED;
} else if (Mix_PlayingMusic()) {
return JA_MUSIC_PLAYING;
} else {
return JA_MUSIC_STOPPED;
}
}
void JA_DeleteMusic(JA_Music music) {
if (current_music == music) {
Mix_HaltMusic();
current_music = NULL;
}
Mix_FreeMusic(music->mix_music);
delete music;
}
JA_Sound JA_LoadSound(const char* filename) {
JA_Sound sound = new JA_Sound_t();
sound->mix_chunk = Mix_LoadWAV(filename);
return sound;
}
int JA_PlaySound(JA_Sound sound, const int loop) {
int channel = Mix_PlayChannel(-1, sound->mix_chunk, loop);
return channel;
}
void JA_DeleteSound(JA_Sound sound) {
Mix_FreeChunk(sound->mix_chunk);
delete sound;
}
void JA_PauseChannel(const int channel) {
Mix_Pause(channel);
}
void JA_ResumeChannel(const int channel) {
Mix_Resume(channel);
}
void JA_StopChannel(const int channel) {
Mix_HaltChannel(channel);
}
JA_Channel_state JA_GetChannelState(const int channel) {
if (Mix_Paused(channel)) {
return JA_CHANNEL_PAUSED;
} else if (Mix_Playing(channel)) {
return JA_CHANNEL_PLAYING;
} else {
return JA_CHANNEL_FREE;
}
}
#endif

View File

@@ -16,7 +16,7 @@ LTexture::LTexture()
LTexture::~LTexture()
{
// Deallocate
free();
unload();
}
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
@@ -46,14 +46,14 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
}
// Get rid of preexisting texture
free();
unload();
// The final texture
SDL_Texture *newTexture = NULL;
// Load image at specified path
//SDL_Surface *loadedSurface = IMG_Load(path.c_str());
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void*)data, width, height, depth, pitch, pixel_format);
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
if (loadedSurface == NULL)
{
printf("Unable to load image %s!\n", path.c_str());
@@ -61,7 +61,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
else
{
// Color key image
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
//SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
// Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
@@ -102,7 +102,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
return mTexture != NULL;
}
void LTexture::free()
void LTexture::unload()
{
// Free texture if it exists
if (mTexture != NULL)
@@ -132,7 +132,7 @@ void LTexture::setAlpha(Uint8 alpha)
SDL_SetTextureAlphaMod(mTexture, alpha);
}
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, double angle, SDL_Point *center, SDL_RendererFlip flip)
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
{
// Set rendering space and render to screen
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
@@ -144,6 +144,9 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, doub
renderQuad.h = clip->h;
}
renderQuad.w = renderQuad.w * zoomW;
renderQuad.h = renderQuad.h * zoomH;
// Render to screen
SDL_RenderCopyEx(renderer, mTexture, clip, &renderQuad, angle, center, flip);
}

View File

@@ -23,7 +23,7 @@ public:
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
// Deallocates texture
void free();
void unload();
// Set color modulation
void setColor(Uint8 red, Uint8 green, Uint8 blue);
@@ -35,7 +35,7 @@ public:
void setAlpha(Uint8 alpha);
// Renders texture at given point
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = NULL, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = NULL, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE);
// Set self as render target
void setAsRenderTarget(SDL_Renderer *renderer);

View File

@@ -1,10 +1,10 @@
/*
This source code copyrighted by JailDesigner (2020)
started on Castalla 15-07-2020.
Using some sample source code from Lazy Foo' Productions
*/
/*Descripción del enfoque utilizado para crear el juego.
/*
Descripción del enfoque utilizado para crear el juego.
El programa contine una serie de clases/objetos básicos: la clase sprite
permite dibujar partes de un fichero png en pantalla. La clase AnimatedSprite
@@ -37,11 +37,11 @@ un tipo asociado diferente a NO_KIND
*/
#include "ifdefs.h"
#include "const.h"
#include "gamedirector.h"
#include <time.h>
#include <stdio.h>
#include <string>
#include "const.h"
#include "gamedirector.h"
int main(int argc, char *args[])
{
@@ -49,82 +49,33 @@ int main(int argc, char *args[])
srand(time(nullptr));
// Crea el objeto gameDirector
GameDirector *gameDirector = new GameDirector();
GameDirector *gameDirector = new GameDirector(args[0]);
printf("Starting the game...\n\n");
// Establece el valor de la variable con el path del ejecutable
gameDirector->setExecutablePath(args[0]);
// Inicializa la lista de ficheros
gameDirector->setFileList();
// Comprueba que existen todos los ficheros
if (!gameDirector->checkFileList())
// Mientras no se quiera salir del juego
while (!(gameDirector->exit()))
{
return -1;
}
// Arranca SDL y crea la ventana
if (!gameDirector->initSDL())
{
printf("Failed to initialize!\n");
return -1;
}
else
{
// Carga los recursos
if (!gameDirector->loadMedia(GAME_STATE_INIT))
switch (gameDirector->getProgSection())
{
printf("Failed to load media!\n");
case PROG_SECTION_LOGO:
gameDirector->runLogo();
break;
case PROG_SECTION_INTRO:
gameDirector->runIntro();
break;
case PROG_SECTION_TITLE:
gameDirector->runTitle(gameDirector->getSubsection());
break;
case PROG_SECTION_GAME:
gameDirector->runGame();
break;
}
else
{
// Inicializa el objeto gameDirector
gameDirector->init(false);
printf("Starting the game...\n\n");
// Mientras no se quiera salir del juego
while (!(gameDirector->getGameStatus() == GAME_STATE_QUIT))
{
switch (gameDirector->getGameStatus())
{
case GAME_STATE_LOGO:
gameDirector->loadMedia(GAME_STATE_LOGO);
gameDirector->runLogo();
gameDirector->unLoadMedia(GAME_STATE_LOGO);
break;
case GAME_STATE_INTRO:
gameDirector->loadMedia(GAME_STATE_INTRO);
gameDirector->runIntro();
gameDirector->unLoadMedia(GAME_STATE_INTRO);
break;
case GAME_STATE_TITLE:
gameDirector->loadMedia(GAME_STATE_TITLE);
gameDirector->runTitle();
gameDirector->unLoadMedia(GAME_STATE_TITLE);
break;
case GAME_STATE_PLAYING:
gameDirector->loadMedia(GAME_STATE_PLAYING);
gameDirector->runGame();
gameDirector->unLoadMedia(GAME_STATE_PLAYING);
break;
case GAME_STATE_GAME_OVER_SCREEN:
gameDirector->loadMedia(GAME_STATE_GAME_OVER_SCREEN);
gameDirector->runGameOverScreen();
gameDirector->unLoadMedia(GAME_STATE_GAME_OVER_SCREEN);
break;
case GAME_STATE_INSTRUCTIONS:
gameDirector->loadMedia(GAME_STATE_INSTRUCTIONS);
gameDirector->runInstructions();
gameDirector->unLoadMedia(GAME_STATE_INSTRUCTIONS);
break;
}
}
}
// Libera todos los recursos y cierra SDL
delete gameDirector;
printf("Shutting down the game...\n");
return 0;
}
// Libera todos los recursos y cierra SDL
delete gameDirector;
gameDirector = nullptr;
printf("Shutting down the game...\n");
return 0;
}

View File

@@ -33,6 +33,10 @@ void MovingSprite::init(float x, float y, int w, int h, float velx, float vely,
setAccelX(accelx);
setAccelY(accely);
// Establece el zoom W,H del sprite
setZoomW(1);
setZoomH(1);
// Establece la textura donde están los gráficos para el sprite
setTexture(texture);
@@ -56,7 +60,8 @@ void MovingSprite::move()
// Muestra el sprite por pantalla
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);
}
// Establece el valor de la variable
@@ -95,6 +100,18 @@ float MovingSprite::getAccelY()
return mAccelY;
}
// Establece el valor de la variable
float MovingSprite::getZoomW()
{
return mZoomW;
}
// Establece el valor de la variable
float MovingSprite::getZoomH()
{
return mZoomH;
}
// Establece el valor de la variable
void MovingSprite::setPosX(float x)
{
@@ -129,4 +146,16 @@ void MovingSprite::setAccelX(float x)
void MovingSprite::setAccelY(float y)
{
mAccelY = y;
}
// Establece el valor de la variable
void MovingSprite::setZoomW(float w)
{
mZoomW = w;
}
// Establece el valor de la variable
void MovingSprite::setZoomH(float h)
{
mZoomH = h;
}

View File

@@ -8,6 +8,19 @@
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
class MovingSprite : public Sprite
{
private:
float mPosX; // Posición en el eje X
float mPosY; // Posición en el eje Y
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 mAccelX; // Aceleración en el eje X. Variación de la velocidad
float mAccelY; // Aceleración en el eje Y. Variación de la velocidad
float mZoomW; // Zoom aplicado a la anchura
float mZoomH; // Zoom aplicado a la altura
public:
// Constructor
MovingSprite();
@@ -26,52 +39,51 @@ public:
// Obten el valor de la variable
float getPosX();
// Obten el valor de la variable
float getPosY();
// Obten el valor de la variable
float getVelX();
// Obten el valor de la variable
float getVelY();
// Obten el valor de la variable
float getAccelX();
// Obten el valor de la variable
float getAccelY();
// Obten el valor de la variable
float getZoomW();
// Obten el valor de la variable
float getZoomH();
// Establece el valor de la variable
void setPosX(float x);
// Establece el valor de la variable
void setPosY(float y);
// Establece el valor de la variable
void setVelX(float x);
// Establece el valor de la variable
void setVelY(float y);
// Establece el valor de la variable
void setAccelX(float x);
// Establece el valor de la variable
void setAccelY(float y);
private:
// Posición
float mPosX;
float mPosY;
// Establece el valor de la variable
void setZoomW(float w);
// Velocidad
float mVelX;
float mVelY;
// Aceleración
float mAccelX;
float mAccelY;
// Establece el valor de la variable
void setZoomH(float h);
};
#endif

View File

@@ -6,6 +6,7 @@ Player::Player()
{
mSpriteLegs = new AnimatedSprite();
mSpriteBody = new AnimatedSprite();
mSpriteHead = new AnimatedSprite();
init(0, 0, nullptr, nullptr, nullptr);
}
@@ -17,6 +18,7 @@ Player::~Player()
mSpriteBody = nullptr;
delete mSpriteLegs;
delete mSpriteBody;
delete mSpriteHead;
}
// Iniciador
@@ -27,8 +29,10 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mStatusWalking = PLAYER_STATUS_WALKING_STOP;
mStatusFiring = PLAYER_STATUS_FIRING_NO;
mInvulnerable = false;
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
mExtraHit = false;
mCoffees = 0;
mInput = true;
// Establece la altura y el ancho del jugador
mWidth = 3 * BLOCK;
@@ -51,10 +55,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
// Establece la velocidad base
mBaseSpeed = 1.5;
// Establece el numero inicial de vidas
mStartingLives = 3;
mLives = mStartingLives;
// Establece la puntuación inicial
mScore = 0;
@@ -100,12 +100,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 4);
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 4);
// Establece la velocidad de cada animación
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
@@ -118,12 +112,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 5);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 10);
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 5);
// Establece si la animación se reproduce en bucle
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
@@ -136,12 +124,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, true);
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, true);
// Establece los frames de cada animación
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
@@ -189,36 +171,6 @@ void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody,
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 6, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 7, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 8, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 9, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 0, mWidth * 0, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 1, mWidth * 1, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 2, mWidth * 2, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 3, mWidth * 3, mHeight * 10, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 0, mWidth * 0, mHeight * 11, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 1, mWidth * 1, mHeight * 11, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 2, mWidth * 2, mHeight * 11, mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 3, mWidth * 3, mHeight * 11, mWidth, mHeight);
// Selecciona un frame para pintar
mSpriteLegs->setSpriteClip(mSpriteLegs->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0));
mSpriteBody->setSpriteClip(mSpriteBody->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0));
@@ -231,71 +183,29 @@ void Player::setInput(Uint8 input)
{
case INPUT_LEFT:
mVelX = -mBaseSpeed;
if (mExtraHit)
{
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
}
else
{
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
}
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
break;
case INPUT_RIGHT:
mVelX = mBaseSpeed;
if (mExtraHit)
{
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
}
else
{
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
}
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
break;
case INPUT_FIRE_UP:
if (mExtraHit)
{
setFiringStatus(PLAYER_STATUS_FIRING_UP);
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_UP);
}
setFiringStatus(PLAYER_STATUS_FIRING_UP);
break;
case INPUT_FIRE_LEFT:
if (mExtraHit)
{
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
}
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
break;
case INPUT_FIRE_RIGHT:
if (mExtraHit)
{
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
}
else
{
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
}
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
break;
default:
mVelX = 0;
if (mExtraHit)
{
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
}
else
{
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
}
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
break;
}
}
@@ -309,7 +219,7 @@ void Player::move()
mPosX += mVelX;
// Si el jugador abandona el area de juego por los laterales
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5))
{
// Restaura su posición
mPosX -= mVelX;
@@ -331,7 +241,7 @@ void Player::render()
{
if (mInvulnerable)
{
if ((mInvulnerableTimer % 10) > 4)
if ((mInvulnerableCounter % 10) > 4)
{
mSpriteLegs->render();
mSpriteBody->render();
@@ -370,6 +280,17 @@ void Player::setFiringStatus(Uint8 status)
// Establece la animación correspondiente al estado
void Player::setAnimation()
{
// Actualiza los frames de la animación en función del número de cafes
for (Uint8 i = 0; i < 4; i++)
{
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, i, mWidth * i, mHeight * (0 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, i, mWidth * i, mHeight * (1 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, i, mWidth * i, mHeight * (2 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, i, mWidth * i, mHeight * (3 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, i, mWidth * i, mHeight * (4 + (6 * mCoffees)), mWidth, mHeight);
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, i, mWidth * i, mHeight * (5 + (6 * mCoffees)), mWidth, mHeight);
}
switch (mStatusWalking)
{
case PLAYER_STATUS_WALKING_LEFT:
@@ -377,51 +298,19 @@ void Player::setAnimation()
switch (mStatusFiring)
{
case PLAYER_STATUS_FIRING_UP:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
break;
case PLAYER_STATUS_FIRING_LEFT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
break;
case PLAYER_STATUS_FIRING_RIGHT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
break;
case PLAYER_STATUS_FIRING_NO:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
break;
default:
@@ -435,51 +324,19 @@ void Player::setAnimation()
switch (mStatusFiring)
{
case PLAYER_STATUS_FIRING_UP:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
break;
case PLAYER_STATUS_FIRING_LEFT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
break;
case PLAYER_STATUS_FIRING_RIGHT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
break;
case PLAYER_STATUS_FIRING_NO:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
break;
default:
@@ -493,51 +350,19 @@ void Player::setAnimation()
switch (mStatusFiring)
{
case PLAYER_STATUS_FIRING_UP:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
break;
case PLAYER_STATUS_FIRING_LEFT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
break;
case PLAYER_STATUS_FIRING_RIGHT:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
break;
case PLAYER_STATUS_FIRING_NO:
if (mExtraHit)
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT);
}
else
{
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
}
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
break;
default:
@@ -616,7 +441,7 @@ void Player::update()
setAnimation();
shiftColliders();
updateCooldown();
updateInvulnerableTimer();
updateInvulnerableCounter();
}
// Obtiene la puntuación del jugador
@@ -692,28 +517,28 @@ void Player::setInvulnerable(bool value)
}
// Obtiene el valor de la variable
bool Player::getInvulnerableTimer()
Uint16 Player::getInvulnerableCounter()
{
return mInvulnerableTimer;
return mInvulnerableCounter;
}
// Establece el valor de la variable
void Player::setInvulnerableTimer(Uint16 value)
void Player::setInvulnerableCounter(Uint16 value)
{
mInvulnerableTimer = value;
mInvulnerableCounter = value;
}
// Actualiza el valor de la variable
void Player::updateInvulnerableTimer()
void Player::updateInvulnerableCounter()
{
if (mInvulnerableTimer > 0)
if (mInvulnerableCounter > 0)
{
--mInvulnerableTimer;
--mInvulnerableCounter;
}
else
{
mInvulnerable = false;
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
}
}
@@ -727,18 +552,42 @@ bool Player::hasExtraHit()
void Player::giveExtraHit()
{
mExtraHit = true;
mCoffees++;
if (mCoffees > 2)
mCoffees = 2;
}
// Quita el toque extra al jugador
void Player::removeExtraHit()
{
mExtraHit = false;
if (mCoffees > 0)
mCoffees--;
if (mCoffees == 0)
mExtraHit = false;
mInvulnerable = true;
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
}
// Habilita la entrada de ordenes
void Player::enableInput()
{
mInput = true;
}
// Deshabilita la entrada de ordenes
void Player::disableInput()
{
mInput = false;
}
// Devuelve el numero de cafes actuales
Uint8 Player::getCoffees()
{
return mCoffees;
}
// Obtiene el circulo de colisión
Circle &Player::getCollider()
circle_t &Player::getCollider()
{
return mCollider;
}

View File

@@ -1,5 +1,5 @@
#pragma once
#include "struct.h"
#include "utils.h"
#include "animatedsprite.h"
#ifndef PLAYER_H
@@ -8,6 +8,39 @@
// The player
class Player
{
private:
float mPosX; // Posicion en el eje X
int mPosY; // Posicion en el eje Y
Uint8 mWidth; // Anchura
Uint8 mHeight; // Altura
float mVelX; // Cantidad de pixeles a desplazarse en el eje X
int mVelY; // Cantidad de pixeles a desplazarse en el eje Y
float mBaseSpeed; // Velocidad base del jugador
int mCooldown; // Contador durante el cual no puede disparar
Uint32 mScore; // Puntos del jugador
float mScoreMultiplier; // Multiplicador de puntos
Uint8 mStatusWalking; // Estado del jugador
Uint8 mStatusFiring; // Estado del jugador
bool mAlive; // Indica si el jugador está vivo
bool mInvulnerable; // Indica si el jugador es invulnerable
Uint16 mInvulnerableCounter; // Temporizador para la invulnerabilidad
bool mExtraHit; // Indica si el jugador tiene un toque extra
Uint8 mCoffees; // Indica cuantos cafes lleva acumulados
bool mInput; // Indica si puede recibir ordenes de entrada
AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas
AnimatedSprite *mSpriteBody; // Sprite para dibujar el cuerpo
AnimatedSprite *mSpriteHead; // Sprite para dibujar la cabeza
circle_t mCollider; // Circulo de colisión del jugador
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
public:
// Constructor
Player();
@@ -92,13 +125,13 @@ public:
void setInvulnerable(bool value);
// Obtiene el valor de la variable
bool getInvulnerableTimer();
Uint16 getInvulnerableCounter();
// Establece el valor de la variable
void setInvulnerableTimer(Uint16 value);
void setInvulnerableCounter(Uint16 value);
// Actualiza el valor de la variable
void updateInvulnerableTimer();
void updateInvulnerableCounter();
// Obtiene el valor de la variable
bool hasExtraHit();
@@ -109,65 +142,17 @@ public:
// Quita el toque extra al jugador
void removeExtraHit();
// Habilita la entrada de ordenes
void enableInput();
// Deshabilita la entrada de ordenes
void disableInput();
// Devuelve el numero de cafes actuales
Uint8 getCoffees();
// Obtiene el circulo de colisión
Circle &getCollider();
private:
// Posición X, Y del jugador
float mPosX;
int mPosY;
// Altura y anchura del jugador
Uint8 mWidth;
Uint8 mHeight;
// Velocidad X, Y del jugador
float mVelX;
int mVelY;
// Velocidad base del jugador
float mBaseSpeed;
// Contador durante el cual no puede disparar
int mCooldown;
// Vidas actuales del jugador
Uint8 mLives;
// Vidas iniciales del jugador
Uint8 mStartingLives;
// Puntos del jugador
Uint32 mScore;
// Multiplicador de puntos
float mScoreMultiplier;
// Estado del jugador
Uint8 mStatusWalking;
Uint8 mStatusFiring;
// Indica si el jugador está vivo
bool mAlive;
// Indica si el jugador es invulnerable
bool mInvulnerable;
// Temporizador para la invulnerabilidad
Uint16 mInvulnerableTimer;
// Indica si el jugador tiene un toque extra
bool mExtraHit;
// Sprite para dibujar al jugador en pantalla
AnimatedSprite *mSpriteLegs;
AnimatedSprite *mSpriteBody;
// Circulo de colisión del jugador
Circle mCollider;
// Actualiza el circulo de colisión a la posición del jugador
void shiftColliders();
circle_t &getCollider();
};
#endif

View File

@@ -1,5 +1,5 @@
#pragma once
#include "struct.h"
#include "utils.h"
#include "animatedsprite.h"
#ifndef SMARTSPRITE_H

View File

@@ -16,14 +16,14 @@ Sprite::~Sprite()
// Inicializador
void Sprite::init(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
{
// Establece el alto y el ancho del sprite
setWidth(w);
setHeight(h);
// Establece la posición X,Y del sprite
setPosX(x);
setPosY(y);
// Establece el alto y el ancho del sprite
setWidth(w);
setHeight(h);
// Establece el puntero al renderizador de la ventana
setRenderer(renderer);

View File

@@ -31,7 +31,6 @@ void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 siz
mSprite->setSpriteClip(0, 0, mSprite->getWidth(), mSprite->getHeight());
// Cadena con los caracteres ascii que se van a inicializar
// std::string text = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-/().:#!";
std::string text = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ{\\[]]^_`abcdefghijklmnopqrstuvwxyz";
// Inicializa a cero el vector con las coordenadas
@@ -192,6 +191,15 @@ void Text::writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8
mSprite->getTexture()->setColor(255, 255, 255);
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B)
{
mSprite->getTexture()->setColor(R, G, B);
write(x+1, y+1, text);
mSprite->getTexture()->setColor(255, 255, 255);
write(x, y, text);
}
// Escribe el texto centrado en un punto x y con kerning
void Text::writeCentered(int x, int y, std::string text, int kerning)
{

View File

@@ -7,6 +7,20 @@
// Clase texto. Pinta texto en pantalla a partir de un bitmap
class Text
{
private:
Sprite *mSprite;// Objeto con los graficos para el texto
struct Offset
{
int x;
int y;
Uint8 w;
};
Offset mOffset[255];// Vector con las posiciones y ancho de cada letra
Uint8 mType;// Indica si el texto es de anchura fija o variable
Uint8 mSize;// Altura del texto
public:
// Constructor
Text();
@@ -25,8 +39,11 @@ public:
// Escribe el texto con colores
void writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B);
// Escribe el texto con sombra
void writeShadowed(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B);
// Escribe el texto centrado en un punto x y con kerning
void writeCentered(int x, int y, std::string text, int kerning);
void writeCentered(int x, int y, std::string text, int kerning = 0);
// Obtiene la longitud en pixels de una cadena
Uint16 lenght(std::string text, int kerning);
@@ -42,25 +59,6 @@ public:
// Establece el valor de la variable
void setSize(Uint8 size);
private:
// Objeto con los graficos para el texto
Sprite *mSprite;
// Coordenadas dentro del PNG para cada código ascii y su anchura
struct Offset
{
int x;
int y;
Uint8 w;
};
// Vector con las posiciones y ancho de cada letra
Offset mOffset[255];
// Indica si el texto es de anchura fija o variable
Uint8 mType;
Uint8 mSize;
};
#endif

112
source/utils.cpp Normal file
View File

@@ -0,0 +1,112 @@
#include "utils.h"
// Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2)
{
int deltaX = x2 - x1;
int deltaY = y2 - y1;
return deltaX * deltaX + deltaY * deltaY;
}
// Detector de colisiones entre dos circulos
bool checkCollision(circle_t &a, circle_t &b)
{
// Calcula el radio total al cuadrado
int totalRadiusSquared = a.r + b.r;
totalRadiusSquared = totalRadiusSquared * totalRadiusSquared;
// Si la distancia entre el centro de los circulos es inferior a la suma de sus radios
if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared))
{
// Los circulos han colisionado
return true;
}
// En caso contrario
return false;
}
// Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(circle_t &a, SDL_Rect &b)
{
//Closest point on collision box
int cX, cY;
//Find closest x offset
if (a.x < b.x)
{
cX = b.x;
}
else if (a.x > b.x + b.w)
{
cX = b.x + b.w;
}
else
{
cX = a.x;
}
//Find closest y offset
if (a.y < b.y)
{
cY = b.y;
}
else if (a.y > b.y + b.h)
{
cY = b.y + b.h;
}
else
{
cY = a.y;
}
//If the closest point is inside the circle_t
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
{
//This box and the circle_t have collided
return true;
}
//If the shapes have not collided
return false;
}
// Detector de colisiones entre un dos rectangulos
bool checkCollision(SDL_Rect &a, SDL_Rect &b)
{
//Calculate the sides of rect A
int leftA = a.x;
int rightA = a.x + a.w;
int topA = a.y;
int bottomA = a.y + a.h;
//Calculate the sides of rect B
int leftB = b.x;
int rightB = b.x + b.w;
int topB = b.y;
int bottomB = b.y + b.h;
//If any of the sides from A are outside of B
if (bottomA <= topB)
{
return false;
}
if (topA >= bottomB)
{
return false;
}
if (rightA <= leftB)
{
return false;
}
if (leftA >= rightB)
{
return false;
}
//If none of the sides from A are outside B
return true;
}

View File

@@ -1,42 +1,54 @@
#pragma once
#include "ifdefs.h"
#ifndef STRUCT_H
#define STRUCT_H
// Estructura para definir un circulo
struct Circle
{
Uint16 x;
Uint16 y;
Uint8 r;
};
// Estructura para definir todas las entradas que aceptará el programa
struct Input
{
Uint8 up;
Uint8 down;
Uint8 left;
Uint8 right;
Uint8 escape;
Uint8 pause;
Uint8 fire;
Uint8 fireLeft;
Uint8 fireRight;
Uint8 accept;
Uint8 cancel;
};
// Estructura para mapear el teclado usado en la demo
struct DemoKeys
{
Uint8 left;
Uint8 right;
Uint8 noInput;
Uint8 fire;
Uint8 fireLeft;
Uint8 fireRight;
};
#endif
#pragma once
#include "ifdefs.h"
#ifndef UTILS_H
#define UTILS_H
// Estructura para definir un circulo
struct circle_t
{
Uint16 x;
Uint16 y;
Uint8 r;
};
// Estructura para definir todas las entradas que aceptará el programa
struct input_t
{
Uint8 up;
Uint8 down;
Uint8 left;
Uint8 right;
Uint8 escape;
Uint8 pause;
Uint8 fire;
Uint8 fireLeft;
Uint8 fireRight;
Uint8 accept;
Uint8 cancel;
};
// Estructura para mapear el teclado usado en la demo
struct demoKeys_t
{
Uint8 left;
Uint8 right;
Uint8 noInput;
Uint8 fire;
Uint8 fireLeft;
Uint8 fireRight;
};
// Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2);
// Detector de colisiones entre dos circulos
bool checkCollision(circle_t &a, circle_t &b);
// Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(circle_t &a, SDL_Rect &b);
// Detector de colisiones entre un dos rectangulos
bool checkCollision(SDL_Rect a, SDL_Rect b);
#endif

View File

@@ -26,11 +26,11 @@ fi
# UPLOAD
if [ "$1" = upload ] || [ "$1" = UPLOAD ]; then
printf "\n%s\n" "uploading $PROJECT"
rsync -azmPu --delete -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/
rsync -azmPu -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT.all/
rsync -avzmPu --delete -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/
rsync -avzmPu -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT.all/
fi
if [ "$1" = download ] || [ "$1" = DOWNLOAD ]; then
printf "%s\n" "downloading $PROJECT"
rsync -azmP --delete -e 'ssh -p 4545' sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/* .
rsync -avzmP --delete -e 'ssh -p 4545' sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/* .
fi