added cpp files from coffee crisis
This commit is contained in:
130
source/main.cpp
Normal file
130
source/main.cpp
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
|
||||||
|
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
|
||||||
|
contiene funcionalidad adicional para crear animaciones. La clase text permite
|
||||||
|
dibujar letras de un png en pantalla a partir de una cadena de texto. La clase
|
||||||
|
menu permite crear una estructura con diferentes elementos, escribirlos en
|
||||||
|
pantalla y seleccionar uno de ellos.
|
||||||
|
|
||||||
|
A continuación tenemos las clases enfocadas a la lógica del juego, la clase player
|
||||||
|
contiene la información del jugador, la clase balloon la de los enemigos y la
|
||||||
|
clase bullet para las balas que dispara el jugador. La clase background es
|
||||||
|
muy simple y sirve para pintar el fondo de la pantalla. Por ultimo, la clase
|
||||||
|
gamedirector es la que realiza toda la lógica y se encarga de hacer interactuar
|
||||||
|
al resto de objetos entre si.
|
||||||
|
|
||||||
|
El objeto gamedirector tiene tres estados: titulo, juego y pausa. Segun su estado
|
||||||
|
el bucle que recorre es distinto. En el bucle juego, el objeto gamedirector
|
||||||
|
tiene un objeto jugador, un vector con los objetos globo y un vector con los
|
||||||
|
objetos bala. Se encarga de comprobar las entradas de teclado o gamepad para
|
||||||
|
cerrar la aplicacion, saltar al estado de pausa y para mover al jugador. Recorre
|
||||||
|
el vector de globos y de balas y si tienen algun tipo asignado las gestiona.
|
||||||
|
Comprueba las colisiones entre los globos y el jugador y entre las balas y los
|
||||||
|
globos. Tiene ademas un nivel de amenaza que calcula en funcion del numero de globos
|
||||||
|
en pantalla y que se va incrementando conforme aumenta la puntuación del jugador.
|
||||||
|
|
||||||
|
Los objetos globo tienen varios contadores para alternar de un estado a otro.
|
||||||
|
|
||||||
|
En los vectores que contienen objetos, se considera activos los objetos que tienen
|
||||||
|
un tipo asociado diferente a NO_KIND
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ifdefs.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include "const.h"
|
||||||
|
#include "gamedirector.h"
|
||||||
|
|
||||||
|
int main(int argc, char *args[])
|
||||||
|
{
|
||||||
|
// Inicia el generador de numeros aleatorios
|
||||||
|
srand(time(nullptr));
|
||||||
|
|
||||||
|
// Crea el objeto gameDirector
|
||||||
|
GameDirector *gameDirector = new GameDirector();
|
||||||
|
|
||||||
|
// 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())
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
printf("Failed to load media!\n");
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
455
source/menu.cpp
Normal file
455
source/menu.cpp
Normal file
@@ -0,0 +1,455 @@
|
|||||||
|
#include "ifdefs.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "menu.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Menu::Menu()
|
||||||
|
{
|
||||||
|
init("", 0, 0, 0, nullptr, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu::~Menu()
|
||||||
|
{
|
||||||
|
mRenderer = nullptr;
|
||||||
|
mText = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void Menu::init(std::string name, int x, int y, int backgroundType, LTexture *texture, SDL_Renderer *renderer, Text *text)
|
||||||
|
{
|
||||||
|
// Inicia variables
|
||||||
|
mName = name;
|
||||||
|
mSelector.index = 0;
|
||||||
|
mTotalItems = 0;
|
||||||
|
mItemSelected = MENU_NO_OPTION;
|
||||||
|
mVerticalPadding = 1;
|
||||||
|
mPosX = x;
|
||||||
|
mPosY = y;
|
||||||
|
mRectBG.rect.x = 0;
|
||||||
|
mRectBG.rect.y = 0;
|
||||||
|
mRectBG.rect.w = 0;
|
||||||
|
mRectBG.rect.h = 0;
|
||||||
|
mRectBG.r = 0;
|
||||||
|
mRectBG.g = 0;
|
||||||
|
mRectBG.b = 0;
|
||||||
|
mSelector.rect.x = 0;
|
||||||
|
mSelector.rect.y = 0;
|
||||||
|
mSelector.rect.w = 0;
|
||||||
|
mSelector.rect.h = 0;
|
||||||
|
mSelector.r = 0;
|
||||||
|
mSelector.g = 0;
|
||||||
|
mSelector.b = 0;
|
||||||
|
mSelector.a = 255;
|
||||||
|
mBackgroundType = backgroundType;
|
||||||
|
mText = text;
|
||||||
|
mRenderer = renderer;
|
||||||
|
mIsCentered = false;
|
||||||
|
mAreElementsCentered = false;
|
||||||
|
mCenter = x + ((SCREEN_WIDTH - x) / 2);
|
||||||
|
mWidestItem = 0;
|
||||||
|
|
||||||
|
// Selector
|
||||||
|
mSelector.origin = 0;
|
||||||
|
mSelector.target = 0;
|
||||||
|
mSelector.y = 0;
|
||||||
|
mSelector.numJumps = 4;
|
||||||
|
mSelector.despY = 0;
|
||||||
|
mSelector.moving = false;
|
||||||
|
|
||||||
|
// Sprite con los graficos del selector
|
||||||
|
//mSelectorSprite.setWidth(8);
|
||||||
|
//mSelectorSprite.setHeight(8);
|
||||||
|
//mSelectorSprite.setPosX(0);
|
||||||
|
//mSelectorSprite.setPosY(0);
|
||||||
|
//mSelectorSprite.setTexture(texture);
|
||||||
|
//mSelectorSprite.setRenderer(renderer);
|
||||||
|
//mSelectorSprite.setSpriteClip(0, 0, mSelectorSprite.getWidth(), mSelectorSprite.getHeight());
|
||||||
|
|
||||||
|
// Elementos del menu
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
mItem[i].label = "";
|
||||||
|
mItem[i].w = 0;
|
||||||
|
mItem[i].h = 0;
|
||||||
|
mItem[i].x = 0;
|
||||||
|
mItem[i].y = 0;
|
||||||
|
mItem[i].hPaddingUp = 0;
|
||||||
|
mItem[i].hPaddingDown = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
|
//moveSelectorSprite(mSelector.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el nombre del menu
|
||||||
|
std::string Menu::getName()
|
||||||
|
{
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 Menu::getItemSelected()
|
||||||
|
{
|
||||||
|
return mItemSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
|
/*void Menu::moveSelectorSprite(int pos)
|
||||||
|
{
|
||||||
|
mSelector.rect.y = mItem[pos].y - 1;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Actualiza la posicion y el estado del selector
|
||||||
|
void Menu::updateSelector()
|
||||||
|
{
|
||||||
|
if (mSelector.moving)
|
||||||
|
{
|
||||||
|
mSelector.y += mSelector.despY;
|
||||||
|
if (mSelector.despY > 0) // Va hacia abajo
|
||||||
|
{
|
||||||
|
if (mSelector.y > mSelector.target) // Ha llegado al destino
|
||||||
|
{
|
||||||
|
mSelector.origin = mSelector.y = mSelector.target;
|
||||||
|
mSelector.moving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mSelector.despY < 0) // Va hacia abajo
|
||||||
|
{
|
||||||
|
if (mSelector.y < mSelector.target) // Ha llegado al destino
|
||||||
|
{
|
||||||
|
mSelector.origin = mSelector.y = mSelector.target;
|
||||||
|
mSelector.moving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSelector.rect.y = int(mSelector.y) - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSelector.rect.y = int(mSelector.y) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el origen del selector
|
||||||
|
void Menu::setSelectorOrigin(int value)
|
||||||
|
{
|
||||||
|
mSelector.origin = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el destino del selector
|
||||||
|
void Menu::setSelectorTarget(int value)
|
||||||
|
{
|
||||||
|
mSelector.target = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coloca el selector en una posición específica
|
||||||
|
void Menu::setSelectorPos(Uint8 index)
|
||||||
|
{
|
||||||
|
if (index < mTotalItems)
|
||||||
|
{
|
||||||
|
mSelector.index = index;
|
||||||
|
mSelector.y = mSelector.origin = mSelector.target = mItem[mSelector.index].y;
|
||||||
|
mSelector.moving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la anchura del elemento más ancho del menu
|
||||||
|
Uint16 Menu::getWidestItem()
|
||||||
|
{
|
||||||
|
Uint16 result = 0;
|
||||||
|
|
||||||
|
// Obtenemos la anchura del item mas ancho
|
||||||
|
for (Uint8 i = 0; i < mTotalItems; i++)
|
||||||
|
{
|
||||||
|
if (mItem[i].w > result)
|
||||||
|
{
|
||||||
|
result = mItem[i].w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deja el menu apuntando al primer elemento
|
||||||
|
void Menu::reset()
|
||||||
|
{
|
||||||
|
mItemSelected = MENU_NO_OPTION;
|
||||||
|
mSelector.index = 0;
|
||||||
|
//moveSelectorSprite(mSelector.index);
|
||||||
|
mSelector.origin = mSelector.target = mSelector.y = mItem[0].y;
|
||||||
|
mSelector.moving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deja el menu sin elemento seleccionado
|
||||||
|
void Menu::deselectItem()
|
||||||
|
{
|
||||||
|
mItemSelected = MENU_NO_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
||||||
|
void Menu::reorganize()
|
||||||
|
{
|
||||||
|
setRectSize();
|
||||||
|
if (mIsCentered)
|
||||||
|
centerMenu(mCenter);
|
||||||
|
if (mAreElementsCentered)
|
||||||
|
centerMenuElements();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deja el menu apuntando al siguiente elemento
|
||||||
|
bool Menu::increaseSelectorIndex()
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
mSelector.y = mSelector.origin = mItem[mSelector.index].y;
|
||||||
|
|
||||||
|
if (mSelector.index < (mTotalItems - 1))
|
||||||
|
{
|
||||||
|
mSelector.index++;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSelector.target = mItem[mSelector.index].y;
|
||||||
|
mSelector.despY = (mSelector.target - mSelector.origin) / mSelector.numJumps;
|
||||||
|
mSelector.moving = true;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deja el menu apuntando al elemento anterior
|
||||||
|
bool Menu::decreaseSelectorIndex()
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
mSelector.y = mSelector.origin = mItem[mSelector.index].y;
|
||||||
|
|
||||||
|
if (mSelector.index > 0)
|
||||||
|
{
|
||||||
|
mSelector.index--;
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSelector.target = mItem[mSelector.index].y;
|
||||||
|
mSelector.despY = (mSelector.target - mSelector.origin) / mSelector.numJumps;
|
||||||
|
mSelector.moving = true;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
||||||
|
bool Menu::checkInput(Uint8 input)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
switch (input)
|
||||||
|
{
|
||||||
|
case INPUT_UP:
|
||||||
|
success = decreaseSelectorIndex();
|
||||||
|
//moveSelectorSprite(mSelector.index);
|
||||||
|
break;
|
||||||
|
case INPUT_DOWN:
|
||||||
|
success = increaseSelectorIndex();
|
||||||
|
//moveSelectorSprite(mSelector.index);
|
||||||
|
break;
|
||||||
|
case INPUT_ACCEPT:
|
||||||
|
mItemSelected = mSelector.index;
|
||||||
|
break;
|
||||||
|
case INPUT_CANCEL:
|
||||||
|
mItemSelected = mDefaultActionWhenCancel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la logica del menu
|
||||||
|
void Menu::update()
|
||||||
|
{
|
||||||
|
updateSelector();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta el menu en pantalla
|
||||||
|
void Menu::render()
|
||||||
|
{
|
||||||
|
// Rendereritza el fondo del menu
|
||||||
|
if (mBackgroundType == MENU_BACKGROUND_SOLID)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, mRectBG.a);
|
||||||
|
SDL_RenderFillRect(mRenderer, &mRectBG.rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderiza el rectangulo del selector
|
||||||
|
SDL_SetRenderDrawColor(mRenderer, mSelector.r, mSelector.g, mSelector.b, mSelector.a);
|
||||||
|
SDL_RenderFillRect(mRenderer, &mSelector.rect);
|
||||||
|
|
||||||
|
// Renderiza el sprite del selector
|
||||||
|
//mSelectorSprite.render();
|
||||||
|
|
||||||
|
// Renderitza el text
|
||||||
|
for (Uint8 i = 0; i < mTotalItems; i++)
|
||||||
|
{
|
||||||
|
if (i == mSelector.index)
|
||||||
|
{
|
||||||
|
mText->writeColored(mItem[i].x, mItem[i].y, mItem[i].label, mSelector.itemR, mSelector.itemG, mSelector.itemB);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mText->write(mItem[i].x, mItem[i].y, mItem[i].label, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el rectangulo de fondo del menu y el selector
|
||||||
|
void Menu::setRectSize()
|
||||||
|
{
|
||||||
|
Uint8 i = 0;
|
||||||
|
mRectBG.rect.w = 0;
|
||||||
|
mRectBG.rect.h = 0;
|
||||||
|
mSelector.rect.w = 0;
|
||||||
|
mSelector.rect.h = 0;
|
||||||
|
|
||||||
|
// Obtenemos la anchura del item mas ancho y la altura de la suma de alturas de los items
|
||||||
|
for (i = 0; i < mTotalItems; i++)
|
||||||
|
{
|
||||||
|
if (mItem[i].w > mRectBG.rect.w)
|
||||||
|
{
|
||||||
|
mRectBG.rect.w = mItem[i].w;
|
||||||
|
}
|
||||||
|
mRectBG.rect.h += mItem[i].h + mItem[i].hPaddingDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
// La anchura de la cadena más larga, mas un caracter, mas la anchura del sprite del selector
|
||||||
|
mRectBG.rect.w += (mText->getSize() * 1); // + mSelectorSprite.getWidth();
|
||||||
|
|
||||||
|
// La altura de la suma de los items mas un caracter y menos un pixel (porque el texto en realidad es de 7 pixeles)
|
||||||
|
mRectBG.rect.h += (mText->getSize() * 1) - 1;
|
||||||
|
|
||||||
|
// La posición X es la del menú menos la anchura del sprite del selector y menos medio caracter
|
||||||
|
mRectBG.rect.x = mPosX - (mText->getSize() / 2); // - mSelectorSprite.getWidth();
|
||||||
|
|
||||||
|
// La posición Y es la del menu menos la altura de medio caracter i el padding
|
||||||
|
mRectBG.rect.y = mPosY - (mText->getSize() / 2) - mVerticalPadding;
|
||||||
|
|
||||||
|
// Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo
|
||||||
|
mSelector.rect.h = (mText->getSize() * 1) + 1;
|
||||||
|
mSelector.rect.w = mRectBG.rect.w;
|
||||||
|
mSelector.rect.x = mRectBG.rect.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Menu::setTotalItems(int num)
|
||||||
|
{
|
||||||
|
mTotalItems = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el color del rectangulo de fondo
|
||||||
|
void Menu::setBackgroundColor(int r, int g, int b, int alpha)
|
||||||
|
{
|
||||||
|
mRectBG.r = r;
|
||||||
|
mRectBG.g = g;
|
||||||
|
mRectBG.b = b;
|
||||||
|
mRectBG.a = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el color del rectangulo del selector
|
||||||
|
void Menu::setSelectorColor(int r, int g, int b, int alpha)
|
||||||
|
{
|
||||||
|
mSelector.r = r;
|
||||||
|
mSelector.g = g;
|
||||||
|
mSelector.b = b;
|
||||||
|
mSelector.a = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el color del texto del selector
|
||||||
|
void Menu::setSelectorTextColor(int r, int g, int b)
|
||||||
|
{
|
||||||
|
mSelector.itemR = r;
|
||||||
|
mSelector.itemG = g;
|
||||||
|
mSelector.itemB = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Centra el menu respecto un punto
|
||||||
|
void Menu::centerMenu(int value)
|
||||||
|
{
|
||||||
|
mIsCentered = true;
|
||||||
|
mCenter = value;
|
||||||
|
|
||||||
|
// Actualiza el rectangulo de fondo para recalcular las dimensiones
|
||||||
|
setRectSize();
|
||||||
|
|
||||||
|
// Obten el acho del menu
|
||||||
|
mWidestItem = getWidestItem();
|
||||||
|
|
||||||
|
// Establece la nueva posición centrada en funcion del elemento más ancho
|
||||||
|
mPosX = (value) - (mWidestItem / 2);
|
||||||
|
|
||||||
|
// Reposiciona los elementos del menu
|
||||||
|
for (Uint8 i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
mItem[i].x = mPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalcula el rectangulo de fondo
|
||||||
|
setRectSize();
|
||||||
|
|
||||||
|
// Recoloca el selector
|
||||||
|
mSelector.origin = mSelector.target = mSelector.y = mItem[mSelector.index].y;
|
||||||
|
mSelector.moving = false;
|
||||||
|
//moveSelectorSprite(mSelector.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Centra los elementos del menu
|
||||||
|
void Menu::centerMenuElements()
|
||||||
|
{
|
||||||
|
mAreElementsCentered = true;
|
||||||
|
|
||||||
|
for (Uint8 i = 0; i < mTotalItems; i++)
|
||||||
|
{
|
||||||
|
//mItem[i].x = (mCenter - ((mText->lenght(mItem[i].label, 0)) / 2));
|
||||||
|
mItem[i].x = (mCenter - (mItem[i].w / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
|
//moveSelectorSprite(mSelector.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade un item al menu
|
||||||
|
void Menu::addItem(std::string text, const Uint8 hPaddingUp, const Uint8 hPaddingDown)
|
||||||
|
{
|
||||||
|
// Si es el primer item coge la posición y del propio menu
|
||||||
|
if (mTotalItems == 0)
|
||||||
|
{
|
||||||
|
mItem[mTotalItems].label = text;
|
||||||
|
mItem[mTotalItems].w = mText->lenght(mItem[mTotalItems].label, 0);
|
||||||
|
mItem[mTotalItems].h = mText->getSize() + (mVerticalPadding * 2);
|
||||||
|
mItem[mTotalItems].x = mPosX;
|
||||||
|
mItem[mTotalItems].y = mPosY;
|
||||||
|
mItem[mTotalItems].hPaddingUp = hPaddingUp;
|
||||||
|
mItem[mTotalItems].hPaddingDown = hPaddingDown;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// En caso contrario, coge la posición y a partir del elemento anterior
|
||||||
|
if (mTotalItems < 10)
|
||||||
|
{
|
||||||
|
mItem[mTotalItems].label = text;
|
||||||
|
mItem[mTotalItems].w = mText->lenght(mItem[mTotalItems].label, 0);
|
||||||
|
mItem[mTotalItems].h = mText->getSize() + (mVerticalPadding * 2);
|
||||||
|
mItem[mTotalItems].x = mPosX;
|
||||||
|
mItem[mTotalItems].y = mItem[mTotalItems - 1].y + mItem[mTotalItems - 1].h + mItem[mTotalItems - 1].hPaddingDown;
|
||||||
|
mItem[mTotalItems].hPaddingUp = hPaddingUp;
|
||||||
|
mItem[mTotalItems].hPaddingDown = hPaddingDown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTotalItems(mTotalItems + 1);
|
||||||
|
reorganize();
|
||||||
|
setSelectorPos(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el texto de un item
|
||||||
|
void Menu::setItemCaption(Uint8 index, std::string text)
|
||||||
|
{
|
||||||
|
mItem[index].label = text;
|
||||||
|
mItem[index].w = mText->lenght(mItem[index].label, 0);
|
||||||
|
reorganize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
||||||
|
void Menu::setDefaultActionWhenCancel(Uint8 item)
|
||||||
|
{
|
||||||
|
mDefaultActionWhenCancel = item;
|
||||||
|
}
|
||||||
190
source/menu.h
Normal file
190
source/menu.h
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
#ifndef MENU_H
|
||||||
|
#define MENU_H
|
||||||
|
|
||||||
|
// Clase menu
|
||||||
|
class Menu
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Menu();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Menu();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init(std::string name, int x, int y, int backgroundType, LTexture *texture, SDL_Renderer *renderer, Text *text);
|
||||||
|
|
||||||
|
// Obtiene el nombre del menu
|
||||||
|
std::string getName();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getItemSelected();
|
||||||
|
|
||||||
|
// Deja el menu apuntando al primer elemento
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
// Deja el menu sin elemento seleccionado
|
||||||
|
void deselectItem();
|
||||||
|
|
||||||
|
// Comprueba la entrada (teclado, gamepad) y actua en consecuencia
|
||||||
|
bool checkInput(Uint8 input);
|
||||||
|
|
||||||
|
// Actualiza la logica del menu
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Pinta el menu en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Establece el color del rectangulo de fondo
|
||||||
|
void setBackgroundColor(int r, int g, int b, int alpha);
|
||||||
|
|
||||||
|
// Establece el color del rectangulo del selector
|
||||||
|
void setSelectorColor(int r, int g, int b, int alpha);
|
||||||
|
|
||||||
|
// Establece el color del texto del selector
|
||||||
|
void setSelectorTextColor(int r, int g, int b);
|
||||||
|
|
||||||
|
// Centra el menu respecto a un punto
|
||||||
|
void centerMenu(int value);
|
||||||
|
|
||||||
|
// Centra los elementos del menu
|
||||||
|
void centerMenuElements();
|
||||||
|
|
||||||
|
// Añade un item al menu
|
||||||
|
void addItem(std::string text, const Uint8 hPaddingUp = 0, const Uint8 hPaddingDown = 0);
|
||||||
|
|
||||||
|
// Cambia el texto de un item
|
||||||
|
void setItemCaption(Uint8 index, std::string text);
|
||||||
|
|
||||||
|
// Establece el indice del item que se usará por defecto al cancelar el menu
|
||||||
|
void setDefaultActionWhenCancel(Uint8 item);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setTotalItems(int num);
|
||||||
|
|
||||||
|
// Establece el rectangulo de fondo del menu
|
||||||
|
void setRectSize();
|
||||||
|
|
||||||
|
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
||||||
|
void reorganize();
|
||||||
|
|
||||||
|
// Deja el menu apuntando al siguiente elemento
|
||||||
|
bool increaseSelectorIndex();
|
||||||
|
|
||||||
|
// Deja el menu apuntando al elemento anterior
|
||||||
|
bool decreaseSelectorIndex();
|
||||||
|
|
||||||
|
// Mueve el grafico del selector al elemento seleccionado
|
||||||
|
//void moveSelectorSprite(int pos);
|
||||||
|
|
||||||
|
// Actualiza la posicion y el estado del selector
|
||||||
|
void updateSelector();
|
||||||
|
|
||||||
|
// Establece el origen del selector
|
||||||
|
void setSelectorOrigin(int value);
|
||||||
|
|
||||||
|
// Establece el destino del selector
|
||||||
|
void setSelectorTarget(int value);
|
||||||
|
|
||||||
|
// Coloca el selector en una posición específica
|
||||||
|
void setSelectorPos(Uint8 index);
|
||||||
|
|
||||||
|
// Obtiene la anchura del elemento más ancho del menu
|
||||||
|
Uint16 getWidestItem();
|
||||||
|
|
||||||
|
// Posicion X/Y del texto del primer elemento del menu
|
||||||
|
int mPosX; // En esta posición se pinta la primera letra del primer elemento
|
||||||
|
int mPosY;
|
||||||
|
|
||||||
|
// Nombre del menu
|
||||||
|
std::string mName;
|
||||||
|
|
||||||
|
// Numero de items del menu
|
||||||
|
Uint8 mTotalItems;
|
||||||
|
|
||||||
|
// Item del menu que ha sido seleccionado
|
||||||
|
Uint8 mItemSelected;
|
||||||
|
|
||||||
|
// Item del menu seleccionado cuando se cancela el menu
|
||||||
|
Uint8 mDefaultActionWhenCancel;
|
||||||
|
|
||||||
|
// Espacio de separacion entre items
|
||||||
|
Uint8 mVerticalPadding;
|
||||||
|
|
||||||
|
// Tipo de fondo para el menu
|
||||||
|
Uint8 mBackgroundType;
|
||||||
|
|
||||||
|
// Sprite con los graficos del selector
|
||||||
|
//Sprite mSelectorSprite;
|
||||||
|
|
||||||
|
struct rectangle
|
||||||
|
{
|
||||||
|
SDL_Rect rect;
|
||||||
|
Uint8 r; // Rojo
|
||||||
|
Uint8 g; // Verde
|
||||||
|
Uint8 b; // Azul
|
||||||
|
Uint8 a; // Transparencia
|
||||||
|
};
|
||||||
|
|
||||||
|
rectangle mRectBG; // Rectangulo de fondo del menu
|
||||||
|
|
||||||
|
// Estructura para cada elemento del menu
|
||||||
|
struct item
|
||||||
|
{
|
||||||
|
std::string label;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
Uint8 w;
|
||||||
|
Uint8 h;
|
||||||
|
Uint8 hPaddingUp;
|
||||||
|
Uint8 hPaddingDown;
|
||||||
|
};
|
||||||
|
|
||||||
|
item mItem[10];
|
||||||
|
|
||||||
|
// Texto para poder escribir los items del menu
|
||||||
|
Text *mText;
|
||||||
|
|
||||||
|
// Puntero al renderizador de la ventana
|
||||||
|
SDL_Renderer *mRenderer;
|
||||||
|
|
||||||
|
// Variable para saber si el menu debe estar centrado respecto a un punto
|
||||||
|
bool mIsCentered;
|
||||||
|
|
||||||
|
// Centro del menu
|
||||||
|
int mCenter;
|
||||||
|
|
||||||
|
// Variable para saber si los elementos van centrados
|
||||||
|
bool mAreElementsCentered;
|
||||||
|
|
||||||
|
// Anchura del elemento más ancho
|
||||||
|
Uint16 mWidestItem;
|
||||||
|
|
||||||
|
struct selector
|
||||||
|
{
|
||||||
|
double origin; // Coordenada de origen
|
||||||
|
double target; // Coordenada de destino
|
||||||
|
double y; // Coordenada actual
|
||||||
|
Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino
|
||||||
|
double despY; // (target - origin) / numJumps
|
||||||
|
bool moving; // Indica si el selector está avanzando hacia el destino
|
||||||
|
Uint8 index; // Elemento del menu que tiene el foco
|
||||||
|
SDL_Rect rect;
|
||||||
|
Uint8 r; // Rojo
|
||||||
|
Uint8 g; // Verde
|
||||||
|
Uint8 b; // Azul
|
||||||
|
Uint8 a; // Transparencia
|
||||||
|
Uint8 itemR; // Rojo
|
||||||
|
Uint8 itemG; // Verde
|
||||||
|
Uint8 itemB; // Azul
|
||||||
|
};
|
||||||
|
|
||||||
|
selector mSelector;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
132
source/movingsprite.cpp
Normal file
132
source/movingsprite.cpp
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#include "const.h"
|
||||||
|
#include "movingsprite.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
MovingSprite::MovingSprite()
|
||||||
|
{
|
||||||
|
init(0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
MovingSprite::~MovingSprite()
|
||||||
|
{
|
||||||
|
init(0, 0, 0, 0, 0, 0, 0, 0, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iniciador
|
||||||
|
void MovingSprite::init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
// Establece el alto y el ancho del sprite
|
||||||
|
setWidth(w);
|
||||||
|
setHeight(h);
|
||||||
|
|
||||||
|
// Establece la posición X,Y del sprite
|
||||||
|
setPosX(x);
|
||||||
|
setPosY(y);
|
||||||
|
|
||||||
|
// Establece la velocidad X,Y del sprite
|
||||||
|
setVelX(velx);
|
||||||
|
setVelY(vely);
|
||||||
|
|
||||||
|
// Establece la aceleración X,Y del sprite
|
||||||
|
setAccelX(accelx);
|
||||||
|
setAccelY(accely);
|
||||||
|
|
||||||
|
// Establece la textura donde están los gráficos para el sprite
|
||||||
|
setTexture(texture);
|
||||||
|
|
||||||
|
// Establece el renderizador
|
||||||
|
setRenderer(renderer);
|
||||||
|
|
||||||
|
// Establece el rectangulo de donde coger la imagen
|
||||||
|
setSpriteClip(0, 0, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mueve el sprite
|
||||||
|
void MovingSprite::move()
|
||||||
|
{
|
||||||
|
mPosX += mVelX;
|
||||||
|
mPosY += mVelY;
|
||||||
|
|
||||||
|
mVelX += mAccelX;
|
||||||
|
mVelY += mAccelY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra el sprite por pantalla
|
||||||
|
void MovingSprite::render()
|
||||||
|
{
|
||||||
|
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
float MovingSprite::getPosX()
|
||||||
|
{
|
||||||
|
return mPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
float MovingSprite::getPosY()
|
||||||
|
{
|
||||||
|
return mPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
float MovingSprite::getVelX()
|
||||||
|
{
|
||||||
|
return mVelX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
float MovingSprite::getVelY()
|
||||||
|
{
|
||||||
|
return mVelY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
float MovingSprite::getAccelX()
|
||||||
|
{
|
||||||
|
return mAccelX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
float MovingSprite::getAccelY()
|
||||||
|
{
|
||||||
|
return mAccelY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setPosX(float x)
|
||||||
|
{
|
||||||
|
mPosX = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setPosY(float y)
|
||||||
|
{
|
||||||
|
mPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setVelX(float x)
|
||||||
|
{
|
||||||
|
mVelX = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setVelY(float y)
|
||||||
|
{
|
||||||
|
mVelY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setAccelX(float x)
|
||||||
|
{
|
||||||
|
mAccelX = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setAccelY(float y)
|
||||||
|
{
|
||||||
|
mAccelY = y;
|
||||||
|
}
|
||||||
77
source/movingsprite.h
Normal file
77
source/movingsprite.h
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ifdefs.h"
|
||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
|
#ifndef MOVINGSPRITE_H
|
||||||
|
#define MOVINGSPRITE_H
|
||||||
|
|
||||||
|
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||||
|
class MovingSprite : public Sprite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
MovingSprite();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~MovingSprite();
|
||||||
|
|
||||||
|
// Iniciador
|
||||||
|
void init(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Mueve el sprite
|
||||||
|
void move();
|
||||||
|
|
||||||
|
// Muestra el sprite por pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Velocidad
|
||||||
|
float mVelX;
|
||||||
|
float mVelY;
|
||||||
|
|
||||||
|
// Aceleración
|
||||||
|
float mAccelX;
|
||||||
|
float mAccelY;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
751
source/player.cpp
Normal file
751
source/player.cpp
Normal file
@@ -0,0 +1,751 @@
|
|||||||
|
#include "const.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Player::Player()
|
||||||
|
{
|
||||||
|
mSpriteLegs = new AnimatedSprite();
|
||||||
|
mSpriteBody = new AnimatedSprite();
|
||||||
|
init(0, 0, nullptr, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Player::~Player()
|
||||||
|
{
|
||||||
|
init(0, 0, nullptr, nullptr, nullptr);
|
||||||
|
mSpriteLegs = nullptr;
|
||||||
|
mSpriteBody = nullptr;
|
||||||
|
delete mSpriteLegs;
|
||||||
|
delete mSpriteBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iniciador
|
||||||
|
void Player::init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
// Inicializa variables de estado
|
||||||
|
mAlive = true;
|
||||||
|
mStatusWalking = PLAYER_STATUS_WALKING_STOP;
|
||||||
|
mStatusFiring = PLAYER_STATUS_FIRING_NO;
|
||||||
|
mInvulnerable = false;
|
||||||
|
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
|
||||||
|
mExtraHit = false;
|
||||||
|
|
||||||
|
// Establece la altura y el ancho del jugador
|
||||||
|
mWidth = 3 * BLOCK;
|
||||||
|
mHeight = 3 * BLOCK;
|
||||||
|
|
||||||
|
// Establece la posición inicial del jugador
|
||||||
|
mPosX = x;
|
||||||
|
mPosY = y;
|
||||||
|
|
||||||
|
// Establece el tamaño del circulo de colisión
|
||||||
|
mCollider.r = 7;
|
||||||
|
|
||||||
|
// Actualiza la posición del circulo de colisión
|
||||||
|
shiftColliders();
|
||||||
|
|
||||||
|
// Establece la velocidad inicial
|
||||||
|
mVelX = 0;
|
||||||
|
mVelY = 0;
|
||||||
|
|
||||||
|
// Establece la velocidad base
|
||||||
|
mBaseSpeed = 1.5;
|
||||||
|
|
||||||
|
// Establece el numero inicial de vidas
|
||||||
|
mStartingLives = 3;
|
||||||
|
mLives = mStartingLives;
|
||||||
|
|
||||||
|
// Establece la puntuación inicial
|
||||||
|
mScore = 0;
|
||||||
|
|
||||||
|
// Establece el multiplicador de puntos inicial
|
||||||
|
mScoreMultiplier = 1.0f;
|
||||||
|
|
||||||
|
// Inicia el contador para la cadencia de disparo
|
||||||
|
mCooldown = 10;
|
||||||
|
|
||||||
|
// Inicia el sprite
|
||||||
|
mSpriteLegs->init(textureLegs, renderer);
|
||||||
|
mSpriteBody->init(textureBody, renderer);
|
||||||
|
|
||||||
|
// Establece el alto y ancho del sprite
|
||||||
|
mSpriteLegs->setWidth(mWidth);
|
||||||
|
mSpriteLegs->setHeight(mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setWidth(mWidth);
|
||||||
|
mSpriteBody->setHeight(mHeight);
|
||||||
|
|
||||||
|
// Establece la posición del sprite
|
||||||
|
mSpriteLegs->setPosX(int(mPosX));
|
||||||
|
mSpriteLegs->setPosY(mPosY);
|
||||||
|
|
||||||
|
mSpriteBody->setPosX(int(mPosX));
|
||||||
|
mSpriteBody->setPosY(mPosY);
|
||||||
|
|
||||||
|
// Inicializa las variables para la animación
|
||||||
|
mSpriteLegs->setCurrentFrame(0);
|
||||||
|
mSpriteLegs->setAnimationCounter(0);
|
||||||
|
|
||||||
|
mSpriteBody->setCurrentFrame(0);
|
||||||
|
mSpriteBody->setAnimationCounter(0);
|
||||||
|
|
||||||
|
// Establece el numero de frames de cada animacion
|
||||||
|
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 4);
|
||||||
|
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 4);
|
||||||
|
mSpriteLegs->setAnimationNumFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 4);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 4);
|
||||||
|
mSpriteBody->setAnimationNumFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 4);
|
||||||
|
|
||||||
|
// Establece la velocidad de cada animación
|
||||||
|
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_STOP, 10);
|
||||||
|
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 5);
|
||||||
|
mSpriteLegs->setAnimationSpeed(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 5);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP, 10);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 5);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 10);
|
||||||
|
mSpriteBody->setAnimationSpeed(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 5);
|
||||||
|
|
||||||
|
// Establece si la animación se reproduce en bucle
|
||||||
|
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_STOP, true);
|
||||||
|
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_LEFT, true);
|
||||||
|
mSpriteLegs->setAnimationLoop(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, true);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, true);
|
||||||
|
mSpriteBody->setAnimationLoop(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, true);
|
||||||
|
|
||||||
|
// Establece los frames de cada animación
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 2, mWidth * 2, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_LEFT, 3, mWidth * 3, mHeight * 0, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 0, mWidth * 0, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 1, mWidth * 1, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 2, mWidth * 2, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_RIGHT, 3, mWidth * 3, mHeight * 1, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0, mWidth * 0, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 1, mWidth * 1, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 2, mWidth * 2, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteLegs->setAnimationFrames(PLAYER_ANIMATION_LEGS_WALKING_STOP, 3, mWidth * 3, mHeight * 2, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 0, mWidth * 0, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 1, mWidth * 1, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 2, mWidth * 2, mHeight * 0, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT, 3, mWidth * 3, mHeight * 0, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 0, mWidth * 0, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 1, mWidth * 1, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 2, mWidth * 2, mHeight * 1, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT, 3, mWidth * 3, mHeight * 1, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 0, mWidth * 0, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 1, mWidth * 1, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 2, mWidth * 2, mHeight * 2, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT, 3, mWidth * 3, mHeight * 2, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 0, mWidth * 0, mHeight * 3, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 1, mWidth * 1, mHeight * 3, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 2, mWidth * 2, mHeight * 3, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT, 3, mWidth * 3, mHeight * 3, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 0, mWidth * 0, mHeight * 4, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 1, mWidth * 1, mHeight * 4, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 2, mWidth * 2, mHeight * 4, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP, 3, mWidth * 3, mHeight * 4, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 0, mWidth * 0, mHeight * 5, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 1, mWidth * 1, mHeight * 5, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 2, mWidth * 2, mHeight * 5, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP, 3, mWidth * 3, mHeight * 5, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 6, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 6, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 6, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 6, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 0, mWidth * 0, mHeight * 7, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 1, mWidth * 1, mHeight * 7, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 2, mWidth * 2, mHeight * 7, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT, 3, mWidth * 3, mHeight * 7, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 8, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 8, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 8, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 8, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 0, mWidth * 0, mHeight * 9, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 1, mWidth * 1, mHeight * 9, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 2, mWidth * 2, mHeight * 9, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT, 3, mWidth * 3, mHeight * 9, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 0, mWidth * 0, mHeight * 10, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 1, mWidth * 1, mHeight * 10, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 2, mWidth * 2, mHeight * 10, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT, 3, mWidth * 3, mHeight * 10, mWidth, mHeight);
|
||||||
|
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 0, mWidth * 0, mHeight * 11, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 1, mWidth * 1, mHeight * 11, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 2, mWidth * 2, mHeight * 11, mWidth, mHeight);
|
||||||
|
mSpriteBody->setAnimationFrames(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT, 3, mWidth * 3, mHeight * 11, mWidth, mHeight);
|
||||||
|
|
||||||
|
// Selecciona un frame para pintar
|
||||||
|
mSpriteLegs->setSpriteClip(mSpriteLegs->getAnimationClip(PLAYER_ANIMATION_LEGS_WALKING_STOP, 0));
|
||||||
|
mSpriteBody->setSpriteClip(mSpriteBody->getAnimationClip(PLAYER_ANIMATION_BODY_WALKING_STOP, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actua en consecuencia de la entrada recibida
|
||||||
|
void Player::setInput(Uint8 input)
|
||||||
|
{
|
||||||
|
switch (input)
|
||||||
|
{
|
||||||
|
case INPUT_LEFT:
|
||||||
|
mVelX = -mBaseSpeed;
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setWalkingStatus(PLAYER_STATUS_WALKING_LEFT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_RIGHT:
|
||||||
|
mVelX = mBaseSpeed;
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setWalkingStatus(PLAYER_STATUS_WALKING_RIGHT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_FIRE_UP:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_UP);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_UP);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_FIRE_LEFT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_LEFT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_FIRE_RIGHT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_RIGHT);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mVelX = 0;
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setWalkingStatus(PLAYER_STATUS_WALKING_STOP);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mueve el jugador a la posición y animación que le corresponde
|
||||||
|
void Player::move()
|
||||||
|
{
|
||||||
|
if (isAlive())
|
||||||
|
{
|
||||||
|
// Mueve el jugador a derecha o izquierda
|
||||||
|
mPosX += mVelX;
|
||||||
|
|
||||||
|
// Si el jugador abandona el area de juego por los laterales
|
||||||
|
if ((mPosX < PLAY_AREA_LEFT) || (mPosX + mWidth > PLAY_AREA_RIGHT))
|
||||||
|
{
|
||||||
|
// Restaura su posición
|
||||||
|
mPosX -= mVelX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la posición del sprite
|
||||||
|
mSpriteLegs->setPosX(getPosX());
|
||||||
|
mSpriteLegs->setPosY(mPosY);
|
||||||
|
|
||||||
|
mSpriteBody->setPosX(getPosX());
|
||||||
|
mSpriteBody->setPosY(mPosY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta el jugador en pantalla
|
||||||
|
void Player::render()
|
||||||
|
{
|
||||||
|
if (isAlive())
|
||||||
|
{
|
||||||
|
if (mInvulnerable)
|
||||||
|
{
|
||||||
|
if ((mInvulnerableTimer % 10) > 4)
|
||||||
|
{
|
||||||
|
mSpriteLegs->render();
|
||||||
|
mSpriteBody->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteLegs->render();
|
||||||
|
mSpriteBody->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el estado del jugador cuando camina
|
||||||
|
void Player::setWalkingStatus(Uint8 status)
|
||||||
|
{
|
||||||
|
// Si cambiamos de estado, reiniciamos la animación
|
||||||
|
if (mStatusWalking != status)
|
||||||
|
{
|
||||||
|
mStatusWalking = status;
|
||||||
|
mSpriteLegs->setCurrentFrame(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el estado del jugador cuando dispara
|
||||||
|
void Player::setFiringStatus(Uint8 status)
|
||||||
|
{
|
||||||
|
// Si cambiamos de estado, reiniciamos la animación
|
||||||
|
if (mStatusFiring != status)
|
||||||
|
{
|
||||||
|
mStatusFiring = status;
|
||||||
|
mSpriteBody->setCurrentFrame(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la animación correspondiente al estado
|
||||||
|
void Player::setAnimation()
|
||||||
|
{
|
||||||
|
switch (mStatusWalking)
|
||||||
|
{
|
||||||
|
case PLAYER_STATUS_WALKING_LEFT:
|
||||||
|
mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_LEFT);
|
||||||
|
switch (mStatusFiring)
|
||||||
|
{
|
||||||
|
case PLAYER_STATUS_FIRING_UP:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_LEFT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_RIGHT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_NO:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_WALKING_RIGHT:
|
||||||
|
mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_RIGHT);
|
||||||
|
switch (mStatusFiring)
|
||||||
|
{
|
||||||
|
case PLAYER_STATUS_FIRING_UP:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_LEFT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_RIGHT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_NO:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_WALKING_STOP:
|
||||||
|
mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_STOP);
|
||||||
|
switch (mStatusFiring)
|
||||||
|
{
|
||||||
|
case PLAYER_STATUS_FIRING_UP:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_LEFT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_RIGHT:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_FIRING_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PLAYER_STATUS_FIRING_NO:
|
||||||
|
if (mExtraHit)
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP_EXTRA_HIT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mSpriteBody->animate(PLAYER_ANIMATION_BODY_WALKING_STOP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mSpriteLegs->animate(PLAYER_ANIMATION_LEGS_WALKING_STOP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int Player::getPosX()
|
||||||
|
{
|
||||||
|
return int(mPosX);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int Player::getPosY()
|
||||||
|
{
|
||||||
|
return mPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int Player::getWidth()
|
||||||
|
{
|
||||||
|
return mWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int Player::getHeight()
|
||||||
|
{
|
||||||
|
return mHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si el jugador puede disparar
|
||||||
|
bool Player::canFire()
|
||||||
|
{
|
||||||
|
// Si el contador a llegado a cero, podemos disparar. En caso contrario decrementamos el contador
|
||||||
|
if (mCooldown > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setFireCooldown(int time)
|
||||||
|
{
|
||||||
|
mCooldown = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void Player::updateCooldown()
|
||||||
|
{
|
||||||
|
if (mCooldown > 0)
|
||||||
|
{
|
||||||
|
--mCooldown;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setFiringStatus(PLAYER_STATUS_FIRING_NO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||||
|
void Player::update()
|
||||||
|
{
|
||||||
|
move();
|
||||||
|
setAnimation();
|
||||||
|
shiftColliders();
|
||||||
|
updateCooldown();
|
||||||
|
updateInvulnerableTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la puntuación del jugador
|
||||||
|
int Player::getScore()
|
||||||
|
{
|
||||||
|
return mScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asigna un valor a la puntuación del jugador
|
||||||
|
void Player::setScore(int score)
|
||||||
|
{
|
||||||
|
mScore = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Incrementa la puntuación del jugador
|
||||||
|
void Player::addScore(int score)
|
||||||
|
{
|
||||||
|
mScore += score;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Player::isAlive()
|
||||||
|
{
|
||||||
|
return mAlive;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setAlive(bool value)
|
||||||
|
{
|
||||||
|
mAlive = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
float Player::getScoreMultiplier()
|
||||||
|
{
|
||||||
|
return mScoreMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setScoreMultiplier(float value)
|
||||||
|
{
|
||||||
|
mScoreMultiplier = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aumenta el valor de la variable hasta un máximo
|
||||||
|
void Player::incScoreMultiplier()
|
||||||
|
{
|
||||||
|
if (mScoreMultiplier < 5.0f)
|
||||||
|
{
|
||||||
|
mScoreMultiplier += 0.1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decrementa el valor de la variable hasta un mínimo
|
||||||
|
void Player::decScoreMultiplier()
|
||||||
|
{
|
||||||
|
if (mScoreMultiplier > 1.0f)
|
||||||
|
{
|
||||||
|
mScoreMultiplier -= 0.1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Player::isInvulnerable()
|
||||||
|
{
|
||||||
|
return mInvulnerable;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setInvulnerable(bool value)
|
||||||
|
{
|
||||||
|
mInvulnerable = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Player::getInvulnerableTimer()
|
||||||
|
{
|
||||||
|
return mInvulnerableTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Player::setInvulnerableTimer(Uint16 value)
|
||||||
|
{
|
||||||
|
mInvulnerableTimer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void Player::updateInvulnerableTimer()
|
||||||
|
{
|
||||||
|
if (mInvulnerableTimer > 0)
|
||||||
|
{
|
||||||
|
--mInvulnerableTimer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mInvulnerable = false;
|
||||||
|
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Player::hasExtraHit()
|
||||||
|
{
|
||||||
|
return mExtraHit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Concede un toque extra al jugador
|
||||||
|
void Player::giveExtraHit()
|
||||||
|
{
|
||||||
|
mExtraHit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quita el toque extra al jugador
|
||||||
|
void Player::removeExtraHit()
|
||||||
|
{
|
||||||
|
mExtraHit = false;
|
||||||
|
mInvulnerable = true;
|
||||||
|
mInvulnerableTimer = PLAYER_INVULNERABLE_TIMER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el circulo de colisión
|
||||||
|
Circle &Player::getCollider()
|
||||||
|
{
|
||||||
|
return mCollider;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el circulo de colisión a la posición del jugador
|
||||||
|
void Player::shiftColliders()
|
||||||
|
{
|
||||||
|
mCollider.x = Uint16(mPosX + (mWidth / 2));
|
||||||
|
mCollider.y = mPosY + (mHeight / 2);
|
||||||
|
}
|
||||||
173
source/player.h
Normal file
173
source/player.h
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "struct.h"
|
||||||
|
#include "animatedsprite.h"
|
||||||
|
|
||||||
|
#ifndef PLAYER_H
|
||||||
|
#define PLAYER_H
|
||||||
|
|
||||||
|
// The player
|
||||||
|
class Player
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Player();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Player();
|
||||||
|
|
||||||
|
// Iniciador
|
||||||
|
void init(float x, int y, LTexture *textureLegs, LTexture *textureBody, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Actua en consecuencia de la entrada recibida
|
||||||
|
void setInput(Uint8 input);
|
||||||
|
|
||||||
|
// Mueve el jugador a la posición y animación que le corresponde
|
||||||
|
void move();
|
||||||
|
|
||||||
|
// Pinta el jugador en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Establece el estado del jugador
|
||||||
|
void setWalkingStatus(Uint8 status);
|
||||||
|
void setFiringStatus(Uint8 status);
|
||||||
|
|
||||||
|
// Establece la animación correspondiente al estado
|
||||||
|
void setAnimation();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getPosX();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getPosY();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getWidth();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getHeight();
|
||||||
|
|
||||||
|
// Indica si el jugador puede disparar
|
||||||
|
bool canFire();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setFireCooldown(int time);
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void updateCooldown();
|
||||||
|
|
||||||
|
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Obtiene la puntuación del jugador
|
||||||
|
int getScore();
|
||||||
|
|
||||||
|
// Asigna un valor a la puntuación del jugador
|
||||||
|
void setScore(int score);
|
||||||
|
|
||||||
|
// Incrementa la puntuación del jugador
|
||||||
|
void addScore(int score);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isAlive();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setAlive(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
float getScoreMultiplier();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setScoreMultiplier(float value);
|
||||||
|
|
||||||
|
// Aumenta el valor de la variable hasta un máximo
|
||||||
|
void incScoreMultiplier();
|
||||||
|
|
||||||
|
// Decrementa el valor de la variable hasta un mínimo
|
||||||
|
void decScoreMultiplier();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isInvulnerable();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setInvulnerable(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool getInvulnerableTimer();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setInvulnerableTimer(Uint16 value);
|
||||||
|
|
||||||
|
// Actualiza el valor de la variable
|
||||||
|
void updateInvulnerableTimer();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool hasExtraHit();
|
||||||
|
|
||||||
|
// Concede un toque extra al jugador
|
||||||
|
void giveExtraHit();
|
||||||
|
|
||||||
|
// Quita el toque extra al jugador
|
||||||
|
void removeExtraHit();
|
||||||
|
|
||||||
|
// 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
|
||||||
228
source/smartsprite.cpp
Normal file
228
source/smartsprite.cpp
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
#include "const.h"
|
||||||
|
#include "smartsprite.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
SmartSprite::SmartSprite()
|
||||||
|
{
|
||||||
|
init(nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
SmartSprite::~SmartSprite()
|
||||||
|
{
|
||||||
|
init(nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void SmartSprite::init(LTexture *texture, SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
setTexture(texture);
|
||||||
|
setRenderer(renderer);
|
||||||
|
|
||||||
|
setPosX(0);
|
||||||
|
setPosY(0);
|
||||||
|
setWidth(0);
|
||||||
|
setHeight(0);
|
||||||
|
|
||||||
|
setVelX(0);
|
||||||
|
setVelY(0);
|
||||||
|
setAccelX(0);
|
||||||
|
setAccelY(0);
|
||||||
|
|
||||||
|
setSpriteClip(0, 0, 0, 0);
|
||||||
|
|
||||||
|
setEnabled(false);
|
||||||
|
setEnabledTimer(0);
|
||||||
|
|
||||||
|
mIsOnDestination = false;
|
||||||
|
mDestX = 0;
|
||||||
|
mDestY = 0;
|
||||||
|
|
||||||
|
// El Id siempre es >=0, por lo tanto si no se le asigna Id se queda en negativo
|
||||||
|
mId = -1;
|
||||||
|
|
||||||
|
mIntroEvents = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pone a cero los elementos del objeto
|
||||||
|
void SmartSprite::erase()
|
||||||
|
{
|
||||||
|
init(nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool SmartSprite::isEnabled()
|
||||||
|
{
|
||||||
|
return mEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void SmartSprite::setEnabled(bool state)
|
||||||
|
{
|
||||||
|
mEnabled = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 SmartSprite::getEnabledTimer()
|
||||||
|
{
|
||||||
|
return mEnabledTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void SmartSprite::setEnabledTimer(Uint16 time)
|
||||||
|
{
|
||||||
|
mEnabledTimer = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void SmartSprite::setDestX(int value)
|
||||||
|
{
|
||||||
|
mDestX = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void SmartSprite::setDestY(int value)
|
||||||
|
{
|
||||||
|
mDestY = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int SmartSprite::getDestX()
|
||||||
|
{
|
||||||
|
return mDestX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int SmartSprite::getDestY()
|
||||||
|
{
|
||||||
|
return mDestY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||||
|
bool SmartSprite::update()
|
||||||
|
{
|
||||||
|
if (mEnabled)
|
||||||
|
{
|
||||||
|
move();
|
||||||
|
|
||||||
|
// Comprueba si se desplaza en el eje X hacia la derecha
|
||||||
|
if ((getAccelX() > 0) || ((getAccelX() == 0) && (getVelX() > 0)))
|
||||||
|
{
|
||||||
|
// Comprueba si hemos llegado al destino
|
||||||
|
if (getPosX() > mDestX)
|
||||||
|
{
|
||||||
|
// Lo coloca en posición
|
||||||
|
setPosX(mDestX);
|
||||||
|
|
||||||
|
// Lo detiene
|
||||||
|
setVelX(0.0f);
|
||||||
|
setAccelX(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si se desplaza en el eje X hacia la izquierda
|
||||||
|
else if ((getAccelX() < 0) || ((getAccelX() == 0) && (getVelX() < 0)))
|
||||||
|
{
|
||||||
|
// Comprueba si hemos llegado al destino
|
||||||
|
if (getPosX() < mDestX)
|
||||||
|
{
|
||||||
|
// Lo coloca en posición
|
||||||
|
setPosX(mDestX);
|
||||||
|
|
||||||
|
// Lo detiene
|
||||||
|
setVelX(0.0f);
|
||||||
|
setAccelX(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si se desplaza en el eje Y hacia abajo
|
||||||
|
if ((getAccelY() > 0) || ((getAccelY() == 0) && (getVelY() > 0)))
|
||||||
|
{
|
||||||
|
// Comprueba si hemos llegado al destino
|
||||||
|
if (getPosY() > mDestY)
|
||||||
|
{
|
||||||
|
// Lo coloca en posición
|
||||||
|
setPosY(mDestY);
|
||||||
|
|
||||||
|
// Lo detiene
|
||||||
|
setVelY(0.0f);
|
||||||
|
setAccelY(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Comprueba si se desplaza en el eje Y hacia arriba
|
||||||
|
else if ((getAccelY() < 0) || ((getAccelY() == 0) && (getVelY() < 0)))
|
||||||
|
{
|
||||||
|
// Comprueba si hemos llegado al destino
|
||||||
|
if (getPosY() < mDestY)
|
||||||
|
{
|
||||||
|
// Lo coloca en posición
|
||||||
|
setPosY(mDestY);
|
||||||
|
|
||||||
|
// Lo detiene
|
||||||
|
setVelY(0.0f);
|
||||||
|
setAccelY(0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha llegado a su destino
|
||||||
|
if ((getPosX() == mDestX) && (getPosY() == mDestY))
|
||||||
|
{
|
||||||
|
mIsOnDestination = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mIsOnDestination = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si esta en el destino comprueba su contador
|
||||||
|
if (mIsOnDestination)
|
||||||
|
{
|
||||||
|
// Si el contador es mayor que cero, lo decrementa
|
||||||
|
if (mEnabledTimer > 0)
|
||||||
|
{
|
||||||
|
--mEnabledTimer;
|
||||||
|
}
|
||||||
|
// Si ha llegado a cero, deshabilita el objeto o manda el aviso en función de si tiene Id
|
||||||
|
else if (mEnabledTimer == 0)
|
||||||
|
{
|
||||||
|
if (mId < 0)
|
||||||
|
{
|
||||||
|
mEnabled = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mIntroEvents[mId] = EVENT_COMPLETED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mIsOnDestination;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool SmartSprite::isOnDestination()
|
||||||
|
{
|
||||||
|
return mIsOnDestination;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta el objeto en pantalla
|
||||||
|
void SmartSprite::render()
|
||||||
|
{
|
||||||
|
if (mEnabled)
|
||||||
|
{
|
||||||
|
MovingSprite::render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void SmartSprite::setId(int id)
|
||||||
|
{
|
||||||
|
mId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void SmartSprite::setIntroEvents(Uint8 *value)
|
||||||
|
{
|
||||||
|
mIntroEvents = value;
|
||||||
|
}
|
||||||
84
source/smartsprite.h
Normal file
84
source/smartsprite.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "struct.h"
|
||||||
|
#include "animatedsprite.h"
|
||||||
|
|
||||||
|
#ifndef SMARTSPRITE_H
|
||||||
|
#define SMARTSPRITE_H
|
||||||
|
|
||||||
|
// Clase SmartSprite
|
||||||
|
class SmartSprite : public AnimatedSprite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
SmartSprite();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~SmartSprite();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init(LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Pone a cero los elementos del objeto
|
||||||
|
void erase();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isEnabled();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setEnabled(bool state);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 getEnabledTimer();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setEnabledTimer(Uint16 time);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setDestX(int value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setDestY(int value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getDestX();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
int getDestY();
|
||||||
|
|
||||||
|
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||||
|
bool update();
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool isOnDestination();
|
||||||
|
|
||||||
|
// Pinta el objeto en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setId(int id);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setIntroEvents(Uint8 *value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Indica si esta habilitado
|
||||||
|
bool mEnabled;
|
||||||
|
|
||||||
|
// Contador
|
||||||
|
Uint16 mEnabledTimer;
|
||||||
|
|
||||||
|
// Indica si está en el destino
|
||||||
|
bool mIsOnDestination;
|
||||||
|
|
||||||
|
// Posicion de destino
|
||||||
|
int mDestX;
|
||||||
|
int mDestY;
|
||||||
|
|
||||||
|
// Identificador
|
||||||
|
int mId;
|
||||||
|
|
||||||
|
// Dirección del array de eventos donde notificar el estado
|
||||||
|
Uint8 *mIntroEvents;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
149
source/sprite.cpp
Normal file
149
source/sprite.cpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Sprite::Sprite()
|
||||||
|
{
|
||||||
|
init(0, 0, 0, 0, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Sprite::~Sprite()
|
||||||
|
{
|
||||||
|
mTexture = nullptr;
|
||||||
|
mRenderer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void Sprite::init(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
// Establece el alto y el ancho del sprite
|
||||||
|
setWidth(w);
|
||||||
|
setHeight(h);
|
||||||
|
|
||||||
|
// Establece la posición X,Y del sprite
|
||||||
|
setPosX(x);
|
||||||
|
setPosY(y);
|
||||||
|
|
||||||
|
// Establece el puntero al renderizador de la ventana
|
||||||
|
setRenderer(renderer);
|
||||||
|
|
||||||
|
// Establece la textura donde están los gráficos para el sprite
|
||||||
|
setTexture(texture);
|
||||||
|
|
||||||
|
// Establece el rectangulo de donde coger la imagen
|
||||||
|
setSpriteClip(0, 0, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void Sprite::init(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
// Establece el alto y el ancho del sprite
|
||||||
|
mWidth = rect.w;
|
||||||
|
mHeight = rect.h;
|
||||||
|
|
||||||
|
// Establece la posición X,Y del sprite
|
||||||
|
mPosX = rect.x;
|
||||||
|
mPosY = rect.y;
|
||||||
|
|
||||||
|
// Establece el puntero al renderizador de la ventana
|
||||||
|
setRenderer(renderer);
|
||||||
|
|
||||||
|
// Establece la textura donde están los gráficos para el sprite
|
||||||
|
setTexture(texture);
|
||||||
|
|
||||||
|
// Establece el rectangulo de donde coger la imagen
|
||||||
|
setSpriteClip(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra el sprite por pantalla
|
||||||
|
void Sprite::render()
|
||||||
|
{
|
||||||
|
mTexture->render(mRenderer, mPosX, mPosY, &mSpriteClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int Sprite::getPosX()
|
||||||
|
{
|
||||||
|
return mPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int Sprite::getPosY()
|
||||||
|
{
|
||||||
|
return mPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int Sprite::getWidth()
|
||||||
|
{
|
||||||
|
return mWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int Sprite::getHeight()
|
||||||
|
{
|
||||||
|
return mHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setPosX(int x)
|
||||||
|
{
|
||||||
|
mPosX = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setPosY(int y)
|
||||||
|
{
|
||||||
|
mPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setWidth(int w)
|
||||||
|
{
|
||||||
|
mWidth = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setHeight(int h)
|
||||||
|
{
|
||||||
|
mHeight = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
SDL_Rect Sprite::getSpriteClip()
|
||||||
|
{
|
||||||
|
return mSpriteClip;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setSpriteClip(SDL_Rect rect)
|
||||||
|
{
|
||||||
|
mSpriteClip = rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setSpriteClip(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
mSpriteClip.x = x;
|
||||||
|
mSpriteClip.y = y;
|
||||||
|
mSpriteClip.w = w;
|
||||||
|
mSpriteClip.h = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
LTexture *Sprite::getTexture()
|
||||||
|
{
|
||||||
|
return mTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setTexture(LTexture *texture)
|
||||||
|
{
|
||||||
|
mTexture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Sprite::setRenderer(SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
mRenderer = renderer;
|
||||||
|
}
|
||||||
87
source/sprite.h
Normal file
87
source/sprite.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ifdefs.h"
|
||||||
|
#include "ltexture.h"
|
||||||
|
|
||||||
|
#ifndef SPRITE_H
|
||||||
|
#define SPRITE_H
|
||||||
|
|
||||||
|
// Clase sprite
|
||||||
|
class Sprite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Sprite();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Sprite();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init(int x, int y, int w, int h, LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
void init(SDL_Rect rect, LTexture *texture, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Muestra el sprite por pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int getPosX();
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int getPosY();
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int getWidth();
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
int getHeight();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setPosX(int x);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setPosY(int y);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setWidth(int w);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setHeight(int h);
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
SDL_Rect getSpriteClip();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setSpriteClip(SDL_Rect rect);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setSpriteClip(int x, int y, int w, int h);
|
||||||
|
|
||||||
|
// Obten el valor de la variable
|
||||||
|
LTexture* getTexture();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setTexture(LTexture *texture);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setRenderer(SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Posición X,Y donde dibujar el sprite
|
||||||
|
int mPosX;
|
||||||
|
int mPosY;
|
||||||
|
|
||||||
|
// Alto y ancho del sprite
|
||||||
|
Uint16 mWidth;
|
||||||
|
Uint16 mHeight;
|
||||||
|
|
||||||
|
// Puntero al renderizador de la ventana
|
||||||
|
SDL_Renderer *mRenderer;
|
||||||
|
|
||||||
|
// Textura donde estan todos los dibujos del sprite
|
||||||
|
LTexture *mTexture;
|
||||||
|
|
||||||
|
// Rectangulo de la textura que se dibujará en pantalla
|
||||||
|
SDL_Rect mSpriteClip;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
244
source/text.cpp
Normal file
244
source/text.cpp
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
#include "const.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Text::Text()
|
||||||
|
{
|
||||||
|
mSprite = new Sprite();
|
||||||
|
init(nullptr, nullptr, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Text::~Text()
|
||||||
|
{
|
||||||
|
delete mSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void Text::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
mType = type;
|
||||||
|
mSize = size;
|
||||||
|
|
||||||
|
// Inicia los valores del sprite que dibuja las letras
|
||||||
|
mSprite->setWidth(size);
|
||||||
|
mSprite->setHeight(size);
|
||||||
|
mSprite->setPosX(0);
|
||||||
|
mSprite->setPosY(0);
|
||||||
|
mSprite->setTexture(texture);
|
||||||
|
mSprite->setRenderer(renderer);
|
||||||
|
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
|
||||||
|
for (Uint8 i = 0; i < 255; i++)
|
||||||
|
{
|
||||||
|
mOffset[i].x = 0;
|
||||||
|
mOffset[i].y = 0;
|
||||||
|
mOffset[i].w = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece las coordenadas para cada caracter ascii de la cadena y su ancho
|
||||||
|
for (Uint8 i = 0; i < text.length(); ++i)
|
||||||
|
{
|
||||||
|
mOffset[int(text[i])].x = ((int(text[i]) - 32) % 15) * mSprite->getWidth();
|
||||||
|
mOffset[int(text[i])].y = ((int(text[i]) - 32) / 15) * mSprite->getHeight();
|
||||||
|
if (type == TEXT_FIXED)
|
||||||
|
{
|
||||||
|
mOffset[int(text[i])].w = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el ancho de cada caracter
|
||||||
|
if (type == TEXT_VARIABLE)
|
||||||
|
{
|
||||||
|
mOffset[int(' ')].w = 7;
|
||||||
|
mOffset[int('-')].w = 6;
|
||||||
|
mOffset[int('/')].w = 5;
|
||||||
|
mOffset[int('(')].w = 5;
|
||||||
|
mOffset[int(')')].w = 5;
|
||||||
|
mOffset[int('.')].w = 4;
|
||||||
|
mOffset[int(':')].w = 4;
|
||||||
|
mOffset[int('#')].w = 7;
|
||||||
|
mOffset[int('!')].w = 7;
|
||||||
|
mOffset[int('\'')].w = 3;
|
||||||
|
|
||||||
|
mOffset[int('0')].w = 7;
|
||||||
|
mOffset[int('1')].w = 5;
|
||||||
|
mOffset[int('2')].w = 7;
|
||||||
|
mOffset[int('3')].w = 7;
|
||||||
|
mOffset[int('4')].w = 7;
|
||||||
|
mOffset[int('5')].w = 7;
|
||||||
|
mOffset[int('6')].w = 7;
|
||||||
|
mOffset[int('7')].w = 7;
|
||||||
|
mOffset[int('8')].w = 7;
|
||||||
|
mOffset[int('9')].w = 7;
|
||||||
|
|
||||||
|
mOffset[int('A')].w = 7;
|
||||||
|
mOffset[int('B')].w = 7;
|
||||||
|
mOffset[int('C')].w = 7;
|
||||||
|
mOffset[int('D')].w = 7;
|
||||||
|
mOffset[int('E')].w = 7;
|
||||||
|
mOffset[int('F')].w = 7;
|
||||||
|
mOffset[int('G')].w = 7;
|
||||||
|
mOffset[int('H')].w = 7;
|
||||||
|
mOffset[int('I')].w = 4;
|
||||||
|
mOffset[int('J')].w = 6;
|
||||||
|
mOffset[int('K')].w = 8;
|
||||||
|
mOffset[int('L')].w = 6;
|
||||||
|
mOffset[int('M')].w = 9;
|
||||||
|
mOffset[int('N')].w = 8;
|
||||||
|
mOffset[int('O')].w = 8;
|
||||||
|
mOffset[int('P')].w = 7;
|
||||||
|
mOffset[int('Q')].w = 8;
|
||||||
|
mOffset[int('R')].w = 7;
|
||||||
|
mOffset[int('S')].w = 6;
|
||||||
|
mOffset[int('T')].w = 8;
|
||||||
|
mOffset[int('U')].w = 7;
|
||||||
|
mOffset[int('V')].w = 8;
|
||||||
|
mOffset[int('W')].w = 9;
|
||||||
|
mOffset[int('X')].w = 8;
|
||||||
|
mOffset[int('Y')].w = 8;
|
||||||
|
mOffset[int('Z')].w = 7;
|
||||||
|
|
||||||
|
mOffset[int('a')].w = 7;
|
||||||
|
mOffset[int('b')].w = 7;
|
||||||
|
mOffset[int('c')].w = 6;
|
||||||
|
mOffset[int('d')].w = 7;
|
||||||
|
mOffset[int('e')].w = 7;
|
||||||
|
mOffset[int('f')].w = 5;
|
||||||
|
mOffset[int('g')].w = 7;
|
||||||
|
mOffset[int('h')].w = 7;
|
||||||
|
mOffset[int('i')].w = 4;
|
||||||
|
mOffset[int('j')].w = 5;
|
||||||
|
mOffset[int('k')].w = 7;
|
||||||
|
mOffset[int('l')].w = 4;
|
||||||
|
mOffset[int('m')].w = 10;
|
||||||
|
mOffset[int('n')].w = 7;
|
||||||
|
mOffset[int('o')].w = 7;
|
||||||
|
mOffset[int('p')].w = 7;
|
||||||
|
mOffset[int('q')].w = 7;
|
||||||
|
mOffset[int('r')].w = 6;
|
||||||
|
mOffset[int('s')].w = 6;
|
||||||
|
mOffset[int('t')].w = 5;
|
||||||
|
mOffset[int('u')].w = 7;
|
||||||
|
mOffset[int('v')].w = 7;
|
||||||
|
mOffset[int('w')].w = 9;
|
||||||
|
mOffset[int('x')].w = 7;
|
||||||
|
mOffset[int('y')].w = 7;
|
||||||
|
mOffset[int('z')].w = 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto en pantalla
|
||||||
|
void Text::write(int x, int y, std::string text)
|
||||||
|
{
|
||||||
|
Uint16 shift = 0;
|
||||||
|
for (Uint8 i = 0; i < text.length(); ++i)
|
||||||
|
{
|
||||||
|
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
mSprite->setPosX(x + shift);
|
||||||
|
mSprite->setPosY(y);
|
||||||
|
mSprite->render();
|
||||||
|
shift += (mOffset[int(text[i])].w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto en pantalla con kerning
|
||||||
|
void Text::write(int x, int y, std::string text, int kerning)
|
||||||
|
{
|
||||||
|
Uint16 shift = 0;
|
||||||
|
for (Uint8 i = 0; i < text.length(); ++i)
|
||||||
|
{
|
||||||
|
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
mSprite->setPosX(x + shift);
|
||||||
|
mSprite->setPosY(y);
|
||||||
|
mSprite->render();
|
||||||
|
shift += (mOffset[int(text[i])].w + kerning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe una cantidad determinada de caracteres del texto en pantalla
|
||||||
|
void Text::write(int x, int y, std::string text, int kerning, Uint8 lenght)
|
||||||
|
{
|
||||||
|
Uint16 shift = 0;
|
||||||
|
for (Uint8 i = 0; i < lenght; ++i)
|
||||||
|
{
|
||||||
|
if (text[i] == '*')
|
||||||
|
{
|
||||||
|
shift = 0;
|
||||||
|
y += mSize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
mSprite->setPosX(x + shift);
|
||||||
|
mSprite->setPosY(y);
|
||||||
|
mSprite->render();
|
||||||
|
shift += (mOffset[int(text[i])].w + kerning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto con colores
|
||||||
|
void Text::writeColored(int x, int y, std::string text, Uint8 R, Uint8 G, Uint8 B)
|
||||||
|
{
|
||||||
|
mSprite->getTexture()->setColor(R, G, B);
|
||||||
|
write(x, y, text);
|
||||||
|
mSprite->getTexture()->setColor(255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto centrado en un punto x y con kerning
|
||||||
|
void Text::writeCentered(int x, int y, std::string text, int kerning)
|
||||||
|
{
|
||||||
|
// Uint16 lenght = Text::lenght(text, kerning);
|
||||||
|
x = x - (Text::lenght(text, kerning) / 2);
|
||||||
|
Uint16 shift = 0;
|
||||||
|
for (Uint8 i = 0; i < text.length(); ++i)
|
||||||
|
{
|
||||||
|
mSprite->setSpriteClip(mOffset[int(text[i])].x, mOffset[int(text[i])].y, mSprite->getWidth(), mSprite->getHeight());
|
||||||
|
mSprite->setPosX(x + shift);
|
||||||
|
mSprite->setPosY(y);
|
||||||
|
mSprite->render();
|
||||||
|
shift += (mOffset[int(text[i])].w + kerning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene la longitud en pixels de una cadena
|
||||||
|
Uint16 Text::lenght(std::string text, int kerning)
|
||||||
|
{
|
||||||
|
Uint16 shift = 0;
|
||||||
|
for (Uint8 i = 0; i < text.length(); ++i)
|
||||||
|
{
|
||||||
|
shift += (mOffset[int(text[i])].w + kerning);
|
||||||
|
}
|
||||||
|
return shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 Text::getType()
|
||||||
|
{
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text::setType(Uint8 type)
|
||||||
|
{
|
||||||
|
mType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 Text::getSize()
|
||||||
|
{
|
||||||
|
return mSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text::setSize(Uint8 size)
|
||||||
|
{
|
||||||
|
mSize = size;
|
||||||
|
}
|
||||||
66
source/text.h
Normal file
66
source/text.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "sprite.h"
|
||||||
|
|
||||||
|
#ifndef TEXT_H
|
||||||
|
#define TEXT_H
|
||||||
|
|
||||||
|
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||||
|
class Text
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Text();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Text();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size);
|
||||||
|
|
||||||
|
// Escribe el texto en pantalla
|
||||||
|
void write(int x, int y, std::string text);
|
||||||
|
void write(int x, int y, std::string text, int kerning);
|
||||||
|
void write(int x, int y, std::string text, int kerning, Uint8 lenght);
|
||||||
|
|
||||||
|
// Escribe el texto con colores
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Obtiene la longitud en pixels de una cadena
|
||||||
|
Uint16 lenght(std::string text, int kerning);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getType();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setType(Uint8 type);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint8 getSize();
|
||||||
|
|
||||||
|
// 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
|
||||||
158
source/text2.cpp
Normal file
158
source/text2.cpp
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
#include "const.h"
|
||||||
|
#include "text2.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Text2::Text2()
|
||||||
|
{
|
||||||
|
init(nullptr, nullptr, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Text2::~Text2()
|
||||||
|
{
|
||||||
|
init(nullptr, nullptr, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void Text2::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size)
|
||||||
|
{
|
||||||
|
Text::init(texture, renderer, type, size);
|
||||||
|
mPosX = 0;
|
||||||
|
mPosY = 0;
|
||||||
|
mKerning = 0;
|
||||||
|
mCaption = "";
|
||||||
|
mWrittingSpeed = 0;
|
||||||
|
mWrittingTimer = 0;
|
||||||
|
mIndex = 0;
|
||||||
|
mLenght = 0;
|
||||||
|
mWrittingCompleted = false;
|
||||||
|
mEnabled = false;
|
||||||
|
mEnabledTimer = 0;
|
||||||
|
mId = -1;
|
||||||
|
mIntroEvents = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setPosX(int value)
|
||||||
|
{
|
||||||
|
mPosX = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setPosY(int value)
|
||||||
|
{
|
||||||
|
mPosY = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setKerning(int value)
|
||||||
|
{
|
||||||
|
mKerning = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setCaption(std::string text)
|
||||||
|
{
|
||||||
|
mCaption = text;
|
||||||
|
mLenght = text.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setWrittingSpeed(Uint16 value)
|
||||||
|
{
|
||||||
|
mWrittingSpeed = value;
|
||||||
|
mWrittingTimer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setEnabled(bool value)
|
||||||
|
{
|
||||||
|
mEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Text2::IsEnabled()
|
||||||
|
{
|
||||||
|
return mEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setEnabledTimer(Uint16 value)
|
||||||
|
{
|
||||||
|
mEnabledTimer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 Text2::getEnabledTimer()
|
||||||
|
{
|
||||||
|
return mEnabledTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el objeto
|
||||||
|
void Text2::update()
|
||||||
|
{
|
||||||
|
if (mEnabled)
|
||||||
|
{
|
||||||
|
if (mWrittingCompleted == false)
|
||||||
|
{
|
||||||
|
if (mWrittingTimer > 0)
|
||||||
|
{
|
||||||
|
--mWrittingTimer;
|
||||||
|
}
|
||||||
|
if (mWrittingTimer == 0)
|
||||||
|
{
|
||||||
|
++mIndex;
|
||||||
|
mWrittingTimer = mWrittingSpeed;
|
||||||
|
}
|
||||||
|
if (mIndex == mLenght)
|
||||||
|
{
|
||||||
|
mWrittingCompleted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mWrittingCompleted)
|
||||||
|
{
|
||||||
|
if (mEnabledTimer > 0)
|
||||||
|
{
|
||||||
|
--mEnabledTimer;
|
||||||
|
}
|
||||||
|
else if (mEnabledTimer == 0)
|
||||||
|
{
|
||||||
|
if (mId < 0)
|
||||||
|
{
|
||||||
|
mEnabled = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mIntroEvents[mId] = EVENT_COMPLETED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el objeto en pantalla
|
||||||
|
void Text2::render()
|
||||||
|
{
|
||||||
|
if (mEnabled)
|
||||||
|
{
|
||||||
|
Text::write(mPosX, mPosY, mCaption, mKerning, mIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Centra la cadena de texto a un punto X
|
||||||
|
void Text2::center(int x)
|
||||||
|
{
|
||||||
|
setPosX(x - (lenght(mCaption, mKerning) / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setId(int id)
|
||||||
|
{
|
||||||
|
mId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Text2::setIntroEvents(Uint8 *value)
|
||||||
|
{
|
||||||
|
mIntroEvents = value;
|
||||||
|
}
|
||||||
102
source/text2.h
Normal file
102
source/text2.h
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
#ifndef TEXT2_H
|
||||||
|
#define TEXT2_H
|
||||||
|
|
||||||
|
// Clase texto. Pinta texto en pantalla a partir de un bitmap
|
||||||
|
class Text2 : public Text
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Text2();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Text2();
|
||||||
|
|
||||||
|
// Inicializador
|
||||||
|
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setPosX(int value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setPosY(int value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setKerning(int value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setCaption(std::string text);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setWrittingSpeed(Uint16 value);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setEnabled(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool IsEnabled();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setEnabledTimer(Uint16 value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
Uint16 getEnabledTimer();
|
||||||
|
|
||||||
|
// Actualiza el objeto
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja el objeto en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Centra la cadena de texto a un punto X
|
||||||
|
void center(int x);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setId(int id);
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setIntroEvents(Uint8 *value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Posicion X/Y donde empezar a escribir el texto
|
||||||
|
int mPosX;
|
||||||
|
int mPosY;
|
||||||
|
|
||||||
|
// Kerning del texto
|
||||||
|
int mKerning;
|
||||||
|
|
||||||
|
// Texto para escribir
|
||||||
|
std::string mCaption;
|
||||||
|
|
||||||
|
// Velocidad de escritura
|
||||||
|
Uint16 mWrittingSpeed;
|
||||||
|
|
||||||
|
// Temporizador de escritura para cada caracter
|
||||||
|
Uint16 mWrittingTimer;
|
||||||
|
|
||||||
|
// Posición del texto que se está escribiendo
|
||||||
|
Uint16 mIndex;
|
||||||
|
|
||||||
|
// Longitud de la cadena a escribir
|
||||||
|
Uint16 mLenght;
|
||||||
|
|
||||||
|
// Indica si se ha escrito todo el texto
|
||||||
|
bool mWrittingCompleted;
|
||||||
|
|
||||||
|
// Indica si el objeto está habilitado
|
||||||
|
bool mEnabled;
|
||||||
|
|
||||||
|
// Temporizador para deshabilitar el objeto
|
||||||
|
Uint16 mEnabledTimer;
|
||||||
|
|
||||||
|
// Identificador
|
||||||
|
int mId;
|
||||||
|
|
||||||
|
// Dirección del array de eventos donde notificar el estado
|
||||||
|
Uint8 *mIntroEvents;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
2704
source/volcano.pas
2704
source/volcano.pas
File diff suppressed because it is too large
Load Diff
12
sync.sh
12
sync.sh
@@ -1,4 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
readonly PROJECT=volcano
|
||||||
|
|
||||||
readonly USAGE="
|
readonly USAGE="
|
||||||
USAGE:
|
USAGE:
|
||||||
$(basename "$0") [UPLOAD or DOWNLOAD]"
|
$(basename "$0") [UPLOAD or DOWNLOAD]"
|
||||||
@@ -23,12 +25,12 @@ fi
|
|||||||
|
|
||||||
# UPLOAD
|
# UPLOAD
|
||||||
if [ "$1" = upload ] || [ "$1" = UPLOAD ]; then
|
if [ "$1" = upload ] || [ "$1" = UPLOAD ]; then
|
||||||
printf "\n%s\n" "uploading volcano"
|
printf "\n%s\n" "uploading $PROJECT"
|
||||||
rsync -azmPu --delete -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/volcano/
|
rsync -azmPu --delete -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/
|
||||||
rsync -azmPu -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/volcano.all/
|
rsync -azmPu -e 'ssh -p 4545' . sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT.all/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = download ] || [ "$1" = DOWNLOAD ]; then
|
if [ "$1" = download ] || [ "$1" = DOWNLOAD ]; then
|
||||||
printf "%s\n" "downloading volcano"
|
printf "%s\n" "downloading $PROJECT"
|
||||||
rsync -azmP --delete -e 'ssh -p 4545' sergio@sustancia.synology.me:/home/sergio/backup/code/volcano/* .
|
rsync -azmP --delete -e 'ssh -p 4545' sergio@sustancia.synology.me:/home/sergio/backup/code/$PROJECT/* .
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user