Limpieza de código. Modificada la fuente nokiabig2. Puestas ayudas para los dos jugadores. Cambiado el tamaño del mensaje de juego completado

This commit is contained in:
2021-09-10 20:46:24 +02:00
parent 09421a093d
commit bdf092d46e
35 changed files with 377 additions and 655 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@@ -4,13 +4,11 @@
// Constructor // Constructor
AnimatedSprite::AnimatedSprite() AnimatedSprite::AnimatedSprite()
{ {
//init(nullptr, nullptr);
} }
// Destructor // Destructor
AnimatedSprite::~AnimatedSprite() AnimatedSprite::~AnimatedSprite()
{ {
//init(nullptr, nullptr);
} }
// Iniciador // Iniciador
@@ -41,10 +39,10 @@ void AnimatedSprite::animate(int index)
{ {
if (mEnabled) if (mEnabled)
{ {
// Calculamos el frame actual a partir del contador // Calcula el frame actual a partir del contador
mCurrentFrame = mAnimationCounter / mAnimation[index].speed; mCurrentFrame = mAnimationCounter / mAnimation[index].speed;
// Si alcanzamos el final de la animación, reiniciamos el contador de la animación // Si alcanza el final de la animación, reinicia el contador de la animación
// en función de la variable loop // en función de la variable loop
if (mCurrentFrame >= mAnimation[index].numFrames) if (mCurrentFrame >= mAnimation[index].numFrames)
{ {
@@ -56,10 +54,10 @@ void AnimatedSprite::animate(int index)
// En caso contrario // En caso contrario
else else
{ {
// Escogemos el frame correspondiente de la animación // Escoge el frame correspondiente de la animación
setSpriteClip(mAnimation[index].frames[mCurrentFrame]); setSpriteClip(mAnimation[index].frames[mCurrentFrame]);
// Incrementamos el contador de la animacion // Incrementa el contador de la animacion
mAnimationCounter++; mAnimationCounter++;
} }
} }

View File

@@ -351,13 +351,16 @@ void Balloon::init(float x, float y, Uint8 kind, float velx, float speed, Uint16
mPosX = x; mPosX = x;
mPosY = y; mPosY = y;
mBouncing.enabled = false; // Si el efecto está activo // Valores para el efecto de rebote
mBouncing.counter = 0; // Countador para el efecto mBouncing.enabled = false;
mBouncing.speed = 0; // Velocidad a la que transcurre el efecto mBouncing.counter = 0;
mBouncing.zoomW = 1.0f; // Zoom aplicado a la anchura mBouncing.speed = 0;
mBouncing.zoomH = 1.0f; // Zoom aplicado a la altura mBouncing.zoomW = 1.0f;
mBouncing.despX = 0.0f; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom mBouncing.zoomH = 1.0f;
mBouncing.despX = 0.0f;
mBouncing.despY = 0.0f; mBouncing.despY = 0.0f;
mBouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f};
mBouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f};
// Textura con los gráficos del sprite // Textura con los gráficos del sprite
mSprite->setTexture(texture); mSprite->setTexture(texture);
@@ -432,13 +435,9 @@ void Balloon::allignTo(int x)
mPosX = float(x - (mWidth / 2)); mPosX = float(x - (mWidth / 2));
if (mPosX < PLAY_AREA_LEFT) if (mPosX < PLAY_AREA_LEFT)
{
mPosX = PLAY_AREA_LEFT + 1; mPosX = PLAY_AREA_LEFT + 1;
}
else if ((mPosX + mWidth) > PLAY_AREA_RIGHT) else if ((mPosX + mWidth) > PLAY_AREA_RIGHT)
{
mPosX = float(PLAY_AREA_RIGHT - mWidth - 1); mPosX = float(PLAY_AREA_RIGHT - mWidth - 1);
}
// Posición X,Y del sprite // Posición X,Y del sprite
mSprite->setPosX(getPosX()); mSprite->setPosX(getPosX());
@@ -531,10 +530,12 @@ void Balloon::move()
} }
/* /*
Para aplicar la gravedad, el diseño original la aplicaba en cada iteración del bucle 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 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 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 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 // Incrementa la variable que calcula la distancia acumulada en Y
@@ -550,11 +551,6 @@ void Balloon::move()
mVelY += mGravity; mVelY += mGravity;
std::min(mVelY, mMaxVelY); 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 // Actualiza la posición del sprite
mSprite->setPosX(getPosX()); mSprite->setPosX(getPosX());
@@ -679,12 +675,6 @@ void Balloon::updateState()
updateColliders(); updateColliders();
} }
// Hace visible el globo de forma intermitente
//if (mCreationCounter > 100)
// setVisible(mCreationCounter / 10 % 2 == 0);
//else
// setVisible(mCreationCounter / 5 % 2 == 0);
mCreationCounter--; mCreationCounter--;
} }
// El contador ha llegado a cero // El contador ha llegado a cero
@@ -711,7 +701,8 @@ void Balloon::updateState()
if (mStoppedCounter > 0) if (mStoppedCounter > 0)
mStoppedCounter--; mStoppedCounter--;
// Si el contador ha llegado a cero, ya no está detenido // Si el contador ha llegado a cero, ya no está detenido
else if (!isPopping()) // Quitarles el estado "detenido" si no estan explosionandoxq else if (!isPopping())
// Quitarles el estado "detenido" si no estan explosionando
setStop(false); setStop(false);
} }
} }
@@ -910,7 +901,6 @@ circle_t &Balloon::getCollider()
// Alinea el circulo de colisión con la posición del objeto globo // Alinea el circulo de colisión con la posición del objeto globo
void Balloon::updateColliders() void Balloon::updateColliders()
{ {
// Align collider to center of balloon
mCollider.x = Uint16(mPosX + mCollider.r); mCollider.x = Uint16(mPosX + mCollider.r);
mCollider.y = mPosY + mCollider.r; mCollider.y = mPosY + mCollider.r;
} }
@@ -940,6 +930,7 @@ void Balloon::bounceStart()
mBouncing.despX = 0; mBouncing.despX = 0;
mBouncing.despY = 0; mBouncing.despY = 0;
} }
void Balloon::bounceStop() void Balloon::bounceStop()
{ {
mBouncing.enabled = false; mBouncing.enabled = false;
@@ -951,6 +942,7 @@ void Balloon::bounceStop()
mBouncing.despX = 0.0f; mBouncing.despX = 0.0f;
mBouncing.despY = 0.0f; mBouncing.despY = 0.0f;
} }
void Balloon::updateBounce() void Balloon::updateBounce()
{ {
if (mBouncing.enabled) if (mBouncing.enabled)

View File

@@ -1,13 +1,71 @@
#pragma once #pragma once
#include "utils.h" #include "utils.h"
#include "animatedsprite.h" #include "animatedsprite.h"
#include <vector>
#ifndef BALLOON_H #ifndef BALLOON_H
#define BALLOON_H #define BALLOON_H
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
#define MAX_BOUNCE 10 #define MAX_BOUNCE 10
// Clase globo // Tipos de globo
#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
// Puntos de globo
#define BALLOON_SCORE_1 50
#define BALLOON_SCORE_2 100
#define BALLOON_SCORE_3 200
#define BALLOON_SCORE_4 400
// Tamaños de globo
#define BALLOON_SIZE_1 1
#define BALLOON_SIZE_2 2
#define BALLOON_SIZE_3 3
#define BALLOON_SIZE_4 4
// Clases de globo
#define BALLOON_CLASS 0
#define HEXAGON_CLASS 1
// Velocidad del globo
#define BALLOON_VELX_POSITIVE 0.7f
#define BALLOON_VELX_NEGATIVE -0.7f
// Indice para las animaciones de los globos
#define BALLOON_MOVING_ANIMATION 0
#define BALLOON_POP_ANIMATION 1
#define BALLOON_BORN_ANIMATION 2
// Cantidad posible de globos
#define MAX_BALLOONS 100
// Velocidades a las que se mueven los globos
#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_WIDTH_1 8
#define BALLOON_WIDTH_2 13
#define BALLOON_WIDTH_3 21
#define BALLOON_WIDTH_4 37
// PowerBall
#define POWERBALL_SCREENPOWER_MINIMUM 10
#define POWERBALL_COUNTER 8
// Clase Balloon
class Balloon class Balloon
{ {
private: private:
@@ -51,10 +109,8 @@ private:
float zoomH; // Zoom aplicado a la altura float zoomH; // Zoom aplicado a la altura
float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom float despX; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom float despY; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
// Vector con los valores de zoom para el ancho y alto del globo std::vector<float> h; // Vector con los valores de zoom para el 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; bouncing mBouncing;

View File

@@ -11,7 +11,6 @@ Bullet::Bullet()
// Destructor // Destructor
Bullet::~Bullet() Bullet::~Bullet()
{ {
//init(0, 0, NO_KIND, nullptr, nullptr);
delete mSprite; delete mSprite;
mSprite = nullptr; mSprite = nullptr;
} }
@@ -107,7 +106,7 @@ void Bullet::render()
Uint8 Bullet::move() Uint8 Bullet::move()
{ {
// Variable con el valor de retorno // Variable con el valor de retorno
Uint8 msg = MSG_OK; Uint8 msg = BULLET_MOVE_OK;
// Mueve el objeto a su nueva posición // Mueve el objeto a su nueva posición
mPosX += mVelX; mPosX += mVelX;
@@ -119,7 +118,7 @@ Uint8 Bullet::move()
mKind = NO_KIND; mKind = NO_KIND;
// Mensaje de salida // Mensaje de salida
msg = MSG_BULLET_OUT; msg = BULLET_MOVE_OUT;
} }
// Mueve el objeto a su nueva posición en vertical // Mueve el objeto a su nueva posición en vertical
@@ -132,7 +131,7 @@ Uint8 Bullet::move()
mKind = NO_KIND; mKind = NO_KIND;
// Mensaje de salida // Mensaje de salida
msg = MSG_BULLET_OUT; msg = BULLET_MOVE_OUT;
} }
// Actualiza la posición del sprite // Actualiza la posición del sprite
@@ -145,18 +144,6 @@ Uint8 Bullet::move()
return msg; return msg;
} }
#ifdef TEST
void Bullet::testMove()
{
// Update sprite position
mSprite->setPosX(mPosX);
mSprite->setPosY(mPosY);
// Update circle colliders
shiftColliders();
}
#endif
// Deshabilita el objeto // Deshabilita el objeto
void Bullet::erase() void Bullet::erase()
{ {
@@ -167,13 +154,9 @@ void Bullet::erase()
bool Bullet::isActive() bool Bullet::isActive()
{ {
if (mKind == NO_KIND) if (mKind == NO_KIND)
{
return false; return false;
}
else else
{
return true; return true;
}
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable

View File

@@ -5,7 +5,16 @@
#ifndef BULLET_H #ifndef BULLET_H
#define BULLET_H #define BULLET_H
// Clase bala // Tipos de bala
#define BULLET_UP 1
#define BULLET_LEFT 2
#define BULLET_RIGHT 3
// Tipos de retorno de la funcion move de la bala
#define BULLET_MOVE_OK 0
#define BULLET_MOVE_OUT 1
// Clase Bullet
class Bullet class Bullet
{ {
private: private:

View File

@@ -2,86 +2,23 @@
#include "ifdefs.h" #include "ifdefs.h"
#include "utils.h" #include "utils.h"
#include "lang.h" #include "lang.h"
#include <string>
#ifndef CONST_H #ifndef CONST_H
#define CONST_H #define CONST_H
// Textos // Tamaño de bloque
#define WINDOW_CAPTION "Coffee Crisis"
#define TEXT_COPYRIGHT "@2020,2021 JailDesigner (v2.0.2)"
// Recursos
//#define BINFILE_SCORE 0
//#define BINFILE_DEMO 1
//#define BINFILE_CONFIG 2
//
//#define TOTAL_BINFILE 3
//
//#define MUSIC_INTRO 0
//#define MUSIC_PLAYING 1
//#define MUSIC_TITLE 2
//
//#define TOTAL_MUSIC 3
//
//#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
//#define SOUND_CLOCK 16
//#define SOUND_POWERBALL 17
//
//#define TOTAL_SOUND 18
//
//#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
//
//#define TOTAL_TEXTURE 17
//
//// Tamaño de bloque
#define BLOCK 8 #define BLOCK 8
#define HALF_BLOCK BLOCK / 2 #define HALF_BLOCK BLOCK / 2
//
//// Tamaño de la pantalla real // Tamaño de la pantalla real
#define SCREEN_WIDTH 256 #define SCREEN_WIDTH 256
const int SCREEN_HEIGHT = SCREEN_WIDTH * 3 / 4; #define SCREEN_HEIGHT 192
//
//// Tamaño de la pantalla que se muestra // Tamaño de la pantalla que se muestra
const int VIEW_WIDTH = SCREEN_WIDTH * 3; const int VIEW_WIDTH = SCREEN_WIDTH * 3;
const int VIEW_HEIGHT = SCREEN_HEIGHT * 3; const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
//
//// Cantidad de enteros a escribir en los ficheros de datos
#define TOTAL_SCORE_DATA 3
#define TOTAL_DEMO_DATA 2000
//// Zona de juego // Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK); const int PLAY_AREA_TOP = (0 * BLOCK);
const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK); const int PLAY_AREA_BOTTOM = SCREEN_HEIGHT - (4 * BLOCK);
const int PLAY_AREA_LEFT = (0 * BLOCK); const int PLAY_AREA_LEFT = (0 * BLOCK);
@@ -94,8 +31,8 @@ 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_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4; const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3; const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
//
//// Anclajes de pantalla // Anclajes de pantalla
const int SCREEN_CENTER_X = SCREEN_WIDTH / 2; const int SCREEN_CENTER_X = SCREEN_WIDTH / 2;
const int SCREEN_FIRST_QUARTER_X = SCREEN_WIDTH / 4; const int SCREEN_FIRST_QUARTER_X = SCREEN_WIDTH / 4;
const int SCREEN_THIRD_QUARTER_X = (SCREEN_WIDTH / 4) * 3; const int SCREEN_THIRD_QUARTER_X = (SCREEN_WIDTH / 4) * 3;
@@ -103,56 +40,14 @@ const int SCREEN_CENTER_Y = SCREEN_HEIGHT / 2;
const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4; const int SCREEN_FIRST_QUARTER_Y = SCREEN_HEIGHT / 4;
const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3; const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
//// Opciones de menu // Secciones del programa
#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
#define MENU_BACKGROUND_TRANSPARENT 0
#define MENU_BACKGROUND_SOLID 1
//// Estados del jugador
#define PLAYER_STATUS_WALKING_LEFT 0
#define PLAYER_STATUS_WALKING_RIGHT 1
#define PLAYER_STATUS_WALKING_STOP 2
#define PLAYER_STATUS_FIRING_UP 0
#define PLAYER_STATUS_FIRING_LEFT 1
#define PLAYER_STATUS_FIRING_RIGHT 2
#define PLAYER_STATUS_FIRING_NO 3
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
#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_HEAD_WALKING_LEFT 0
#define PLAYER_ANIMATION_HEAD_FIRING_LEFT 1
#define PLAYER_ANIMATION_HEAD_WALKING_RIGHT 2
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
//// Variables del jugador
//#define PLAYER_INVULNERABLE_COUNTER 200
//#define PLAYER_POWERUP_COUNTER 1500
//
//// Secciones del programa
#define PROG_SECTION_LOGO 0 #define PROG_SECTION_LOGO 0
#define PROG_SECTION_INTRO 1 #define PROG_SECTION_INTRO 1
#define PROG_SECTION_TITLE 2 #define PROG_SECTION_TITLE 2
#define PROG_SECTION_GAME 3 #define PROG_SECTION_GAME 3
#define PROG_SECTION_QUIT 4 #define PROG_SECTION_QUIT 4
//
//// Subsecciones // Subsecciones
#define GAME_SECTION_PLAY_1P 0 #define GAME_SECTION_PLAY_1P 0
#define GAME_SECTION_PLAY_2P 1 #define GAME_SECTION_PLAY_2P 1
#define GAME_SECTION_PAUSE 2 #define GAME_SECTION_PAUSE 2
@@ -161,198 +56,18 @@ const int SCREEN_THIRD_QUARTER_Y = (SCREEN_HEIGHT / 4) * 3;
#define TITLE_SECTION_2 4 #define TITLE_SECTION_2 4
#define TITLE_SECTION_3 5 #define TITLE_SECTION_3 5
#define TITLE_SECTION_INSTRUCTIONS 6 #define TITLE_SECTION_INSTRUCTIONS 6
//
//// Modo para las instrucciones // Estados de cada elemento que pertenece a un evento
#define INSTRUCTIONS_MODE_MANUAL 0
#define INSTRUCTIONS_MODE_AUTO 1
//
//// Estados de cada elemento que pertenece a un evento
#define EVENT_WAITING 1 #define EVENT_WAITING 1
#define EVENT_RUNNING 2 #define EVENT_RUNNING 2
#define EVENT_COMPLETED 3 #define EVENT_COMPLETED 3
//// Cantidad de eventos de la intro // Ningun tipo
#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
//#define TITLE_TOTAL_EVENTS 2
//
//// Relaciones de Id con nomnbres
#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);
//const int SCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
//const int SCORE_NUMBER_X = (SCREEN_WIDTH / 4) - ((6 * BLOCK) / 2);
//const int SCORE_NUMBER_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
//
//const int HISCORE_WORD_X = ((SCREEN_WIDTH / 4) * 3) - ((8 * BLOCK) / 2);
//const int HISCORE_WORD_Y = SCREEN_HEIGHT - (3 * BLOCK) + 2;
//const int HISCORE_NUMBER_X = ((SCREEN_WIDTH / 4) * 3) - ((6 * BLOCK) / 2);
//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_Y = SCREEN_HEIGHT - (2 * BLOCK) + 2;
//
//// Ningun tipo
#define NO_KIND 0 #define NO_KIND 0
//
//// Tipos de globo
#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
//
//// Puntos de globo
#define BALLOON_SCORE_1 50
#define BALLOON_SCORE_2 100
#define BALLOON_SCORE_3 200
#define BALLOON_SCORE_4 400
//
//// Tamaños de globo
#define BALLOON_SIZE_1 1
#define BALLOON_SIZE_2 2
#define BALLOON_SIZE_3 3
#define BALLOON_SIZE_4 4
//
//// Clases de globo
#define BALLOON_CLASS 0
#define HEXAGON_CLASS 1
//
//// Velocidad del globo
#define BALLOON_VELX_POSITIVE 0.7f
#define BALLOON_VELX_NEGATIVE -0.7f
//// Indice para las animaciones de los globos // Colores
#define BALLOON_MOVING_ANIMATION 0
#define BALLOON_POP_ANIMATION 1
#define BALLOON_BORN_ANIMATION 2
//
//// Cantidad posible de globos
#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_WIDTH_1 8
#define BALLOON_WIDTH_2 13
#define BALLOON_WIDTH_3 21
#define BALLOON_WIDTH_4 37
//
//// PowerBall
#define POWERBALL_SCREENPOWER_MINIMUM 10
#define POWERBALL_COUNTER 8
//
//// Tipos de bala
#define BULLET_UP 1
#define BULLET_LEFT 2
#define BULLET_RIGHT 3
//
//// Cantidad posible de globos
#define MAX_BULLETS 50
//
//// Tipos de objetos
#define ITEM_POINTS_1_DISK 1
#define ITEM_POINTS_2_GAVINA 2
#define ITEM_POINTS_3_PACMAR 3
#define ITEM_CLOCK 4
#define ITEM_COFFEE 5
#define ITEM_POWER_BALL 6
#define ITEM_COFFEE_MACHINE 7
//// Porcentaje de aparición de los objetos
#define ITEM_POINTS_1_DISK_ODDS 10
#define ITEM_POINTS_2_GAVINA_ODDS 6
#define ITEM_POINTS_3_PACMAR_ODDS 3
#define ITEM_CLOCK_ODDS 5
#define ITEM_COFFEE_ODDS 5
#define ITEM_POWER_BALL_ODDS 0
#define ITEM_COFFEE_MACHINE_ODDS 4
//// Cantidad de objetos simultaneos
#define MAX_ITEMS 10
//
//// Valores para las variables asociadas a los objetos
#define REMAINING_EXPLOSIONS 3
#define REMAINING_EXPLOSIONS_COUNTER 50
#define TIME_STOPPED_COUNTER 300
//
//// Estados de entrada
#define NO_INPUT 0
#define INPUT_FIRE_LEFT 7
#define INPUT_FIRE_UP 8
#define INPUT_FIRE_RIGHT 9
//#define INPUT_PAUSE 10
//
//// Zona muerta del mando analógico
//#define JOYSTICK_DEAD_ZONE 8000
//
//// Tipos de mensajes para el retorno de las funciones
#define MSG_OK 0
#define MSG_BULLET_OUT 1
//
//// Tipos de texto
//#define TEXT_FIXED 0
//#define TEXT_VARIABLE 1
//
//// Cantidad de elementos del vector de SmartSprites
#define MAX_SMART_SPRITES 10
//
//// Cantidad máxima de gotas de café
//#define MAX_COFFEE_DROPS 100
//
//// Contadores
//#define TITLE_COUNTER 800
#define STAGE_COUNTER 200
#define INSTRUCTIONS_COUNTER 600
#define DEATH_COUNTER 350
#define SHAKE_COUNTER 10
#define HELP_COUNTER 1000
//
//// Colores
const color_t bgColor = {0x27, 0x27, 0x36}; const color_t bgColor = {0x27, 0x27, 0x36};
const color_t noColor = {0xFF, 0xFF, 0xFF}; const color_t noColor = {0xFF, 0xFF, 0xFF};
const color_t shdwTxtColor = {0x43, 0x43, 0x4F}; const color_t shdwTxtColor = {0x43, 0x43, 0x4F};
//// Formaciones enemigas
#define NUMBER_OF_ENEMY_FORMATIONS 100
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
//
//// Dificultad del juego
#define DIFFICULTY_EASY 0
#define DIFFICULTY_NORMAL 1
#define DIFFICULTY_HARD 2
//
//// Tipo de filtro
#define FILTER_NEAREST 0
#define FILTER_LINEAL 1
#endif #endif

View File

@@ -145,8 +145,7 @@ bool Director::initSDL()
bool success = true; bool success = true;
// Inicializa SDL // Inicializa SDL
//if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO) < 0)
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{ {
printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError()); printf("SDL could not initialize!\nSDL Error: %s\n", SDL_GetError());
success = false; success = false;

View File

@@ -20,30 +20,30 @@
#include "game.h" #include "game.h"
#include "input.h" #include "input.h"
#include "fade.h" #include "fade.h"
//#include <math.h>
#ifndef DIRECTOR_H #ifndef DIRECTOR_H
#define DIRECTOR_H #define DIRECTOR_H
// Textos
#define WINDOW_CAPTION "Coffee Crisis"
// Cantidad máxima de elementos para el vector con las rutas de los ficheros de recursos
#define MAX_FILE_LIST 100 #define MAX_FILE_LIST 100
// Director // Clase Director
class Director class Director
{ {
private: private:
SDL_Window *mWindow; // La ventana donde dibujamos SDL_Window *mWindow; // La ventana donde dibujamos
SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Renderer *mRenderer; // El renderizador de la ventana
Logo *mLogo; // Objeto para la sección del logo Logo *mLogo; // Objeto para la sección del logo
Intro *mIntro; // Objeto para la sección de la intro Intro *mIntro; // Objeto para la sección de la intro
Title *mTitle; // Objeto para la sección del titulo y el menu de opciones Title *mTitle; // Objeto para la sección del titulo y el menu de opciones
Game *mGame; // Objeto para la sección del juego Game *mGame; // Objeto para la sección del juego
Input *mInput; // Objeto Input para gestionar las entradas Input *mInput; // Objeto Input para gestionar las entradas
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos std::string mFileList[MAX_FILE_LIST]; // Vector con las rutas a los ficheros de recursos
struct options_t *mOptions; // Variable con todas las opciones del programa struct options_t *mOptions; // Variable con todas las opciones del programa
std::string mExecutablePath; // Path del ejecutable std::string mExecutablePath; // Path del ejecutable
section_t mSection; // Sección y subsección actual del programa; section_t mSection; // Sección y subsección actual del programa;

View File

@@ -25,9 +25,6 @@ void Fade::init(Uint8 r, Uint8 g, Uint8 b)
mEnabled = false; mEnabled = false;
mFinished = false; mFinished = false;
mCounter = 0; mCounter = 0;
//mR = 0x27;
//mG = 0x27;
//mB = 0x36;
mR = r; mR = r;
mG = g; mG = g;
mB = b; mB = b;
@@ -153,16 +150,7 @@ bool Fade::isEnabled()
// Comprueba si ha terminado la transicion // Comprueba si ha terminado la transicion
bool Fade::hasEnded() bool Fade::hasEnded()
{ {
if (mFinished) return mFinished;
{
//mEnabled = false;
//mFinished = false;
return true;
}
else
{
return false;
}
} }
// Establece el tipo de fade // Establece el tipo de fade

View File

@@ -5,11 +5,12 @@
#ifndef FADE_H #ifndef FADE_H
#define FADE_H #define FADE_H
// Tipos de fundido
#define FADE_FULLSCREEN 0 #define FADE_FULLSCREEN 0
#define FADE_CENTER 1 #define FADE_CENTER 1
#define FADE_RANDOM_SQUARE 2 #define FADE_RANDOM_SQUARE 2
// Fade // Clase Fade
class Fade class Fade
{ {
private: private:

View File

@@ -388,9 +388,6 @@ void Game::init()
initEnemyPools(); initEnemyPools();
initGameStages(); initGameStages();
// BORRAR
//mStage[mCurrentStage].currentPower = mStage[mCurrentStage].powerToComplete - 10;
// Modo debug // Modo debug
mDebug.enabled = false; mDebug.enabled = false;
mDebug.enemySet = 0; mDebug.enemySet = 0;
@@ -400,7 +397,7 @@ void Game::init()
mDemo.recording = false; mDemo.recording = false;
mDemo.counter = 0; mDemo.counter = 0;
// Iniciualiza el objeto para el fundido // Inicializa el objeto para el fundido
mFade->init(0x27, 0x27, 0x36); mFade->init(0x27, 0x27, 0x36);
// Inicializa el objeto con el menu de pausa // Inicializa el objeto con el menu de pausa
@@ -1526,12 +1523,6 @@ void Game::increaseStageCurrentPower(Uint8 power)
mStage[mCurrentStage].currentPower += power; mStage[mCurrentStage].currentPower += power;
} }
// Establece el valor de la variable
/*void Game::setScore(Uint32 score)
{
mScore = score;
}*/
// Establece el valor de la variable // Establece el valor de la variable
void Game::setHiScore(Uint32 score) void Game::setHiScore(Uint32 score)
{ {
@@ -1607,39 +1598,8 @@ std::string Game::updateScoreText(Uint32 num)
// Pinta el marcador en pantalla usando un objeto texto // Pinta el marcador en pantalla usando un objeto texto
void Game::renderScoreBoard() void Game::renderScoreBoard()
{ {
//color_t color = {0, 0, 0};
// Si el jugador esta muerto, no pintes el fondo del marcador, así que pase por encima cuando sale despedido
//if (mPlayer[0]->isAlive())
mSpriteScoreBoard->render(); mSpriteScoreBoard->render();
/*
// SCORE
mText->writeCentered(PLAY_AREA_CENTER_FIRST_QUARTER_X, SCORE_WORD_Y - 6, mLang->getText(39), 0);
mText->writeCentered(PLAY_AREA_CENTER_FIRST_QUARTER_X, SCORE_NUMBER_Y - 6, updateScoreText(mPlayer[0]->getScore()), 0);
// HI-SCORE
mText->writeCentered(PLAY_AREA_CENTER_THIRD_QUARTER_X, HISCORE_WORD_Y - 6, mLang->getText(40), 0);
mText->writeCentered(PLAY_AREA_CENTER_THIRD_QUARTER_X, HISCORE_NUMBER_Y - 6, updateScoreText(mHiScore), 0);
// MULT
color.g = 255;
mText->writeColored(MULTIPLIER_WORD_X, MULTIPLIER_WORD_Y - 6, mLang->getText(41), color);
color.g = 192;
mTextX2->writeShadowed(PLAY_AREA_CENTER_X - 16, SCORE_WORD_Y + 5, std::to_string(mPlayer[0]->getScoreMultiplier()).substr(0, 1), color, 1);
mText->writeShadowed(PLAY_AREA_CENTER_X - 2, SCORE_WORD_Y + 12, ".", color);
mText->writeShadowed(PLAY_AREA_CENTER_X + 4, SCORE_WORD_Y + 12, std::to_string(mPlayer[0]->getScoreMultiplier()).substr(2, 1), color);
// STAGE
mText->writeCentered(PLAY_AREA_CENTER_FIRST_QUARTER_X, SCORE_NUMBER_Y + 4, mLang->getText(42) + std::to_string(mStage[mCurrentStage].number), 0);
// POWER
mSpritePowerMeter->setSpriteClip(256, 184, 40, 8);
mSpritePowerMeter->render();
const float percent = (mStage[mCurrentStage].currentPower * 40.0f) / mStage[mCurrentStage].powerToComplete;
mSpritePowerMeter->setSpriteClip(296, 184, (int)percent, 8);
mSpritePowerMeter->render();
*/
const int offset1 = 162; const int offset1 = 162;
const int offset2 = offset1 + 7; const int offset2 = offset1 + 7;
const int offset3 = offset2 + 7; const int offset3 = offset2 + 7;
@@ -1801,8 +1761,6 @@ void Game::updateDeath()
if (allAreDead) if (allAreDead)
{ {
//JA_StopMusic();
if (mDeathCounter > 0) if (mDeathCounter > 0)
{ {
mDeathCounter--; mDeathCounter--;
@@ -2244,7 +2202,6 @@ void Game::checkBulletBalloonCollision()
int index = mBullet[j]->getOwner(); int index = mBullet[j]->getOwner();
mPlayer[index]->incScoreMultiplier(); mPlayer[index]->incScoreMultiplier();
mPlayer[index]->addScore(Uint32(mBalloon[i]->getScore() * mPlayer[index]->getScoreMultiplier() * mDifficultyScoreMultiplier)); mPlayer[index]->addScore(Uint32(mBalloon[i]->getScore() * mPlayer[index]->getScoreMultiplier() * mDifficultyScoreMultiplier));
//setScore(mPlayer[index]->getScore());
updateHiScore(); updateHiScore();
// Explota el globo // Explota el globo
@@ -2281,7 +2238,7 @@ void Game::moveBullets()
{ {
for (int i = 0; i < MAX_BULLETS; i++) for (int i = 0; i < MAX_BULLETS; i++)
if (mBullet[i]->isActive()) if (mBullet[i]->isActive())
if (mBullet[i]->move() == MSG_BULLET_OUT) if (mBullet[i]->move() == BULLET_MOVE_OUT)
mPlayer[mBullet[i]->getOwner()]->decScoreMultiplier(); mPlayer[mBullet[i]->getOwner()]->decScoreMultiplier();
} }
@@ -2357,11 +2314,6 @@ void Game::resetItems()
// Devuelve un item en función del azar // Devuelve un item en función del azar
Uint8 Game::dropItem() Uint8 Game::dropItem()
{ {
//if (mPlayer[0]->isPowerUp() || (mCoffeeMachineEnabled))
// return NO_KIND;
//else
// return ITEM_COFFEE_MACHINE;
const Uint8 luckyNumber = rand() % 100; const Uint8 luckyNumber = rand() % 100;
const Uint8 item = rand() % 6; const Uint8 item = rand() % 6;
@@ -2426,6 +2378,7 @@ void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
{ {
const Uint8 index = getSmartSpriteFreeIndex(); const Uint8 index = getSmartSpriteFreeIndex();
// Crea una copia del objeto
*mSmartSprite[index] = *sprite; *mSmartSprite[index] = *sprite;
mSmartSprite[index]->setPosX(x); mSmartSprite[index]->setPosX(x);
mSmartSprite[index]->setPosY(y); mSmartSprite[index]->setPosY(y);
@@ -2842,12 +2795,12 @@ void Game::checkGameInput()
mPlayer[index]->setInput(INPUT_RIGHT); mPlayer[index]->setInput(INPUT_RIGHT);
if (mDemo.dataFile[mDemo.counter].noInput == 1) if (mDemo.dataFile[mDemo.counter].noInput == 1)
mPlayer[index]->setInput(NO_INPUT); mPlayer[index]->setInput(INPUT_NULL);
if (mDemo.dataFile[mDemo.counter].fire == 1) if (mDemo.dataFile[mDemo.counter].fire == 1)
if (mPlayer[index]->canFire()) if (mPlayer[index]->canFire())
{ {
mPlayer[index]->setInput(INPUT_FIRE_UP); mPlayer[index]->setInput(INPUT_BUTTON_2);
createBullet(mPlayer[index]->getPosX() + (mPlayer[index]->getWidth() / 2) - 4, mPlayer[index]->getPosY() + (mPlayer[index]->getHeight() / 2), BULLET_UP, mPlayer[index]->isPowerUp(), index); createBullet(mPlayer[index]->getPosX() + (mPlayer[index]->getWidth() / 2) - 4, mPlayer[index]->getPosY() + (mPlayer[index]->getHeight() / 2), BULLET_UP, mPlayer[index]->isPowerUp(), index);
mPlayer[index]->setFireCooldown(10); mPlayer[index]->setFireCooldown(10);
} }
@@ -2855,7 +2808,7 @@ void Game::checkGameInput()
if (mDemo.dataFile[mDemo.counter].fireLeft == 1) if (mDemo.dataFile[mDemo.counter].fireLeft == 1)
if (mPlayer[index]->canFire()) if (mPlayer[index]->canFire())
{ {
mPlayer[index]->setInput(INPUT_FIRE_LEFT); mPlayer[index]->setInput(INPUT_BUTTON_1);
createBullet(mPlayer[index]->getPosX() + (mPlayer[index]->getWidth() / 2) - 4, mPlayer[index]->getPosY() + (mPlayer[index]->getHeight() / 2), BULLET_UP, mPlayer[index]->isPowerUp(), index); createBullet(mPlayer[index]->getPosX() + (mPlayer[index]->getWidth() / 2) - 4, mPlayer[index]->getPosY() + (mPlayer[index]->getHeight() / 2), BULLET_UP, mPlayer[index]->isPowerUp(), index);
mPlayer[index]->setFireCooldown(10); mPlayer[index]->setFireCooldown(10);
} }
@@ -2863,7 +2816,7 @@ void Game::checkGameInput()
if (mDemo.dataFile[mDemo.counter].fireRight == 1) if (mDemo.dataFile[mDemo.counter].fireRight == 1)
if (mPlayer[index]->canFire()) if (mPlayer[index]->canFire())
{ {
mPlayer[index]->setInput(INPUT_FIRE_RIGHT); mPlayer[index]->setInput(INPUT_BUTTON_3);
createBullet(mPlayer[index]->getPosX() + (mPlayer[index]->getWidth() / 2) - 4, mPlayer[index]->getPosY() + (mPlayer[index]->getHeight() / 2), BULLET_UP, mPlayer[index]->isPowerUp(), index); createBullet(mPlayer[index]->getPosX() + (mPlayer[index]->getWidth() / 2) - 4, mPlayer[index]->getPosY() + (mPlayer[index]->getHeight() / 2), BULLET_UP, mPlayer[index]->isPowerUp(), index);
mPlayer[index]->setFireCooldown(10); mPlayer[index]->setFireCooldown(10);
} }
@@ -2900,7 +2853,7 @@ void Game::checkGameInput()
else else
{ {
// Ninguno de los dos inputs anteriores // Ninguno de los dos inputs anteriores
mPlayer[i]->setInput(NO_INPUT); mPlayer[i]->setInput(INPUT_NULL);
mDemo.keys.noInput = 1; mDemo.keys.noInput = 1;
} }
} }
@@ -2909,7 +2862,7 @@ void Game::checkGameInput()
{ {
if (mPlayer[i]->canFire()) if (mPlayer[i]->canFire())
{ {
mPlayer[i]->setInput(INPUT_FIRE_UP); mPlayer[i]->setInput(INPUT_BUTTON_2);
createBullet(mPlayer[i]->getPosX() + (mPlayer[i]->getWidth() / 2) - 4, mPlayer[i]->getPosY() + (mPlayer[i]->getHeight() / 2), BULLET_UP, mPlayer[i]->isPowerUp(), i); createBullet(mPlayer[i]->getPosX() + (mPlayer[i]->getWidth() / 2) - 4, mPlayer[i]->getPosY() + (mPlayer[i]->getHeight() / 2), BULLET_UP, mPlayer[i]->isPowerUp(), i);
mPlayer[i]->setFireCooldown(10); mPlayer[i]->setFireCooldown(10);
@@ -2925,7 +2878,7 @@ void Game::checkGameInput()
{ {
if (mPlayer[i]->canFire()) if (mPlayer[i]->canFire())
{ {
mPlayer[i]->setInput(INPUT_FIRE_LEFT); mPlayer[i]->setInput(INPUT_BUTTON_1);
createBullet(mPlayer[i]->getPosX() + (mPlayer[i]->getWidth() / 2) - 4, mPlayer[i]->getPosY() + (mPlayer[i]->getHeight() / 2), BULLET_LEFT, mPlayer[i]->isPowerUp(), i); createBullet(mPlayer[i]->getPosX() + (mPlayer[i]->getWidth() / 2) - 4, mPlayer[i]->getPosY() + (mPlayer[i]->getHeight() / 2), BULLET_LEFT, mPlayer[i]->isPowerUp(), i);
mPlayer[i]->setFireCooldown(10); mPlayer[i]->setFireCooldown(10);
@@ -2941,7 +2894,7 @@ void Game::checkGameInput()
{ {
if (mPlayer[i]->canFire()) if (mPlayer[i]->canFire())
{ {
mPlayer[i]->setInput(INPUT_FIRE_RIGHT); mPlayer[i]->setInput(INPUT_BUTTON_3);
createBullet(mPlayer[i]->getPosX() + (mPlayer[i]->getWidth() / 2) - 4, mPlayer[i]->getPosY() + (mPlayer[i]->getHeight() / 2), BULLET_RIGHT, mPlayer[i]->isPowerUp(), i); createBullet(mPlayer[i]->getPosX() + (mPlayer[i]->getWidth() / 2) - 4, mPlayer[i]->getPosY() + (mPlayer[i]->getHeight() / 2), BULLET_RIGHT, mPlayer[i]->isPowerUp(), i);
mPlayer[i]->setFireCooldown(10); mPlayer[i]->setFireCooldown(10);
@@ -2981,10 +2934,6 @@ void Game::renderMessages()
if ((mCounter < STAGE_COUNTER) && (!mDemo.enabled)) if ((mCounter < STAGE_COUNTER) && (!mDemo.enabled))
{ {
mSpriteGetReady->setPosX((int)mGetReadyBitmapPath[mCounter]); mSpriteGetReady->setPosX((int)mGetReadyBitmapPath[mCounter]);
//mSpriteGetReady->render();
//const color_t color = {0x17, 0x17, 0x26};
//mTextBig->writeShadowed((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), color, 2);
//mTextBig->writeDX(TXT_STROKE, (int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), 1, noColor, 1, shdwTxtColor);
mTextNokiaBig2->write((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), -2); mTextNokiaBig2->write((int)mGetReadyBitmapPath[mCounter], PLAY_AREA_CENTER_Y - 8, mLang->getText(75), -2);
} }
@@ -2993,10 +2942,6 @@ void Game::renderMessages()
{ {
if ((mTimeStoppedCounter > 100) || (mTimeStoppedCounter % 10 > 4)) if ((mTimeStoppedCounter > 100) || (mTimeStoppedCounter % 10 > 4))
mTextNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor); mTextNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36) + std::to_string(mTimeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor);
//{
// mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y, mLang->getText(36), -2);
// mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, PLAY_AREA_FIRST_QUARTER_Y + mTextNokiaBig2->getCharacterWidth() + 2, std::to_string(mTimeStoppedCounter / 10), -2);
//}
if (mTimeStoppedCounter > 100) if (mTimeStoppedCounter > 100)
{ {
@@ -3027,7 +2972,7 @@ void Game::renderMessages()
{ // Texto de juego completado { // Texto de juego completado
text = mLang->getText(50); text = mLang->getText(50);
mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, -2, noColor, 1, shdwTxtColor); mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter], text, -2, noColor, 1, shdwTxtColor);
mTextNokiaBig2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter] + mTextNokiaBig2->getCharacterWidth() + 2, mLang->getText(76), -1, noColor, 1, shdwTxtColor); mTextNokia2->writeDX(TXT_CENTER, PLAY_AREA_CENTER_X, mStageBitmapPath[mStageBitmapCounter] + mTextNokiaBig2->getCharacterWidth() + 2, mLang->getText(76), -1, noColor, 1, shdwTxtColor);
} }
} }
} }
@@ -3197,13 +3142,7 @@ void Game::runPausedGame()
} }
} }
// Dibuja los objetos // Pinta el escenario
//renderBackground();
//renderBalloons();
//renderBullets();
//for (int i = 0; i < mNumPlayers; i++)
// mPlayer[i]->render();
//renderScoreBoard();
renderPlayField(); renderPlayField();
mMenuPause->render(); mMenuPause->render();
mFade->render(); mFade->render();
@@ -3218,7 +3157,6 @@ void Game::runPausedGame()
switch (mMenuPause->getItemSelected()) switch (mMenuPause->getItemSelected())
{ {
case 0: case 0:
//mMenuPause->reset();
mSection.name = PROG_SECTION_GAME; mSection.name = PROG_SECTION_GAME;
if (mNumPlayers == 1) if (mNumPlayers == 1)
mSection.subsection = GAME_SECTION_PLAY_1P; mSection.subsection = GAME_SECTION_PLAY_1P;
@@ -3229,7 +3167,6 @@ void Game::runPausedGame()
break; break;
case 1: case 1:
//mMenuPause->reset();
mFade->setFadeType(FADE_CENTER); mFade->setFadeType(FADE_CENTER);
mFade->activateFade(); mFade->activateFade();
break; break;
@@ -3346,13 +3283,9 @@ void Game::runGameOverScreen()
void Game::renderDebugInfo() void Game::renderDebugInfo()
{ {
const color_t color = {0xFF, 0x20, 0x20}; const color_t color = {0xFF, 0x20, 0x20};
//mText->writeShadowed(2, 2 + 0 * BLOCK, "POW: " + std::to_string(mPlayer[0]->mPowerUpCounter), color);
//if (mHelper.needCoffeeMachine)
// mText->writeShadowed(2, 2 + 1 * BLOCK, "NEED COFFEMACHINE", color);
if (mDebug.enabled) if (mDebug.enabled)
{ {
//SDL_RenderSetLogicalSize(mRenderer, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2);
mText->writeShadowed(2, 2 + 0 * BLOCK, "menace(umb): " + std::to_string(mMenaceCurrent) + "(" + std::to_string(mMenaceThreshold) + ")", color); mText->writeShadowed(2, 2 + 0 * BLOCK, "menace(umb): " + std::to_string(mMenaceCurrent) + "(" + std::to_string(mMenaceThreshold) + ")", color);
mText->writeShadowed(2, 2 + 1 * BLOCK, "currentPower: " + std::to_string(mStage[mCurrentStage].currentPower), color); mText->writeShadowed(2, 2 + 1 * BLOCK, "currentPower: " + std::to_string(mStage[mCurrentStage].currentPower), color);
mText->writeShadowed(2, 2 + 2 * BLOCK, "mCurrentStage:" + std::to_string(mCurrentStage), color); mText->writeShadowed(2, 2 + 2 * BLOCK, "mCurrentStage:" + std::to_string(mCurrentStage), color);
@@ -3451,20 +3384,22 @@ void Game::updateGameCompleted()
// Actualiza las variables de ayuda // Actualiza las variables de ayuda
void Game::updateHelper() void Game::updateHelper()
{ {
// El ayudante solo funciona para un jugador // Solo ofrece ayuda cuando la amenaza es elevada
// Solo ofrece ayuda cuando la amenaza o la velocidad es elevada
if (mMenaceCurrent > 15) if (mMenaceCurrent > 15)
{ {
if (mPlayer[0]->getCoffees() == 0) for (int i = 0; i < mNumPlayers; i++)
{
if (mPlayer[i]->getCoffees() == 0)
mHelper.needCoffee = true; mHelper.needCoffee = true;
else else
mHelper.needCoffee = false; mHelper.needCoffee = false;
if (!mPlayer[0]->isPowerUp()) if (!mPlayer[i]->isPowerUp())
mHelper.needCoffeeMachine = true; mHelper.needCoffeeMachine = true;
else else
mHelper.needCoffeeMachine = false; mHelper.needCoffeeMachine = false;
} }
}
else else
{ {
mHelper.needCoffee = false; mHelper.needCoffee = false;

View File

@@ -22,7 +22,43 @@
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
// Game // Cantidad de elementos a escribir en los ficheros de datos
#define TOTAL_SCORE_DATA 3
#define TOTAL_DEMO_DATA 2000
// Contadores
#define STAGE_COUNTER 200
#define SHAKE_COUNTER 10
#define HELP_COUNTER 1000
// Formaciones enemigas
#define NUMBER_OF_ENEMY_FORMATIONS 100
#define MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION 50
// Cantidad de elementos del vector de SmartSprites
#define MAX_SMART_SPRITES 10
// Cantidad máxima posible de balas
#define MAX_BULLETS 50
// Porcentaje de aparición de los objetos
#define ITEM_POINTS_1_DISK_ODDS 10
#define ITEM_POINTS_2_GAVINA_ODDS 6
#define ITEM_POINTS_3_PACMAR_ODDS 3
#define ITEM_CLOCK_ODDS 5
#define ITEM_COFFEE_ODDS 5
#define ITEM_POWER_BALL_ODDS 0
#define ITEM_COFFEE_MACHINE_ODDS 4
// Cantidad de objetos simultaneos
#define MAX_ITEMS 10
// Valores para las variables asociadas a los objetos
#define REMAINING_EXPLOSIONS 3
#define REMAINING_EXPLOSIONS_COUNTER 50
#define TIME_STOPPED_COUNTER 300
// Clase Game
class Game class Game
{ {
private: private:

View File

@@ -1,15 +1,4 @@
#ifdef _WIN64
#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\SDL2\SDL.h"
#endif
#ifdef _WIN32
#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\SDL2\SDL.h"
#endif
#ifdef __APPLE__
//#include "/Library/Frameworks/SDL2.framework/Versions/A/Headers/SDL.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif
#ifdef __linux__ #ifdef __linux__
#ifdef __MIPSEL__ #ifdef __MIPSEL__

View File

@@ -1,9 +1,6 @@
#include "input.h" #include "input.h"
#include <iostream> #include <iostream>
// Contestar cuantos joystics ha detectado
// Preguntarlepor los joystics que ha encontrado para ir poniendolos en la variable de opciones
// Constructor // Constructor
Input::Input(std::string file) Input::Input(std::string file)
{ {

View File

@@ -49,10 +49,9 @@ private:
}; };
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
//SDL_GameController *mGameController; // Manejador para el mando std::vector<SDL_GameController *> mConnectedControllers; // Vector con todos los mandos conectados
std::vector<SDL_GameController*> mConnectedControllers; std::vector<std::string> mControllerNames; // Vector con los nombres de los mandos
std::vector<std::string> mControllerNames; int mNumGamepads; // Numero de mandos conectados
int mNumGamepads;
std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt
// Comprueba si hay un mando conectado // Comprueba si hay un mando conectado
@@ -72,7 +71,7 @@ public:
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button); void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
// Comprueba si un input esta activo // Comprueba si un input esta activo
bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY, int index=0); bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0);
// Comprueba si hay algun mando conectado // Comprueba si hay algun mando conectado
bool gameControllerFound(); bool gameControllerFound();

View File

@@ -10,7 +10,14 @@
#ifndef INSTRUCTIONS_H #ifndef INSTRUCTIONS_H
#define INSTRUCTIONS_H #define INSTRUCTIONS_H
// Instructions // Contadores
#define INSTRUCTIONS_COUNTER 600
// Modo para las instrucciones
#define INSTRUCTIONS_MODE_MANUAL 0
#define INSTRUCTIONS_MODE_AUTO 1
// Clase Instructions
class Instructions class Instructions
{ {
private: private:

View File

@@ -181,9 +181,7 @@ void Intro::init()
mWriter[8]->setSpeed(20); mWriter[8]->setSpeed(20);
for (int i = 0; i < INTRO_TOTAL_TEXTS; i++) for (int i = 0; i < INTRO_TOTAL_TEXTS; i++)
{
mWriter[i]->center(SCREEN_CENTER_X); mWriter[i]->center(SCREEN_CENTER_X);
}
} }
// Carga los recursos // Carga los recursos
@@ -208,10 +206,7 @@ section_t Intro::run()
// Si la música no está sonando // Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ JA_PlayMusic(mMusic, 0); // Reproduce la música
// Reproduce la música
JA_PlayMusic(mMusic, 0);
}
while (mSection.name == PROG_SECTION_INTRO) while (mSection.name == PROG_SECTION_INTRO)
{ {

View File

@@ -10,7 +10,29 @@
#ifndef INTRO_H #ifndef INTRO_H
#define INTRO_H #define INTRO_H
// Intro // Cantidad de eventos de la intro
#define INTRO_TOTAL_BITMAPS 6
#define INTRO_TOTAL_TEXTS 9
const int INTRO_TOTAL_EVENTS = INTRO_TOTAL_BITMAPS + INTRO_TOTAL_TEXTS;
// Relaciones de Id con nombres
#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
// Clase Intro
class Intro class Intro
{ {
private: private:

View File

@@ -1,6 +1,5 @@
#include "const.h" #include "const.h"
#include "item.h" #include "item.h"
#include <stdio.h>
// Constructor // Constructor
Item::Item() Item::Item()

View File

@@ -6,7 +6,16 @@
#ifndef ITEM_H #ifndef ITEM_H
#define ITEM_H #define ITEM_H
// Clase AnimatedSprite // Tipos de objetos
#define ITEM_POINTS_1_DISK 1
#define ITEM_POINTS_2_GAVINA 2
#define ITEM_POINTS_3_PACMAR 3
#define ITEM_CLOCK 4
#define ITEM_COFFEE 5
#define ITEM_POWER_BALL 6
#define ITEM_COFFEE_MACHINE 7
// Clase Item
class Item class Item
{ {
private: private:

View File

@@ -5,7 +5,7 @@
#ifndef LANG_H #ifndef LANG_H
#define LANG_H #define LANG_H
// Lang codes // Códigos de idioma
#define es_ES 0 #define es_ES 0
#define ba_BA 1 #define ba_BA 1
#define en_UK 2 #define en_UK 2
@@ -19,7 +19,7 @@ class Lang
{ {
private: private:
std::string *mFileList; // Lista de ficheros con los recursos std::string *mFileList; // Lista de ficheros con los recursos
std::string mTextStrings[MAX_TEXT_STRINGS]; std::string mTextStrings[MAX_TEXT_STRINGS]; // Vector con los textos
public: public:
// Constructor // Constructor

View File

@@ -9,7 +9,7 @@
#ifndef LOGO_H #ifndef LOGO_H
#define LOGO_H #define LOGO_H
// Logo // Clase Logo
class Logo class Logo
{ {
private: private:

View File

@@ -227,26 +227,15 @@ bool Menu::increaseSelectorIndex()
mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index); mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index);
// Calcula cual es el siguiente elemento // Calcula cual es el siguiente elemento
//if (mSelector.index < (mTotalItems - 1))
//{
// mSelector.index++;
// while ((!mItem[mSelector.index].selectable) && (mSelector.index < (mTotalItems - 1)))
// mSelector.index++;
// success = true;
//}
// Calcula cual es el siguiente elemento (versión con loop)
//if (mSelector.index < (mTotalItems - 1))
{
++mSelector.index %= mTotalItems; ++mSelector.index %= mTotalItems;
while (!mItem[mSelector.index].selectable) while (!mItem[mSelector.index].selectable)
//mSelector.index++; //mSelector.index++;
++mSelector.index %= mTotalItems; ++mSelector.index %= mTotalItems;
success = true; success = true;
}
// Establece las coordenadas y altura de destino
if (success) if (success)
{ // Establece las coordenadas y altura de destino {
mSelector.targetY = mItem[mSelector.index].rect.y; mSelector.targetY = mItem[mSelector.index].rect.y;
mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps; mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps;
@@ -271,17 +260,6 @@ bool Menu::decreaseSelectorIndex()
mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index); mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index);
// Calcula cual es el siguiente elemento // Calcula cual es el siguiente elemento
//if (mSelector.index > 0)
//{
// mSelector.index--;
// while ((!mItem[mSelector.index].selectable) && (mSelector.index > 0))
// mSelector.index--;
// success = true;
//}
// Calcula cual es el siguiente elemento (versión con loop)
//if (mSelector.index > 0)
{
if (mSelector.index == 0) if (mSelector.index == 0)
mSelector.index = mTotalItems; mSelector.index = mTotalItems;
else else
@@ -294,10 +272,10 @@ bool Menu::decreaseSelectorIndex()
mSelector.index--; mSelector.index--;
} }
success = true; success = true;
}
// Establece las coordenadas y altura de destino
if (success) if (success)
{ // Establece las coordenadas y altura de destino {
mSelector.targetY = mItem[mSelector.index].rect.y; mSelector.targetY = mItem[mSelector.index].rect.y;
mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps; mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps;
@@ -370,10 +348,6 @@ void Menu::render()
mText->write(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label); mText->write(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label);
} }
} }
//borrar
//mText->write(0, 0, std::to_string(mSelector.h) + " " + std::to_string(mSelector.incH) + " " + std::to_string(mSelector.resizing));
//mText->write(0, 8, std::to_string(mSelector.y) + " " + std::to_string(mSelector.despY) + " " + std::to_string(mSelector.moving));
} }
} }
@@ -433,9 +407,6 @@ void Menu::centerMenuOnX(int value)
mIsCenteredOnX = true; mIsCenteredOnX = true;
mCenterX = value; mCenterX = value;
// Actualiza el rectangulo de fondo para recalcular las dimensiones
//setRectSize();
// Establece la nueva posición centrada en funcion del elemento más ancho // Establece la nueva posición centrada en funcion del elemento más ancho
mPosX = (value) - (findWidth() / 2); mPosX = (value) - (findWidth() / 2);
@@ -453,9 +424,6 @@ void Menu::centerMenuOnY(int value)
mIsCenteredOnY = true; mIsCenteredOnY = true;
mCenterY = value; mCenterY = value;
// Actualiza el rectangulo de fondo para recalcular las dimensiones
//setRectSize();
// Establece la nueva posición centrada en funcion del elemento más ancho // Establece la nueva posición centrada en funcion del elemento más ancho
mPosY = (value) - (findHeight() / 2); mPosY = (value) - (findHeight() / 2);
@@ -497,7 +465,6 @@ void Menu::addItem(std::string text, Uint8 hPaddingDown, bool selectable, bool g
setTotalItems(mTotalItems + 1); setTotalItems(mTotalItems + 1);
mCenterX = mPosX + (findWidth() / 2); mCenterX = mPosX + (findWidth() / 2);
//setSelectorPos(0);
reorganize(); reorganize();
} }
@@ -520,16 +487,12 @@ void Menu::setDefaultActionWhenCancel(Uint8 item)
void Menu::checkInput() void Menu::checkInput()
{ {
if (mInput->checkInput(INPUT_UP, REPEAT_FALSE)) if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
{
if (decreaseSelectorIndex()) if (decreaseSelectorIndex())
JA_PlaySound(mSoundMove); JA_PlaySound(mSoundMove);
}
if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE)) if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE))
{
if (increaseSelectorIndex()) if (increaseSelectorIndex())
JA_PlaySound(mSoundMove); JA_PlaySound(mSoundMove);
}
if (mInput->checkInput(INPUT_ACCEPT, REPEAT_FALSE)) if (mInput->checkInput(INPUT_ACCEPT, REPEAT_FALSE))
{ {

View File

@@ -8,9 +8,17 @@
#ifndef MENU_H #ifndef MENU_H
#define MENU_H #define MENU_H
// Cantidad máxima de items en el menu
#define MENU_MAX_ITEMS 50 #define MENU_MAX_ITEMS 50
// Clase menu // Tipos de fondos para el menu
#define MENU_BACKGROUND_TRANSPARENT 0
#define MENU_BACKGROUND_SOLID 1
// Opciones de menu
#define MENU_NO_OPTION -1
// Clase Menu
class Menu class Menu
{ {
private: private:

View File

@@ -262,15 +262,15 @@ void Player::setInput(Uint8 input)
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT); setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
break; break;
case INPUT_FIRE_UP: case INPUT_BUTTON_2:
setFiringStatus(PLAYER_STATUS_FIRING_UP); setFiringStatus(PLAYER_STATUS_FIRING_UP);
break; break;
case INPUT_FIRE_LEFT: case INPUT_BUTTON_1:
setFiringStatus(PLAYER_STATUS_FIRING_LEFT); setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
break; break;
case INPUT_FIRE_RIGHT: case INPUT_BUTTON_3:
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT); setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
break; break;
@@ -291,10 +291,7 @@ void Player::move()
// Si el jugador abandona el area de juego por los laterales // Si el jugador abandona el area de juego por los laterales
if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5)) if ((mPosX < PLAY_AREA_LEFT - 5) || (mPosX + mWidth > PLAY_AREA_RIGHT + 5))
{ mPosX -= mVelX; // Restaura su posición
// Restaura su posición
mPosX -= mVelX;
}
// Actualiza la posición del sprite // Actualiza la posición del sprite
mSpriteLegs->setPosX(getPosX()); mSpriteLegs->setPosX(getPosX());
@@ -509,13 +506,9 @@ bool Player::canFire()
{ {
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador // Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
if (mCooldown > 0) if (mCooldown > 0)
{
return false; return false;
}
else else
{
return true; return true;
}
} }
// Establece el valor de la variable // Establece el valor de la variable

View File

@@ -6,7 +6,42 @@
#ifndef PLAYER_H #ifndef PLAYER_H
#define PLAYER_H #define PLAYER_H
// The player // Contadores
#define DEATH_COUNTER 350
// Estados del jugador
#define PLAYER_STATUS_WALKING_LEFT 0
#define PLAYER_STATUS_WALKING_RIGHT 1
#define PLAYER_STATUS_WALKING_STOP 2
#define PLAYER_STATUS_FIRING_UP 0
#define PLAYER_STATUS_FIRING_LEFT 1
#define PLAYER_STATUS_FIRING_RIGHT 2
#define PLAYER_STATUS_FIRING_NO 3
#define PLAYER_ANIMATION_LEGS_WALKING_RIGHT 1
#define PLAYER_ANIMATION_LEGS_WALKING_STOP 2
#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_HEAD_WALKING_LEFT 0
#define PLAYER_ANIMATION_HEAD_FIRING_LEFT 1
#define PLAYER_ANIMATION_HEAD_WALKING_RIGHT 2
#define PLAYER_ANIMATION_HEAD_FIRING_RIGHT 3
#define PLAYER_ANIMATION_HEAD_WALKING_STOP 4
#define PLAYER_ANIMATION_HEAD_FIRING_UP 5
#define PLAYER_ANIMATION_LEGS_WALKING_LEFT 0
// Variables del jugador
#define PLAYER_INVULNERABLE_COUNTER 200
#define PLAYER_POWERUP_COUNTER 1500
// Clase Player
class Player class Player
{ {
private: private:

View File

@@ -4,13 +4,11 @@
// Constructor // Constructor
SmartSprite::SmartSprite() SmartSprite::SmartSprite()
{ {
//init(nullptr, nullptr);
} }
// Destructor // Destructor
SmartSprite::~SmartSprite() SmartSprite::~SmartSprite()
{ {
//init(nullptr, nullptr);
} }
// Inicializador // Inicializador
@@ -114,7 +112,7 @@ bool SmartSprite::update()
// Comprueba si se desplaza en el eje X hacia la derecha // Comprueba si se desplaza en el eje X hacia la derecha
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0))) if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
{ {
// Comprueba si hemos llegado al destino // Comprueba si ha llegado al destino
if (getPosX() > mDestX) if (getPosX() > mDestX)
{ {
// Lo coloca en posición // Lo coloca en posición
@@ -128,7 +126,7 @@ bool SmartSprite::update()
// Comprueba si se desplaza en el eje X hacia la izquierda // Comprueba si se desplaza en el eje X hacia la izquierda
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0))) else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
{ {
// Comprueba si hemos llegado al destino // Comprueba si ha llegado al destino
if (getPosX() < mDestX) if (getPosX() < mDestX)
{ {
// Lo coloca en posición // Lo coloca en posición
@@ -143,7 +141,7 @@ bool SmartSprite::update()
// Comprueba si se desplaza en el eje Y hacia abajo // Comprueba si se desplaza en el eje Y hacia abajo
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0))) if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
{ {
// Comprueba si hemos llegado al destino // Comprueba si ha llegado al destino
if (getPosY() > mDestY) if (getPosY() > mDestY)
{ {
// Lo coloca en posición // Lo coloca en posición
@@ -157,7 +155,7 @@ bool SmartSprite::update()
// Comprueba si se desplaza en el eje Y hacia arriba // Comprueba si se desplaza en el eje Y hacia arriba
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0))) else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
{ {
// Comprueba si hemos llegado al destino // Comprueba si ha llegado al destino
if (getPosY() < mDestY) if (getPosY() < mDestY)
{ {
// Lo coloca en posición // Lo coloca en posición
@@ -171,13 +169,9 @@ bool SmartSprite::update()
// Comprueba si ha llegado a su destino // Comprueba si ha llegado a su destino
if ((getPosX() == mDestX) && (getPosY() == mDestY)) if ((getPosX() == mDestX) && (getPosY() == mDestY))
{
mIsOnDestination = true; mIsOnDestination = true;
}
else else
{
mIsOnDestination = false; mIsOnDestination = false;
}
// Si esta en el destino comprueba su contador // Si esta en el destino comprueba su contador
if (mIsOnDestination) if (mIsOnDestination)
@@ -185,7 +179,7 @@ bool SmartSprite::update()
// Si el contador es mayor que cero, lo decrementa // Si el contador es mayor que cero, lo decrementa
if (mEnabledCounter > 0) if (mEnabledCounter > 0)
{ {
--mEnabledCounter; mEnabledCounter--;
} }
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id // Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
else if (mEnabledCounter == 0) else if (mEnabledCounter == 0)
@@ -215,9 +209,7 @@ bool SmartSprite::isOnDestination()
void SmartSprite::render() void SmartSprite::render()
{ {
if (mEnabled) if (mEnabled)
{
MovingSprite::render(); MovingSprite::render();
}
} }
// Establece el valor de la variable // Establece el valor de la variable

View File

@@ -10,7 +10,7 @@
#define TXT_CENTER 4 #define TXT_CENTER 4
#define TXT_STROKE 8 #define TXT_STROKE 8
// Clase texto. Pinta texto en pantalla a partir de un bitmap // Clase Text. Pinta texto en pantalla a partir de una cadena y un bitmap
class Text class Text
{ {
private: private:
@@ -18,9 +18,9 @@ private:
struct Offset struct Offset
{ {
int x; int x; // Posición en el eje X dentro del bitmap
int y; int y; // Posición en el eje Y dentro del bitmap
Uint8 w; Uint8 w; // Ancho en pixeles de la letra
}; };
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra

View File

@@ -33,6 +33,7 @@ Title::Title(SDL_Window *window, SDL_Renderer *renderer, Input *input, std::stri
mMenu.title = new Menu(mRenderer, mText, mInput, mFileList); mMenu.title = new Menu(mRenderer, mText, mInput, mFileList);
mMenu.options = new Menu(mRenderer, mText, mInput, mFileList); mMenu.options = new Menu(mRenderer, mText, mInput, mFileList);
// Crea la textura para el mosaico de fondo
mBackground = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2); mBackground = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2);
if (mBackground == NULL) if (mBackground == NULL)
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError()); printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
@@ -136,8 +137,7 @@ void Title::init(bool demo, Uint8 subsection)
mFade->init(0x17, 0x17, 0x26); mFade->init(0x17, 0x17, 0x26);
mDemo = demo; mDemo = demo;
//if (!mInput->gameControllerFound()) // Pone valores por defecto a las opciones de control
{
mOptions->input[0].id = 0; mOptions->input[0].id = 0;
mOptions->input[0].name = "KEYBOARD"; mOptions->input[0].name = "KEYBOARD";
mOptions->input[0].deviceType = INPUT_USE_KEYBOARD; mOptions->input[0].deviceType = INPUT_USE_KEYBOARD;
@@ -145,13 +145,15 @@ void Title::init(bool demo, Uint8 subsection)
mOptions->input[1].id = 0; mOptions->input[1].id = 0;
mOptions->input[1].name = "GAME CONTROLLER"; mOptions->input[1].name = "GAME CONTROLLER";
mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER; mOptions->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
}
// Comprueba si hay mandos conectados
checkInputDevices(); checkInputDevices();
mDeviceIndex[0] = mAvailableInputDevices.size() - 1; // Pone valores por defecto
mDeviceIndex[1] = 0; mDeviceIndex[0] = mAvailableInputDevices.size() - 1; // El último dispositivo encontrado es el teclado
mDeviceIndex[1] = 0; // El primer mando encontrado. Si no ha encontrado ninguno es el teclado
// Si ha encontrado un mando se lo asigna al segundo jugador
if (mInput->gameControllerFound()) if (mInput->gameControllerFound())
{ {
mOptions->input[1].id = mAvailableInputDevices[mDeviceIndex[1]].id; mOptions->input[1].id = mAvailableInputDevices[mDeviceIndex[1]].id;
@@ -244,6 +246,7 @@ void Title::init(bool demo, Uint8 subsection)
// Crea el mosaico de fondo del titulo // Crea el mosaico de fondo del titulo
createTiledBackground(); createTiledBackground();
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar
mBackgroundWindow.x = 128; mBackgroundWindow.x = 128;
mBackgroundWindow.y = 96; mBackgroundWindow.y = 96;
mBackgroundWindow.w = SCREEN_WIDTH; mBackgroundWindow.w = SCREEN_WIDTH;
@@ -251,9 +254,7 @@ void Title::init(bool demo, Uint8 subsection)
// Inicializa los valores del vector con los valores del seno // Inicializa los valores del vector con los valores del seno
for (int i = 0; i < 360; i++) for (int i = 0; i < 360; i++)
{
mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f); mSin[i] = SDL_sinf((float)i * 3.14f / 180.0f);
}
// Inicializa los objetos de menu // Inicializa los objetos de menu
mMenu.title->init("TITLE", 0, (14 * BLOCK) + 4, MENU_BACKGROUND_TRANSPARENT); mMenu.title->init("TITLE", 0, (14 * BLOCK) + 4, MENU_BACKGROUND_TRANSPARENT);
@@ -380,7 +381,6 @@ void Title::updateMenuLabels()
else else
{ {
mMenu.options->setGreyed(i, false); mMenu.options->setGreyed(i, false);
//mMenu.options->setItemCaption(i, mInput->getControllerName(0));
mMenu.options->setItemCaption(i, mOptions->input[0].name); mMenu.options->setItemCaption(i, mOptions->input[0].name);
} }
break; break;
@@ -410,7 +410,6 @@ void Title::updateMenuLabels()
else else
{ {
mMenu.options->setGreyed(i, false); mMenu.options->setGreyed(i, false);
//mMenu.options->setItemCaption(i, mInput->getControllerName(0));
mMenu.options->setItemCaption(i, mOptions->input[1].name); mMenu.options->setItemCaption(i, mOptions->input[1].name);
} }
break; break;
@@ -496,15 +495,18 @@ void Title::updateMenuLabels()
// CANCEL // CANCEL
mMenu.options->setItemCaption(i, mLang->getText(10)); // CANCEL mMenu.options->setItemCaption(i, mLang->getText(10)); // CANCEL
// Recoloca el menu de opciones
mMenu.options->centerMenuOnX(SCREEN_CENTER_X); mMenu.options->centerMenuOnX(SCREEN_CENTER_X);
mMenu.options->centerMenuOnY(SCREEN_CENTER_Y); mMenu.options->centerMenuOnY(SCREEN_CENTER_Y);
mMenu.options->centerMenuElementsOnX(); mMenu.options->centerMenuElementsOnX();
// Establece las etiquetas del menu de titulo
mMenu.title->setItemCaption(0, mLang->getText(51)); // 1 PLAYER mMenu.title->setItemCaption(0, mLang->getText(51)); // 1 PLAYER
mMenu.title->setItemCaption(1, mLang->getText(52)); // 2 PLAYERS mMenu.title->setItemCaption(1, mLang->getText(52)); // 2 PLAYERS
mMenu.title->setItemCaption(2, mLang->getText(1)); // OPTIONS mMenu.title->setItemCaption(2, mLang->getText(1)); // OPTIONS
mMenu.title->setItemCaption(3, mLang->getText(3)); // QUIT mMenu.title->setItemCaption(3, mLang->getText(3)); // QUIT
// Recoloca el menu de titulo
mMenu.title->centerMenuOnX(SCREEN_CENTER_X); mMenu.title->centerMenuOnX(SCREEN_CENTER_X);
mMenu.title->centerMenuElementsOnX(); mMenu.title->centerMenuElementsOnX();
} }
@@ -655,10 +657,7 @@ section_t Title::run(Uint8 subsection)
// Si la música no está sonando // Si la música no está sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED)) if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{ JA_PlayMusic(mMusic); // Reproduce la música
// Reproduce la música
JA_PlayMusic(mMusic);
}
// Calcula la lógica de los objetos // Calcula la lógica de los objetos
if (SDL_GetTicks() - mTicks > mTicksSpeed) if (SDL_GetTicks() - mTicks > mTicksSpeed)
@@ -842,10 +841,8 @@ section_t Title::run(Uint8 subsection)
} }
if (mMenu.active->getName() == "TITLE") if (mMenu.active->getName() == "TITLE")
{
mCounter--; mCounter--;
} }
}
// Limpia la pantalla // Limpia la pantalla
SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255); SDL_SetRenderDrawColor(mRenderer, bgColor.r, bgColor.g, bgColor.b, 255);
@@ -949,29 +946,23 @@ bool Title::updatePlayerInputs(int numPlayer)
} }
else // Si hay mas de un dispositivo, se recorre el vector else // Si hay mas de un dispositivo, se recorre el vector
{ {
printf("numplayer:%i\n",numPlayer); printf("numplayer:%i\n", numPlayer);
printf("deviceindex:%i\n",mDeviceIndex[numPlayer]); printf("deviceindex:%i\n", mDeviceIndex[numPlayer]);
// Incrementa el indice // Incrementa el indice
if (mDeviceIndex[numPlayer] < numDevices - 1) if (mDeviceIndex[numPlayer] < numDevices - 1)
mDeviceIndex[numPlayer]++; mDeviceIndex[numPlayer]++;
else else
mDeviceIndex[numPlayer] = 0; mDeviceIndex[numPlayer] = 0;
printf("deviceindex:%i\n",mDeviceIndex[numPlayer]); printf("deviceindex:%i\n", mDeviceIndex[numPlayer]);
// Si coincide con el del otro jugador, se lo intercambian // Si coincide con el del otro jugador, se lo intercambian
if (mDeviceIndex[0] == mDeviceIndex[1]) if (mDeviceIndex[0] == mDeviceIndex[1])
{ {
printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]);
//const int temp = mDeviceIndex[0];
//mDeviceIndex[0] = mDeviceIndex[1];
//mDeviceIndex[1] = temp;
const int theOtherPlayer = (numPlayer + 1) % 2; const int theOtherPlayer = (numPlayer + 1) % 2;
mDeviceIndex[theOtherPlayer]--; mDeviceIndex[theOtherPlayer]--;
if (mDeviceIndex[theOtherPlayer] < 0) if (mDeviceIndex[theOtherPlayer] < 0)
mDeviceIndex[theOtherPlayer]=numDevices-1; mDeviceIndex[theOtherPlayer] = numDevices - 1;
printf("%i:%i\n",mDeviceIndex[0],mDeviceIndex[1]);
} }
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador // Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador

View File

@@ -2,11 +2,9 @@
#include "ifdefs.h" #include "ifdefs.h"
#include "const.h" #include "const.h"
#include "utils.h" #include "utils.h"
#include "sprite.h" #include "sprite.h"
#include "movingsprite.h" #include "movingsprite.h"
#include "smartsprite.h" #include "smartsprite.h"
#include "item.h" #include "item.h"
#include "text.h" #include "text.h"
#include "menu.h" #include "menu.h"
@@ -19,7 +17,16 @@
#ifndef TITLE_H #ifndef TITLE_H
#define TITLE_H #define TITLE_H
// Title // Textos
#define TEXT_COPYRIGHT "@2020,2021 JailDesigner (v2.0.2)"
// Contadores
#define TITLE_COUNTER 800
// Cantidad de eventos de la pantalla de titulo
#define TITLE_TOTAL_EVENTS 2
// Clase Title
class Title class Title
{ {
private: private:

View File

@@ -17,10 +17,7 @@ bool checkCollision(circle_t &a, circle_t &b)
// Si la distancia entre el centro de los circulos es inferior a la suma de sus radios // 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)) if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared))
{ return true; // Los circulos han colisionado
// Los circulos han colisionado
return true;
}
// En caso contrario // En caso contrario
return false; return false;

View File

@@ -6,6 +6,15 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
// Dificultad del juego
#define DIFFICULTY_EASY 0
#define DIFFICULTY_NORMAL 1
#define DIFFICULTY_HARD 2
// Tipo de filtro
#define FILTER_NEAREST 0
#define FILTER_LINEAL 1
// Estructura para definir un circulo // Estructura para definir un circulo
struct circle_t struct circle_t
{ {

View File

@@ -134,9 +134,7 @@ void Writer::update()
void Writer::render() void Writer::render()
{ {
if (mEnabled) if (mEnabled)
{
mText->write(mPosX, mPosY, mCaption, mKerning, mIndex); mText->write(mPosX, mPosY, mCaption, mKerning, mIndex);
}
} }
// Centra la cadena de texto a un punto X // Centra la cadena de texto a un punto X

View File

@@ -5,7 +5,7 @@
#ifndef WRITER_H #ifndef WRITER_H
#define WRITER_H #define WRITER_H
// Clase texto. Pinta texto en pantalla a partir de un bitmap // Clase Writer. Pinta texto en pantalla a partir de una cadena y un bitmap
class Writer class Writer
{ {
private: private: