Acomodats els estats del jugador
El compte enrrere per a continuar ara ix al acabar la animació de morir Afegit el estat "entering_name"
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <errno.h> // for errno, EACCES, EEXIST, ENAMETOO...
|
||||
#include <pwd.h> // for getpwuid, passwd
|
||||
#include <stdio.h> // for printf, perror, size_t
|
||||
#include <string.h> // for strcmp
|
||||
#include <sys/stat.h> // for stat, mkdir, S_IRWXU
|
||||
@@ -34,6 +33,10 @@
|
||||
#include "title.h" // for Title
|
||||
#include "utils.h" // for music_file_t, sound_file_t, opt...
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <pwd.h> // for getpwuid, passwd
|
||||
#endif
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, char *argv[])
|
||||
{
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
#include "enter_name.h"
|
||||
#include <algorithm> // for max, min
|
||||
#include <algorithm> // for max, min
|
||||
|
||||
// Constructor
|
||||
EnterName::EnterName(std::string *name)
|
||||
{
|
||||
characterList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
// Obtiene el puntero al nombre
|
||||
this->name = name;
|
||||
|
||||
// Inicia la lista de caracteres permitidos
|
||||
characterList = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
pos = 0;
|
||||
numCharacters = (int)characterList.size();
|
||||
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
characterIndex[i] = 0;
|
||||
@@ -33,13 +37,32 @@ void EnterName::decPos()
|
||||
pos = std::max(pos, 0);
|
||||
}
|
||||
|
||||
// Incrementa el índice
|
||||
void EnterName::incIndex()
|
||||
{
|
||||
++characterIndex[pos];
|
||||
if (characterIndex[pos] >= numCharacters)
|
||||
{
|
||||
characterIndex[pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Decrementa el índice
|
||||
void EnterName::decIndex()
|
||||
{
|
||||
--characterIndex[pos];
|
||||
if (characterIndex[pos] < 0)
|
||||
{
|
||||
characterIndex[pos] = numCharacters - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la variable
|
||||
void EnterName::updateName()
|
||||
{
|
||||
name->clear();
|
||||
for (int i = 0; i < NAME_LENGHT; ++i)
|
||||
{
|
||||
name->append("a");
|
||||
//name->append(characterIndex[i] = 0;
|
||||
name->push_back(characterList[characterIndex[i]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,20 @@
|
||||
|
||||
#define NAME_LENGHT 8
|
||||
|
||||
/*
|
||||
Un array, "characterList", contiene la lista de caracteres
|
||||
Un segundo array, "characterIndex", contiene el indice a "characterList" de cada una de las letras que conforman el nombre
|
||||
"pos" es la posición de "characterIndex" que se está modificando
|
||||
Izquierda o derecha modifican "pos", arriba o abajo modifican el índice de "characterIndex[pos]"
|
||||
Pulsar cualquier botón, mueve "pos" a la derecha. Al pulsar el botón en la ´´ultima posición se finaliza la introducción de nombres
|
||||
*/
|
||||
|
||||
// Clase EnterName
|
||||
class EnterName
|
||||
{
|
||||
private:
|
||||
std::string characterList; // Lista de todos los caracteres permitidos
|
||||
std::string *name; // Nombre introducido
|
||||
std::string *name; // Nombre introducido
|
||||
int pos; // Posición a editar del nombre
|
||||
int numCharacters; // Cantidad de caracteres de la lista de caracteres
|
||||
int characterIndex[NAME_LENGHT]; // Indice de la lista para cada uno de los caracteres que forman el nombre
|
||||
@@ -20,6 +28,12 @@ private:
|
||||
// Decrementa la posición
|
||||
void decPos();
|
||||
|
||||
// Incrementa el índice
|
||||
void incIndex();
|
||||
|
||||
// Decrementa el índice
|
||||
void decIndex();
|
||||
|
||||
// Actualiza la variable
|
||||
void updateName();
|
||||
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
#include "game.h"
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_h
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_R...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for min
|
||||
#include <fstream> // for basic_ifstream
|
||||
#include <iostream> // for char_traits, basic_istream, ifstream
|
||||
#include "asset.h" // for Asset
|
||||
#include "background.h" // for Background
|
||||
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
|
||||
#include "bullet.h" // for Bullet, BULLET_LEFT, BULLET_RIGHT
|
||||
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
|
||||
#include "explosions.h" // for Explosions
|
||||
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN...
|
||||
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
|
||||
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
||||
#include "lang.h" // for getText
|
||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "player.h" // for Player, PLAYER_STATUS_PLAYING, PLA...
|
||||
#include "scoreboard.h" // for Scoreboard, scoreboard_modes_e
|
||||
#include "screen.h" // for Screen
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "text.h" // for Text, TXT_CENTER
|
||||
#include "texture.h" // for Texture
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||
#include <SDL2/SDL_keycode.h> // for SDLK_1, SDLK_2, SDLK_3, SDLK_h
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_rwops.h> // for SDL_RWFromFile, SDL_RWclose, SDL_R...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_FOCUS_GAINED, SDL_...
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for min
|
||||
#include <fstream> // for basic_ifstream
|
||||
#include <iostream> // for char_traits, basic_istream, ifstream
|
||||
#include "asset.h" // for Asset
|
||||
#include "background.h" // for Background
|
||||
#include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_...
|
||||
#include "bullet.h" // for Bullet, BULLET_LEFT, BULLET_RIGHT
|
||||
#include "enemy_formations.h" // for stage_t, EnemyFormations, enemyIni...
|
||||
#include "explosions.h" // for Explosions
|
||||
#include "fade.h" // for Fade, FADE_RANDOM_SQUARE, FADE_VEN...
|
||||
#include "input.h" // for inputs_e, Input, INPUT_DO_NOT_ALLO...
|
||||
#include "item.h" // for Item, ITEM_COFFEE_MACHINE, ITEM_CLOCK
|
||||
#include "jail_audio.h" // for JA_PlaySound, JA_DeleteSound, JA_L...
|
||||
#include "lang.h" // for getText
|
||||
#include "manage_hiscore_table.h" // for ManageHiScoreTable
|
||||
#include "options.h" // for options
|
||||
#include "param.h" // for param
|
||||
#include "player.h" // for Player, PLAYER_STATUS_PLAYING, PLA...
|
||||
#include "scoreboard.h" // for Scoreboard, scoreboard_modes_e
|
||||
#include "screen.h" // for Screen
|
||||
#include "smart_sprite.h" // for SmartSprite
|
||||
#include "text.h" // for Text, TXT_CENTER
|
||||
#include "texture.h" // for Texture
|
||||
struct JA_Music_t;
|
||||
struct JA_Sound_t;
|
||||
|
||||
@@ -1744,11 +1744,10 @@ void Game::killPlayer(Player *player)
|
||||
JA_PlaySound(playerCollisionSound);
|
||||
screen->shake();
|
||||
JA_PlaySound(coffeeOutSound);
|
||||
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(PLAYER_STATUS_CONTINUE);
|
||||
player->setStatusPlaying(PLAYER_STATUS_DYING);
|
||||
if (!demo.enabled)
|
||||
{ // En el modo DEMO ni se para la musica ni se añade la puntuación a la tabla
|
||||
allPlayersAreWaiting() ? JA_StopMusic() : JA_ResumeMusic();
|
||||
addScoreToScoreBoard(player->getName(), player->getScore());
|
||||
allPlayersAreNotPlaying() ? JA_StopMusic() : JA_ResumeMusic();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2584,6 +2583,18 @@ bool Game::allPlayersAreWaiting()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
bool Game::allPlayersAreNotPlaying()
|
||||
{
|
||||
bool success = true;
|
||||
for (auto player : players)
|
||||
{
|
||||
success &= !player->isPlaying();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Comprueba los eventos que hay en cola
|
||||
void Game::checkEvents()
|
||||
{
|
||||
@@ -2809,12 +2820,33 @@ void Game::checkPlayersStatusPlaying()
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_GAME_OVER);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_ENTERING_NAME:
|
||||
scoreboard->setMode(player->getScoreBoardPanel(), SCOREBOARD_MODE_ENTER_NAME);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_DYING:
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_DIED:
|
||||
{
|
||||
const int nextPlayerStatus = IsEligibleForHighScore(player->getScore()) ? PLAYER_STATUS_ENTERING_NAME : PLAYER_STATUS_CONTINUE;
|
||||
demo.enabled ? player->setStatusPlaying(PLAYER_STATUS_WAITING) : player->setStatusPlaying(nextPlayerStatus);
|
||||
// addScoreToScoreBoard(player->getName(), player->getScore());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool Game::IsEligibleForHighScore(int score)
|
||||
{
|
||||
return score > options.game.hiScoreTable.back().score;
|
||||
}
|
||||
|
||||
// Obtiene un jugador a partir de su "id"
|
||||
Player *Game::getPlayer(int id)
|
||||
{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "section.h" // for options_e
|
||||
#include "utils.h" // for demoKeys_t, color_t, hiScoreEntry_t
|
||||
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
#include "section.h" // for options_e
|
||||
#include "utils.h" // for demoKeys_t, color_t, hiScoreEntry_t
|
||||
class Asset;
|
||||
class Background;
|
||||
class Balloon;
|
||||
@@ -410,6 +410,9 @@ private:
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
bool allPlayersAreWaiting();
|
||||
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
bool allPlayersAreNotPlaying();
|
||||
|
||||
// Carga las animaciones
|
||||
void loadAnimations(std::string filePath, std::vector<std::string> *buffer);
|
||||
|
||||
@@ -434,6 +437,9 @@ private:
|
||||
// Añade una puntuación a la tabla de records
|
||||
void addScoreToScoreBoard(std::string name, int score);
|
||||
|
||||
// Comprueba si la puntuación entra en la tabla de mejores puntuaciones
|
||||
bool IsEligibleForHighScore(int score);
|
||||
|
||||
// Comprueba el estado de juego de los jugadores
|
||||
void checkPlayersStatusPlaying();
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "player.h"
|
||||
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "input.h" // for inputs_e
|
||||
#include "param.h" // for param
|
||||
#include "texture.h" // for Texture
|
||||
#include <SDL2/SDL_render.h> // for SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL...
|
||||
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||
#include <stdlib.h> // for rand
|
||||
#include <algorithm> // for max, min
|
||||
#include "animated_sprite.h" // for AnimatedSprite
|
||||
#include "input.h" // for inputs_e
|
||||
#include "param.h" // for param
|
||||
#include "texture.h" // for Texture
|
||||
|
||||
// Constructor
|
||||
Player::Player(int id, float x, int y, SDL_Rect *playArea, std::vector<Texture *> texture, std::vector<std::vector<std::string> *> animations)
|
||||
@@ -58,7 +58,7 @@ void Player::init()
|
||||
coffees = 0;
|
||||
input = true;
|
||||
continueTicks = 0;
|
||||
continueCounter = 9;
|
||||
continueCounter = 20;
|
||||
width = 30;
|
||||
height = 30;
|
||||
collider.r = 9;
|
||||
@@ -133,7 +133,7 @@ void Player::move()
|
||||
|
||||
powerSprite->setPosX(getPosX() - powerUpDespX);
|
||||
}
|
||||
else
|
||||
else if (isDying())
|
||||
{
|
||||
playerSprite->update();
|
||||
|
||||
@@ -147,6 +147,12 @@ void Player::move()
|
||||
// Rebota
|
||||
playerSprite->setVelX(-vx);
|
||||
}
|
||||
|
||||
// Si el cadaver abandona el area de juego por abajo
|
||||
if (playerSprite->getPosY() > param.game.playArea.rect.h)
|
||||
{
|
||||
setStatusPlaying(PLAYER_STATUS_DIED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +333,24 @@ bool Player::isWaiting()
|
||||
return statusPlaying == PLAYER_STATUS_WAITING;
|
||||
}
|
||||
|
||||
// Indica si el jugador está introduciendo su nombre
|
||||
bool Player::isEnteringName()
|
||||
{
|
||||
return statusPlaying == PLAYER_STATUS_ENTERING_NAME;
|
||||
}
|
||||
|
||||
// Indica si el jugador está muriendose
|
||||
bool Player::isDying()
|
||||
{
|
||||
return statusPlaying == PLAYER_STATUS_DYING;
|
||||
}
|
||||
|
||||
// Indica si el jugador ha terminado de morir
|
||||
bool Player::hasDied()
|
||||
{
|
||||
return statusPlaying == PLAYER_STATUS_DIED;
|
||||
}
|
||||
|
||||
// Establece el estado del jugador en el juego
|
||||
void Player::setStatusPlaying(int value)
|
||||
{
|
||||
@@ -340,18 +364,25 @@ void Player::setStatusPlaying(int value)
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_CONTINUE:
|
||||
// Activa la animación de morir
|
||||
playerSprite->setAccelY(0.2f);
|
||||
playerSprite->setVelY(-6.6f);
|
||||
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
|
||||
|
||||
// Inicializa el contador de continuar
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter = 9;
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_WAITING:
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_ENTERING_NAME:
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_DYING:
|
||||
// Activa la animación de morir
|
||||
playerSprite->setAccelY(0.2f);
|
||||
playerSprite->setVelY(-6.6f);
|
||||
rand() % 2 == 0 ? playerSprite->setVelX(3.3f) : playerSprite->setVelX(-3.3f);
|
||||
break;
|
||||
|
||||
case PLAYER_STATUS_DIED:
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -578,7 +609,6 @@ void Player::decContinueCounter()
|
||||
{
|
||||
continueTicks = SDL_GetTicks();
|
||||
continueCounter--;
|
||||
|
||||
if (continueCounter < 0)
|
||||
{
|
||||
setStatusPlaying(PLAYER_STATUS_WAITING);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for circle_t
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include "utils.h" // for circle_t
|
||||
class AnimatedSprite;
|
||||
class Texture;
|
||||
|
||||
@@ -21,6 +21,9 @@ class Texture;
|
||||
#define PLAYER_STATUS_PLAYING 0
|
||||
#define PLAYER_STATUS_CONTINUE 1
|
||||
#define PLAYER_STATUS_WAITING 2
|
||||
#define PLAYER_STATUS_ENTERING_NAME 3
|
||||
#define PLAYER_STATUS_DYING 4
|
||||
#define PLAYER_STATUS_DIED 5
|
||||
|
||||
// Variables del jugador
|
||||
#define PLAYER_INVULNERABLE_COUNTER 200
|
||||
@@ -149,6 +152,15 @@ public:
|
||||
// Indica si el jugador está esperando
|
||||
bool isWaiting();
|
||||
|
||||
// Indica si el jugador está introduciendo su nombre
|
||||
bool isEnteringName();
|
||||
|
||||
// Indica si el jugador está muriendose
|
||||
bool isDying();
|
||||
|
||||
// Indica si el jugador ha terminado de morir
|
||||
bool hasDied();
|
||||
|
||||
// Establece el estado del jugador en el juego
|
||||
void setStatusPlaying(int value);
|
||||
|
||||
|
||||
@@ -287,6 +287,10 @@ void Scoreboard::fillPanelTextures()
|
||||
textScoreBoard->writeCentered(slot4_4.x, slot4_4.y, std::to_string(continueCounter[i]));
|
||||
break;
|
||||
|
||||
case SCOREBOARD_MODE_ENTER_NAME:
|
||||
textScoreBoard->writeCentered(slot4_1.x, slot4_1.y, "ENTER NAME");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ enum scoreboard_modes_e
|
||||
SCOREBOARD_MODE_CONTINUE,
|
||||
SCOREBOARD_MODE_GAME_OVER,
|
||||
SCOREBOARD_MODE_DEMO,
|
||||
SCOREBOARD_MODE_ENTER_NAME,
|
||||
SCOREBOARD_MODE_NUM_MODES,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user