code reorganized
This commit is contained in:
19
.vscode/c_cpp_properties.json
vendored
Normal file
19
.vscode/c_cpp_properties.json
vendored
Normal 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
21
.vscode/launch.json
vendored
Normal 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
19
.vscode/settings.json
vendored
Normal 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
31
.vscode/tasks.json
vendored
Normal 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++"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
media/.DS_Store
vendored
BIN
media/.DS_Store
vendored
Binary file not shown.
BIN
media/gfx/font_black_x2.png
Normal file
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
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: 10 KiB |
@@ -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.
@@ -5,7 +5,7 @@
|
||||
Balloon::Balloon()
|
||||
{
|
||||
mSprite = new AnimatedSprite();
|
||||
init(0, 0, NO_KIND, BALLON_VELX_POSITIVE, 0, nullptr, nullptr);
|
||||
init(0, 0, NO_KIND, BALLOON_VELX_POSITIVE, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -227,13 +227,21 @@ void Balloon::init(float x, int y, Uint8 kind, float velx, Uint16 creationtimer,
|
||||
|
||||
// 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;
|
||||
|
||||
// Tipo
|
||||
mKind = kind;
|
||||
@@ -288,7 +296,24 @@ void Balloon::render()
|
||||
{
|
||||
if (mVisible)
|
||||
{
|
||||
mSprite->render();
|
||||
if (mBouncing.enabled)
|
||||
{
|
||||
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())
|
||||
{
|
||||
mSprite->getTexture()->setAlpha(255 - (int)((float)mCreationCounter * (255.0f/(float)mCreationCounterIni)));
|
||||
mSprite->render();
|
||||
mSprite->getTexture()->setAlpha(255);
|
||||
}
|
||||
else
|
||||
{
|
||||
mSprite->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,10 +353,13 @@ void Balloon::move()
|
||||
if (mPosY + mHeight > PLAY_AREA_BOTTOM)
|
||||
{
|
||||
// Corregimos
|
||||
mPosY -= int(mVelY);
|
||||
//mPosY -= int(mVelY);
|
||||
mPosY = PLAY_AREA_BOTTOM - mHeight;
|
||||
|
||||
// Invertimos colocando una velocidad por defecto
|
||||
mVelY = -mDefaultVelY;
|
||||
|
||||
bounceStart();
|
||||
}
|
||||
|
||||
// Aplica gravedad al objeto, sin pasarse de un limite establecido
|
||||
@@ -357,10 +385,10 @@ void Balloon::move()
|
||||
setInvulnerable(true);
|
||||
|
||||
// Todavia tiene tiempo en el contador
|
||||
if (mCreationTimer > 0)
|
||||
if (mCreationCounter > 0)
|
||||
{
|
||||
// Desplaza lentamente el globo hacia abajo y hacia un lado
|
||||
if (mCreationTimer % 10 == 0)
|
||||
if (mCreationCounter % 10 == 0)
|
||||
{
|
||||
++mPosY;
|
||||
mPosX += mVelX;
|
||||
@@ -374,16 +402,16 @@ void Balloon::move()
|
||||
}
|
||||
|
||||
// Hace visible el globo de forma intermitente
|
||||
if (mCreationTimer > 100)
|
||||
if (mCreationCounter > 100)
|
||||
{
|
||||
setVisible(mCreationTimer / 10 % 2 == 0);
|
||||
setVisible(mCreationCounter / 10 % 2 == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
setVisible(mCreationTimer / 5 % 2 == 0);
|
||||
setVisible(mCreationCounter / 5 % 2 == 0);
|
||||
}
|
||||
|
||||
--mCreationTimer;
|
||||
--mCreationCounter;
|
||||
}
|
||||
// El contador ha llegado a cero
|
||||
else
|
||||
@@ -398,9 +426,9 @@ void Balloon::move()
|
||||
else if (isStopped() == true)
|
||||
{
|
||||
// Si todavía está detenido, reduce el contador
|
||||
if (mStoppedTimer > 0)
|
||||
if (mStoppedCounter > 0)
|
||||
{
|
||||
--mStoppedTimer;
|
||||
--mStoppedCounter;
|
||||
} // Si el contador ha llegado a cero, ya no está detenido
|
||||
else
|
||||
{
|
||||
@@ -433,6 +461,7 @@ void Balloon::update()
|
||||
move();
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
bounceUpdate();
|
||||
if (isPopping())
|
||||
{
|
||||
setInvulnerable(true);
|
||||
@@ -608,13 +637,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
|
||||
@@ -641,4 +670,41 @@ void Balloon::shiftColliders()
|
||||
Uint8 Balloon::getMenace()
|
||||
{
|
||||
return mMenace;
|
||||
}
|
||||
|
||||
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;
|
||||
mBouncing.zoomH = 1;
|
||||
mSprite->setZoomW(mBouncing.zoomW);
|
||||
mSprite->setZoomH(mBouncing.zoomH);
|
||||
mBouncing.despX = 0;
|
||||
mBouncing.despY = 0;
|
||||
}
|
||||
void Balloon::bounceUpdate()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
118
source/balloon.h
118
source/balloon.h
@@ -1,13 +1,66 @@
|
||||
#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
|
||||
int 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
|
||||
int 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 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 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
|
||||
|
||||
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 shiftColliders(); // Alinea el circulo de colisión con la posición del objeto globo
|
||||
void bounceStart(); // Activa el efecto
|
||||
void bounceStop(); // Detiene el efecto
|
||||
void bounceUpdate(); // Aplica el efecto
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Balloon();
|
||||
@@ -16,7 +69,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, int y, Uint8 kind, float velx, Uint16 creationtimer, LTexture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Centra el globo en la posición X
|
||||
void allignTo(int x);
|
||||
@@ -119,67 +172,6 @@ public:
|
||||
|
||||
// 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "struct.h"
|
||||
#include "utils.h"
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef BULLET_H
|
||||
|
||||
89
source/coffeedrop.cpp
Normal file
89
source/coffeedrop.cpp
Normal 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
50
source/coffeedrop.h
Normal 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
|
||||
338
source/const.h
338
source/const.h
@@ -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,7 @@ 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_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 +97,92 @@ 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
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT 6
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT 7
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT 8
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT 9
|
||||
#define PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT 10
|
||||
#define PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT 11
|
||||
|
||||
// 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 +197,88 @@ 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
|
||||
|
||||
// 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 75
|
||||
|
||||
// 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
|
||||
|
||||
// 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
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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,33 +22,272 @@
|
||||
// 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
|
||||
{
|
||||
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 mText; // Variable con todos los objetos de texto
|
||||
|
||||
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)
|
||||
bool keyPressed; // Variable para evitar la repetición de teclas en los menus
|
||||
};
|
||||
menu mMenu; // Variable con todos los objetos menus y sus variables
|
||||
|
||||
struct intro
|
||||
{
|
||||
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 mIntro; // Contiene todas las variables de la sección 'Intro'
|
||||
|
||||
struct game
|
||||
{
|
||||
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 stage; // Pantalla actual
|
||||
Uint8 stageCounter; // Contador para el tiempo visible del texto de Stage
|
||||
float 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
|
||||
Uint8 menaceLevelCurrent; // Nivel de amenaza actual
|
||||
Uint8 menaceLevelThreshold; // 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 playFieldDrawOnly; // Indica si el bucle de juego avanza o solo pinta
|
||||
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
|
||||
SmartSprite *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
|
||||
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
|
||||
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
|
||||
};
|
||||
game mGame; // Variable con todas las variables usadas durante el juego
|
||||
|
||||
struct title
|
||||
{
|
||||
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 mTitle; // Variable con todas las variables de la pantalla de titulo
|
||||
|
||||
struct demo
|
||||
{
|
||||
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 keys; // Variable con las pulsaciones de teclas del modo demo
|
||||
DemoKeys dataFile[TOTAL_DEMO_DATA]; // Datos del fichero con los movimientos para la demo
|
||||
};
|
||||
demo mDemo; // Variable con todas las variables relacionadas con el modo demo
|
||||
|
||||
struct options
|
||||
{
|
||||
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 mOptions; // Variable con todas las variables de las opciones del programa
|
||||
|
||||
struct logo
|
||||
{
|
||||
Uint16 counter; // Contador
|
||||
Sprite *sprite; // Sprite con la textura del logo
|
||||
};
|
||||
logo mLogo; // Variable con las variables para el logo
|
||||
|
||||
struct prog
|
||||
{
|
||||
bool debug; // Indica si se va a mostrar la información de debug
|
||||
bool quit; // Indica si hay que salir del programa
|
||||
Input keyboard; // Almacena los códigos de teclado correspondientes
|
||||
Input 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 mProg; // Contiene todas las variables globales del programa
|
||||
|
||||
struct resourceBinFile
|
||||
{
|
||||
std::string file; // Ruta al fichero
|
||||
};
|
||||
resourceBinFile mBinFile[TOTAL_BINFILE]; // Todos los ficheros binarios
|
||||
|
||||
struct resourceSound
|
||||
{
|
||||
std::string file; // Ruta al fichero
|
||||
JA_Sound sound; // Variable con el sonido
|
||||
};
|
||||
resourceSound mSound[TOTAL_SOUND]; // Todos los sonidos
|
||||
|
||||
struct resourceMusic
|
||||
{
|
||||
std::string file; // Ruta al fichero
|
||||
JA_Music music; // Variable con la música
|
||||
};
|
||||
resourceMusic mMusic[TOTAL_MUSIC]; // Todas las músicas
|
||||
|
||||
struct resourceTexture
|
||||
{
|
||||
std::string file; // Ruta al fichero
|
||||
LTexture *texture; // Variable con la textura
|
||||
};
|
||||
resourceTexture 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 section = 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();
|
||||
|
||||
// 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);
|
||||
@@ -82,10 +323,10 @@ public:
|
||||
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, Uint16 stoppedcounter, LTexture *texture);
|
||||
|
||||
// Establece a cero todos los valores del vector de objetos globo
|
||||
void resetBalloons();
|
||||
@@ -94,7 +335,7 @@ public:
|
||||
void popBalloon(Uint8 index);
|
||||
|
||||
// Explosiona todos los globos
|
||||
void popAllBallons();
|
||||
void popAllBalloons();
|
||||
|
||||
// Detiene todos los globos
|
||||
void stopAllBalloons(Uint16 time);
|
||||
@@ -106,13 +347,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();
|
||||
@@ -168,11 +409,30 @@ 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 setMenaceLevel();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint8 getMenaceLevel();
|
||||
@@ -190,10 +450,10 @@ public:
|
||||
bool isTimeStopped();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTimeStoppedTimer(Uint16 value);
|
||||
void setTimeStoppedCounter(Uint16 value);
|
||||
|
||||
// Actualiza y comprueba el valor de la variable
|
||||
void updateTimeStoppedTimer();
|
||||
void updateTimeStoppedCounter();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setExplosionTime(bool value);
|
||||
@@ -205,10 +465,10 @@ 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 updateMenaceLevel();
|
||||
|
||||
// Actualiza el campo de juego
|
||||
void updatePlayField();
|
||||
@@ -232,10 +492,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);
|
||||
@@ -265,7 +525,7 @@ public:
|
||||
void runIntro();
|
||||
|
||||
// Bucle para el titulo del juego
|
||||
void runTitle();
|
||||
void runTitle(Uint8 section = TITLE_SECTION_1);
|
||||
|
||||
// Bucle para el juego
|
||||
void runGame();
|
||||
@@ -290,260 +550,6 @@ 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];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,4 +12,6 @@
|
||||
|
||||
#ifdef __linux__
|
||||
#include "/usr/include/SDL2/SDL.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define UNUSED
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "ifdefs.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "struct.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef ITEM_H
|
||||
#define ITEM_H
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
105
source/main.cpp
105
source/main.cpp
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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,9 @@ 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;
|
||||
|
||||
// Establece la altura y el ancho del jugador
|
||||
mWidth = 3 * BLOCK;
|
||||
@@ -51,12 +54,8 @@ 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;
|
||||
mScore = 9500;
|
||||
|
||||
// Establece el multiplicador de puntos inicial
|
||||
mScoreMultiplier = 1.0f;
|
||||
@@ -331,7 +330,7 @@ void Player::render()
|
||||
{
|
||||
if (mInvulnerable)
|
||||
{
|
||||
if ((mInvulnerableTimer % 10) > 4)
|
||||
if ((mInvulnerableCounter % 10) > 4)
|
||||
{
|
||||
mSpriteLegs->render();
|
||||
mSpriteBody->render();
|
||||
@@ -694,26 +693,26 @@ void Player::setInvulnerable(bool value)
|
||||
// Obtiene el valor de la variable
|
||||
bool Player::getInvulnerableTimer()
|
||||
{
|
||||
return mInvulnerableTimer;
|
||||
return mInvulnerableCounter;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setInvulnerableTimer(Uint16 value)
|
||||
{
|
||||
mInvulnerableTimer = value;
|
||||
mInvulnerableCounter = value;
|
||||
}
|
||||
|
||||
// Actualiza el valor de la variable
|
||||
void Player::updateInvulnerableTimer()
|
||||
{
|
||||
if (mInvulnerableTimer > 0)
|
||||
if (mInvulnerableCounter > 0)
|
||||
{
|
||||
--mInvulnerableTimer;
|
||||
--mInvulnerableCounter;
|
||||
}
|
||||
else
|
||||
{
|
||||
mInvulnerable = false;
|
||||
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
|
||||
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,7 +733,7 @@ void Player::removeExtraHit()
|
||||
{
|
||||
mExtraHit = false;
|
||||
mInvulnerable = true;
|
||||
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
|
||||
mInvulnerableCounter = PLAYER_INVULNERABLE_COUNTER;
|
||||
}
|
||||
|
||||
// Obtiene el circulo de colisión
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "struct.h"
|
||||
#include "utils.h"
|
||||
#include "animatedsprite.h"
|
||||
|
||||
#ifndef PLAYER_H
|
||||
@@ -8,6 +8,38 @@
|
||||
// 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
|
||||
|
||||
AnimatedSprite *mSpriteLegs; // Sprite para dibujar las piernas
|
||||
AnimatedSprite *mSpriteBody; // Sprite para dibujar el cuerpo
|
||||
AnimatedSprite *mSpriteHead; // Sprite para dibujar la cabeza
|
||||
|
||||
Circle mCollider; // Circulo de colisión del jugador
|
||||
void shiftColliders(); // Actualiza el circulo de colisión a la posición del jugador
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Player();
|
||||
@@ -111,63 +143,6 @@ public:
|
||||
|
||||
// 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();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
@@ -26,7 +40,7 @@ public:
|
||||
void writeColored(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 +56,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
112
source/utils.cpp
Normal 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 &a, Circle &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 &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
|
||||
if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r)
|
||||
{
|
||||
//This box and the circle 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;
|
||||
}
|
||||
@@ -1,42 +1,57 @@
|
||||
#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
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
// 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 &a, Circle &b);
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(Circle &a, SDL_Rect &b);
|
||||
|
||||
// Detector de colisiones entre un dos rectangulos
|
||||
bool checkCollision(SDL_Rect a, SDL_Rect b);
|
||||
|
||||
// Inicializa el vector con los valores del seno
|
||||
void initSin();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user