forked from jaildesigner-jailgames/jaildoctors_dilemma
El jugador ya cambia de pantalla
This commit is contained in:
BIN
media/player/player01.png
Normal file
BIN
media/player/player01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 222 B |
@@ -29,9 +29,9 @@ const int VIEW_HEIGHT = SCREEN_HEIGHT * 3;
|
|||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
const int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
const int PLAY_AREA_BOTTOM = GAMECANVAS_HEIGHT - (4 * BLOCK);
|
const int PLAY_AREA_BOTTOM = (16 * BLOCK);
|
||||||
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||||
const int PLAY_AREA_RIGHT = GAMECANVAS_WIDTH - (0 * BLOCK);
|
const int PLAY_AREA_RIGHT = (32 * BLOCK);
|
||||||
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||||
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||||
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||||
@@ -41,6 +41,11 @@ const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
|||||||
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
||||||
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
|
#define BORDER_TOP 0
|
||||||
|
#define BORDER_RIGHT 1
|
||||||
|
#define BORDER_BOTTOM 2
|
||||||
|
#define BORDER_LEFT 3
|
||||||
|
|
||||||
// Anclajes de pantalla
|
// Anclajes de pantalla
|
||||||
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
||||||
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ void Director::setFileList()
|
|||||||
mAsset->add("/data/room/02.room", room);
|
mAsset->add("/data/room/02.room", room);
|
||||||
mAsset->add("/media/tilesets/room1.png", bitmap);
|
mAsset->add("/media/tilesets/room1.png", bitmap);
|
||||||
mAsset->add("/media/enemies/enemy01.png", bitmap);
|
mAsset->add("/media/enemies/enemy01.png", bitmap);
|
||||||
|
mAsset->add("/media/player/player01.png", bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ Game::Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang,
|
|||||||
mLang = lang;
|
mLang = lang;
|
||||||
mInput = input;
|
mInput = input;
|
||||||
|
|
||||||
|
// Crea los objetos
|
||||||
mScreen = new Screen(window, renderer);
|
mScreen = new Screen(window, renderer);
|
||||||
mRoom = new Room(mAsset->get("01.room"), mRenderer, mAsset);
|
mRoom = new Room(mAsset->get("01.room"), mRenderer, mAsset);
|
||||||
|
mPlayer = new Player(mAsset->get("player01.png"), mRenderer, mAsset, mInput);
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
mTextureText = new LTexture();
|
mTextureText = new LTexture();
|
||||||
mText = new Text(mAsset->get("smb2.txt"), mTextureText, renderer);
|
mText = new Text(mAsset->get("smb2.txt"), mTextureText, renderer);
|
||||||
@@ -19,11 +21,13 @@ Game::Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang,
|
|||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
|
// Borra las referencias a los punteros
|
||||||
mRenderer = nullptr;
|
mRenderer = nullptr;
|
||||||
mAsset = nullptr;
|
mAsset = nullptr;
|
||||||
mLang = nullptr;
|
mLang = nullptr;
|
||||||
mInput = nullptr;
|
mInput = nullptr;
|
||||||
|
|
||||||
|
// Libera la memoria de los objetos
|
||||||
delete mEventHandler;
|
delete mEventHandler;
|
||||||
mEventHandler = nullptr;
|
mEventHandler = nullptr;
|
||||||
|
|
||||||
@@ -37,6 +41,9 @@ Game::~Game()
|
|||||||
delete mRoom;
|
delete mRoom;
|
||||||
mRoom = nullptr;
|
mRoom = nullptr;
|
||||||
|
|
||||||
|
delete mRoom;
|
||||||
|
mRoom = nullptr;
|
||||||
|
|
||||||
delete mText;
|
delete mText;
|
||||||
mText = nullptr;
|
mText = nullptr;
|
||||||
|
|
||||||
@@ -108,6 +115,8 @@ void Game::update()
|
|||||||
|
|
||||||
checkInput();
|
checkInput();
|
||||||
mRoom->update();
|
mRoom->update();
|
||||||
|
mPlayer->update();
|
||||||
|
checkPlayerOnBorder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +131,7 @@ void Game::draw()
|
|||||||
|
|
||||||
mRoom->drawMap();
|
mRoom->drawMap();
|
||||||
mRoom->drawEnemies();
|
mRoom->drawEnemies();
|
||||||
|
mPlayer->draw();
|
||||||
|
|
||||||
// Texto en el centro de la pantalla
|
// Texto en el centro de la pantalla
|
||||||
mText->writeCentered(GAMECANVAS_CENTER_X, 18 * 8, mRoom->getName());
|
mText->writeCentered(GAMECANVAS_CENTER_X, 18 * 8, mRoom->getName());
|
||||||
@@ -133,6 +143,7 @@ void Game::draw()
|
|||||||
// Comprueba la entrada
|
// Comprueba la entrada
|
||||||
void Game::checkInput()
|
void Game::checkInput()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
|
if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
|
||||||
changeRoom(mRoom->getRoomUp());
|
changeRoom(mRoom->getRoomUp());
|
||||||
|
|
||||||
@@ -144,6 +155,7 @@ void Game::checkInput()
|
|||||||
|
|
||||||
if (mInput->checkInput(INPUT_RIGHT, REPEAT_FALSE))
|
if (mInput->checkInput(INPUT_RIGHT, REPEAT_FALSE))
|
||||||
changeRoom(mRoom->getRoomRight());
|
changeRoom(mRoom->getRoomRight());
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia de habitación
|
// Cambia de habitación
|
||||||
@@ -168,3 +180,13 @@ bool Game::changeRoom(std::string file)
|
|||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si el jugador esta en el borde de la pantalla
|
||||||
|
void Game::checkPlayerOnBorder()
|
||||||
|
{
|
||||||
|
if (mPlayer->getOnBorder())
|
||||||
|
{
|
||||||
|
changeRoom(mRoom->getRoom(mPlayer->getBorder()));
|
||||||
|
mPlayer->switchBorders();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "ifdefs.h"
|
#include "ifdefs.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
@@ -14,6 +13,7 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
#include "player.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
@@ -27,6 +27,7 @@ private:
|
|||||||
SDL_Event *mEventHandler; // Manejador de eventos
|
SDL_Event *mEventHandler; // Manejador de eventos
|
||||||
Screen *mScreen; // Objeto encargado de manejar el renderizador
|
Screen *mScreen; // Objeto encargado de manejar el renderizador
|
||||||
Room *mRoom; // Objeto encargado de gestionar cada habitación del juego
|
Room *mRoom; // Objeto encargado de gestionar cada habitación del juego
|
||||||
|
Player *mPlayer; // Objeto con el jugador
|
||||||
Asset *mAsset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *mAsset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas
|
||||||
Input *mInput; // Objeto pata gestionar la entrada
|
Input *mInput; // Objeto pata gestionar la entrada
|
||||||
@@ -49,12 +50,15 @@ private:
|
|||||||
// Pinta los objetos en pantalla
|
// Pinta los objetos en pantalla
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
// Comprueba la entrada
|
// Comprueba la entrada y actua
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|
||||||
// Cambia de habitación
|
// Cambia de habitación
|
||||||
bool changeRoom(std::string file);
|
bool changeRoom(std::string file);
|
||||||
|
|
||||||
|
// Comprueba si el jugador esta en el borde de la pantalla y actua
|
||||||
|
void checkPlayerOnBorder();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input);
|
Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input);
|
||||||
|
|||||||
@@ -30,9 +30,12 @@ void MovingSprite::clear()
|
|||||||
|
|
||||||
mAngle = 0.0; // Angulo para dibujarlo
|
mAngle = 0.0; // Angulo para dibujarlo
|
||||||
mRotate = false; // Indica si ha de rotar
|
mRotate = false; // Indica si ha de rotar
|
||||||
|
mCenter = {0, 0}; // Centro de rotación
|
||||||
mRotateSpeed = 0; // Velocidad de giro
|
mRotateSpeed = 0; // Velocidad de giro
|
||||||
mRotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
mRotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
|
||||||
mCounter = 0; // Contador interno
|
mCounter = 0; // Contador interno
|
||||||
|
|
||||||
|
mFlip = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iniciador
|
// Iniciador
|
||||||
@@ -96,7 +99,7 @@ void MovingSprite::move()
|
|||||||
void MovingSprite::render()
|
void MovingSprite::render()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH, mAngle);
|
mTexture->render(mRenderer, (int)mPosX, (int)mPosY, &mSpriteClip, mZoomW, mZoomH, mAngle, &mCenter, mFlip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
@@ -284,3 +287,9 @@ void MovingSprite::switchRotate()
|
|||||||
{
|
{
|
||||||
mRotateAmount *= -1;
|
mRotateAmount *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void MovingSprite::setFlip(SDL_RendererFlip flip)
|
||||||
|
{
|
||||||
|
mFlip = flip;
|
||||||
|
}
|
||||||
@@ -21,11 +21,13 @@ protected:
|
|||||||
float mZoomW; // Zoom aplicado a la anchura
|
float mZoomW; // Zoom aplicado a la anchura
|
||||||
float mZoomH; // Zoom aplicado a la altura
|
float mZoomH; // Zoom aplicado a la altura
|
||||||
|
|
||||||
double mAngle; // Angulo para dibujarlo
|
double mAngle; // Angulo para dibujarlo
|
||||||
bool mRotate; // Indica si ha de rotar
|
bool mRotate; // Indica si ha de rotar
|
||||||
Uint16 mRotateSpeed; // Velocidad de giro
|
Uint16 mRotateSpeed; // Velocidad de giro
|
||||||
double mRotateAmount; // Cantidad de grados a girar en cada iteración
|
double mRotateAmount; // Cantidad de grados a girar en cada iteración
|
||||||
Uint16 mCounter; // Contador interno
|
Uint16 mCounter; // Contador interno
|
||||||
|
SDL_Point mCenter; // Centro de rotación
|
||||||
|
SDL_RendererFlip mFlip; // Indica como se voltea el sprite
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -132,6 +134,9 @@ public:
|
|||||||
|
|
||||||
// Cambia el sentido de la rotación
|
// Cambia el sentido de la rotación
|
||||||
void switchRotate();
|
void switchRotate();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setFlip(SDL_RendererFlip flip);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset)
|
Player::Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset, Input *_input)
|
||||||
{
|
{
|
||||||
// Obten punteros a objetos
|
// Obten punteros a objetos
|
||||||
asset = _asset;
|
asset = _asset;
|
||||||
renderer = _renderer;
|
renderer = _renderer;
|
||||||
|
input = _input;
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
texture = new LTexture();
|
texture = new LTexture();
|
||||||
@@ -18,6 +19,25 @@ Player::Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset)
|
|||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
color = stringToColor("white");
|
color = stringToColor("white");
|
||||||
|
onBorder = false;
|
||||||
|
border = BORDER_TOP;
|
||||||
|
|
||||||
|
sprite->setPosX(2 * 8);
|
||||||
|
sprite->setPosY(12 * 8);
|
||||||
|
sprite->setVelX(0);
|
||||||
|
sprite->setVelY(0);
|
||||||
|
sprite->setWidth(8);
|
||||||
|
sprite->setHeight(16);
|
||||||
|
sprite->setCurrentFrame(0);
|
||||||
|
sprite->setAnimationCounter(0);
|
||||||
|
sprite->setAnimationNumFrames(0, 4);
|
||||||
|
sprite->setAnimationSpeed(0, 5);
|
||||||
|
sprite->setAnimationLoop(0, true);
|
||||||
|
sprite->setAnimationFrames(0, 0, 8 * 0, 0, 8, 16);
|
||||||
|
sprite->setAnimationFrames(0, 1, 8 * 1, 0, 8, 16);
|
||||||
|
sprite->setAnimationFrames(0, 2, 8 * 2, 0, 8, 16);
|
||||||
|
sprite->setAnimationFrames(0, 3, 8 * 3, 0, 8, 16);
|
||||||
|
sprite->setSpriteClip(sprite->getAnimationClip(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -42,6 +62,100 @@ void Player::draw()
|
|||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void Player::update()
|
void Player::update()
|
||||||
{
|
{
|
||||||
|
checkInput();
|
||||||
sprite->update();
|
sprite->update();
|
||||||
sprite->animate(0);
|
// sprite->animate(0);
|
||||||
|
checkBorders();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba las entradas y modifica variables
|
||||||
|
void Player::checkInput()
|
||||||
|
{
|
||||||
|
// if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
|
||||||
|
// changeRoom(mRoom->getRoomUp());
|
||||||
|
//
|
||||||
|
// if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE))
|
||||||
|
// changeRoom(mRoom->getRoomDown());
|
||||||
|
|
||||||
|
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE))
|
||||||
|
{
|
||||||
|
sprite->setVelX(-VX);
|
||||||
|
sprite->animate(0);
|
||||||
|
sprite->setFlip(SDL_FLIP_HORIZONTAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE))
|
||||||
|
{
|
||||||
|
sprite->setVelX(VX);
|
||||||
|
sprite->animate(0);
|
||||||
|
sprite->setFlip(SDL_FLIP_NONE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprite->setVelX(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||||
|
bool Player::getOnBorder()
|
||||||
|
{
|
||||||
|
return onBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indica en cual de los cuatro bordes se encuentra
|
||||||
|
int Player::getBorder()
|
||||||
|
{
|
||||||
|
return border;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si se halla en alguno de los cuatro bordes
|
||||||
|
void Player::checkBorders()
|
||||||
|
{
|
||||||
|
if (sprite->getPosX() < PLAY_AREA_LEFT)
|
||||||
|
{
|
||||||
|
border = BORDER_LEFT;
|
||||||
|
onBorder = true;
|
||||||
|
}
|
||||||
|
else if (sprite->getPosX() > PLAY_AREA_RIGHT - sprite->getWidth())
|
||||||
|
{
|
||||||
|
border = BORDER_RIGHT;
|
||||||
|
onBorder = true;
|
||||||
|
}
|
||||||
|
else if (sprite->getPosY() < PLAY_AREA_TOP)
|
||||||
|
{
|
||||||
|
border = BORDER_TOP;
|
||||||
|
onBorder = true;
|
||||||
|
}
|
||||||
|
else if (sprite->getPosY() > PLAY_AREA_BOTTOM - sprite->getHeight())
|
||||||
|
{
|
||||||
|
border = BORDER_BOTTOM;
|
||||||
|
onBorder = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
onBorder = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
||||||
|
void Player::switchBorders()
|
||||||
|
{
|
||||||
|
if (border == BORDER_TOP)
|
||||||
|
{
|
||||||
|
sprite->setPosY(PLAY_AREA_BOTTOM - sprite->getHeight() - 1);
|
||||||
|
}
|
||||||
|
else if (border == BORDER_BOTTOM)
|
||||||
|
{
|
||||||
|
sprite->setPosY(PLAY_AREA_TOP + 1);
|
||||||
|
}
|
||||||
|
else if (border == BORDER_RIGHT)
|
||||||
|
{
|
||||||
|
sprite->setPosX(PLAY_AREA_LEFT + 1);
|
||||||
|
}
|
||||||
|
if (border == BORDER_LEFT)
|
||||||
|
{
|
||||||
|
sprite->setPosX(PLAY_AREA_RIGHT - sprite->getWidth() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
onBorder = false;
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,41 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
#include "ifdefs.h"
|
||||||
|
#include "const.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
#include "input.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|
||||||
|
#define VX 0.6
|
||||||
|
|
||||||
// Clase Player
|
// Clase Player
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
LTexture *texture; // Textura con los graficos del enemigo
|
LTexture *texture; // Textura con los graficos del enemigo
|
||||||
AnimatedSprite *sprite; // Sprite del enemigo
|
AnimatedSprite *sprite; // Sprite del enemigo
|
||||||
|
Input *input; // Objeto para gestyionar la entrada
|
||||||
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
color_t color; // Color del jugador
|
color_t color; // Color del jugador
|
||||||
|
|
||||||
|
bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||||
|
int border; // Indica en cual de los cuatro bordes se encuentra
|
||||||
|
|
||||||
|
// Comprueba las entradas y modifica variables
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
|
// Comprueba si se halla en alguno de los cuatro bordes
|
||||||
|
void checkBorders();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset);
|
Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset, Input *_input);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Player();
|
~Player();
|
||||||
@@ -32,6 +45,15 @@ public:
|
|||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||||
|
bool getOnBorder();
|
||||||
|
|
||||||
|
// Indica en cual de los cuatro bordes se encuentra
|
||||||
|
int getBorder();
|
||||||
|
|
||||||
|
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
||||||
|
void switchBorders();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -281,26 +281,29 @@ void Room::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||||
std::string Room::getRoomUp()
|
std::string Room::getRoom(int border)
|
||||||
{
|
{
|
||||||
return room_up;
|
switch (border)
|
||||||
}
|
{
|
||||||
|
case BORDER_TOP:
|
||||||
|
return room_up;
|
||||||
|
break;
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
case BORDER_BOTTOM:
|
||||||
std::string Room::getRoomDown()
|
return room_down;
|
||||||
{
|
break;
|
||||||
return room_down;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
case BORDER_RIGHT:
|
||||||
std::string Room::getRoomLeft()
|
return room_right;
|
||||||
{
|
break;
|
||||||
return room_left;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
case BORDER_LEFT:
|
||||||
std::string Room::getRoomRight()
|
return room_left;
|
||||||
{
|
break;
|
||||||
return room_right;
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
@@ -78,17 +78,9 @@ public:
|
|||||||
// Actualiza las variables y objetos de la habitación
|
// Actualiza las variables y objetos de la habitación
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||||
std::string getRoomUp();
|
std::string getRoom(int border);
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
|
||||||
std::string getRoomDown();
|
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
|
||||||
std::string getRoomLeft();
|
|
||||||
|
|
||||||
// Devuelve el valor de la variable
|
|
||||||
std::string getRoomRight();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user