6 Commits
v0.2 ... v0.3

19 changed files with 518 additions and 45 deletions

View File

@@ -3,4 +3,4 @@ macos:
g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/volcano_macos g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/volcano_macos
linux: linux:
mkdir -p bin mkdir -p bin
g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/volcano_macos g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/volcano_linux

View File

@@ -11,11 +11,11 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,65,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 65,65,0,0,65,65,0,0,0,0,0,0,0,0,0,68,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,74,74,74,0,0,0,0, 0,49,0,0,0,0,0,47,0,0,0,0,0,77,74,76,0,0,0,0,
74,74,74,75,75,74,74,68,68,68,68,68,74,74,78,74,68,74,68,68 74,74,74,75,75,74,74,68,68,65,68,68,74,74,78,74,68,74,68,68
</data> </data>
</layer> </layer>
</map> </map>

BIN
media/font/debug.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 689 B

194
media/font/debug.txt Normal file
View File

@@ -0,0 +1,194 @@
# box width
5
# box height
5
# 32 espacio ( )
5
# 33 !
5
# 34 "
5
# 35 #
5
# 36 $
5
# 37 %
5
# 38 &
5
# 39 '
5
# 40 (
5
# 41 )
5
# 42 *
5
# 43 +
5
# 44 ,
5
# 45 -
5
# 46 .
5
# 47 /
5
# 48 0
5
# 49 1
5
# 50 2
5
# 51 3
5
# 52 4
5
# 53 5
5
# 54 6
5
# 55 7
5
# 56 8
5
# 57 9
5
# 58 :
5
# 59 ;
5
# 60 <
5
# 61 =
5
# 62 >
5
# 63 ?
5
# 64 @
5
# 65 A
5
# 66 B
5
# 67 C
5
# 68 D
5
# 69 E
5
# 70 F
5
# 71 G
5
# 72 H
5
# 73 I
5
# 74 J
5
# 75 K
5
# 76 L
5
# 77 M
5
# 78 N
5
# 79 O
5
# 80 P
5
# 81 Q
5
# 82 R
5
# 83 S
5
# 84 T
5
# 85 U
5
# 86 V
5
# 87 W
5
# 88 X
5
# 89 Y
5
# 90 Z
5
# 91 [
5
# 92 \
5
# 93 ]
5
# 94 ^
5
# 95 _
5
# 96 `
5
# 97 a
5
# 98 b
5
# 99 c
5
# 100 d
5
# 101 e
5
# 102 f
5
# 103 g
5
# 104 h
5
# 105 i
5
# 106 j
5
# 107 k
5
# 108 l
5
# 109 m
5
# 110 n
5
# 111 o
5
# 112 p
5
# 113 q
5
# 114 r
5
# 115 s
5
# 116 t
5
# 117 u
5
# 118 v
5
# 119 w
5
# 120 x
5
# 121 y
5
# 122 z
5
# 123 {
5
# 124 |
5
# 125 }
5
# 126 ~
5

View File

@@ -90,13 +90,13 @@ void AnimatedSprite::setAnimationLoop(std::string name, bool loop)
} }
// Establece el valor de la variable // Establece el valor de la variable
void AnimatedSprite::setCompleted(std::string name, bool value) void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
{ {
animation[getIndex(name)].completed = value; animation[getIndex(name)].completed = value;
} }
// Comprueba si ha terminado la animación // Comprueba si ha terminado la animación
bool AnimatedSprite::isCompleted(std::string name) bool AnimatedSprite::animationIsCompleted(std::string name)
{ {
return animation[getIndex(name)].completed; return animation[getIndex(name)].completed;
} }

View File

@@ -49,10 +49,10 @@ public:
void setAnimationLoop(std::string name, bool loop); void setAnimationLoop(std::string name, bool loop);
// Establece el valor de la variable // Establece el valor de la variable
void setCompleted(std::string name, bool value); void setAnimationCompleted(std::string name, bool value);
// Comprueba si ha terminado la animación // Comprueba si ha terminado la animación
bool isCompleted(std::string name); bool animationIsCompleted(std::string name);
// Devuelve el rectangulo de una animación y frame concreto // Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(std::string name, Uint8 index); SDL_Rect getAnimationClip(std::string name, Uint8 index);

View File

@@ -11,7 +11,8 @@ Game::Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input)
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
map = new Map(asset->get("01.map"), renderer, asset); map = new Map(asset->get("01.map"), renderer, asset);
player = new Player(renderer, asset, input); player = new Player(renderer, asset, input, map);
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
} }
// Destructor // Destructor
@@ -20,6 +21,7 @@ Game::~Game()
delete eventHandler; delete eventHandler;
delete map; delete map;
delete player; delete player;
delete debugText;
} }
// Bucle para el juego // Bucle para el juego
@@ -48,6 +50,8 @@ void Game::init()
section.name = SECTION_PROG_GAME; section.name = SECTION_PROG_GAME;
section.subsection = SUBSECTION_GAME_PLAY; section.subsection = SUBSECTION_GAME_PLAY;
debug = true;
} }
// Actualiza el juego, las variables, comprueba la entrada, etc. // Actualiza el juego, las variables, comprueba la entrada, etc.
@@ -71,6 +75,7 @@ void Game::update()
} }
player->update(); player->update();
checkInput();
} }
} }
@@ -84,7 +89,33 @@ void Game::render()
// Dibuja los objetos // Dibuja los objetos
map->render(); map->render();
player->render(); player->render();
renderDebugInfo();
// Actualiza la pantalla // Actualiza la pantalla
screen->blit(); screen->blit();
} }
// Comprueba la entrada
void Game::checkInput()
{
if (input->checkInput(INPUT_BUTTON_2, REPEAT_FALSE))
debug = !debug;
}
// Muestra información de depuración
void Game::renderDebugInfo()
{
if (!debug)
{
return;
}
int line = 0;
std::string text = "";
text = std::to_string((int)player->sprite->getPosX()) + "," + std::to_string((int)player->sprite->getPosY());
debugText->write(0, line, text, -1);
//text = std::to_string(player->checkMapCollisions());
//debugText->write(0, line+=6, text, -1);
}

View File

@@ -6,6 +6,7 @@
#include "input.h" #include "input.h"
#include "map.h" #include "map.h"
#include "player.h" #include "player.h"
#include "text.h"
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
@@ -18,11 +19,13 @@ private:
Screen *screen; // Objeto encargado de dibujar en pantalla Screen *screen; // Objeto encargado de dibujar en pantalla
Input *input; // Objeto Input para gestionar las entradas Input *input; // Objeto Input para gestionar las entradas
SDL_Event *eventHandler; // Manejador de eventos SDL_Event *eventHandler; // Manejador de eventos
Text *debugText; // Objeto para escribir texto con información de debug
section_t section; // Seccion actual dentro del programa section_t section; // Seccion actual dentro del programa
int ticks; // Contador de ticks para ajustar la velocidad del programa int ticks; // Contador de ticks para ajustar la velocidad del programa
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Map *map; // Objeto encargado de gestionar el mapeado del juego Map *map; // Objeto encargado de gestionar el mapeado del juego
Player *player; // Objeto para gestionar el jugador Player *player; // Objeto para gestionar el jugador
bool debug; // Indica si esta activo el modo de depuración
// Actualiza el juego, las variables, comprueba la entrada, etc. // Actualiza el juego, las variables, comprueba la entrada, etc.
void update(); void update();
@@ -33,6 +36,12 @@ private:
// Inicializa las variables necesarias para la sección 'Game' // Inicializa las variables necesarias para la sección 'Game'
void init(); void init();
// Comprueba la entrada
void checkInput();
// Muestra información de depuración
void renderDebugInfo();
public: public:
// Constructor // Constructor
Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input); Game(SDL_Renderer *renderer, Asset *asset, Screen *screen, Input *input);

View File

@@ -21,6 +21,11 @@ Map::Map(std::string file, SDL_Renderer *renderer, Asset *asset)
// Pinta el mapa de la habitación en la textura // Pinta el mapa de la habitación en la textura
fillMapTexture(); fillMapTexture();
// Inicializa variables
tile_width = 16;
map_width = 20;
map_height = 13;
} }
// Destructor // Destructor
@@ -181,11 +186,11 @@ void Map::fillMapTexture()
{ {
SDL_SetRenderTarget(renderer, map_texture); SDL_SetRenderTarget(renderer, map_texture);
SDL_SetTextureBlendMode(map_texture, SDL_BLENDMODE_BLEND); SDL_SetTextureBlendMode(map_texture, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
// Dibuja la textura de fondo // Dibuja la textura de fondo
SDL_Rect clip = {0, 0, 320, 240-32}; SDL_Rect clip = {0, 0, 320, 208};
texture_bg->render(renderer, 0, 0, &clip); texture_bg->render(renderer, 0, 0, &clip);
// Dibuja el mapeado de tiles // Dibuja el mapeado de tiles
@@ -204,6 +209,22 @@ void Map::fillMapTexture()
texture_tile->render(renderer, x * tile_size, y * tile_size, &clip); texture_tile->render(renderer, x * tile_size, y * tile_size, &clip);
} }
// Dibuja el degradado del marcador
int color = 105;
for (int i = 208; i < 240; i++)
{
SDL_SetRenderDrawColor(renderer, 0x69, color, 0x69, 0xFF);
SDL_RenderDrawLine(renderer, 0, i, 320, i);
color--;
}
// Dibuja el marco del marcador
SDL_SetRenderDrawColor(renderer, 85, 50, 85, 0xFF);
SDL_Rect rect = {0, 208, 320, 32};
SDL_RenderDrawRect(renderer, &rect);
rect = {1, 209, 318, 30};
SDL_RenderDrawRect(renderer, &rect);
SDL_SetRenderTarget(renderer, nullptr); SDL_SetRenderTarget(renderer, nullptr);
} }
@@ -214,3 +235,23 @@ void Map::render()
SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT}; SDL_Rect rect = {0, 0, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT};
SDL_RenderCopy(renderer, map_texture, &rect, NULL); SDL_RenderCopy(renderer, map_texture, &rect, NULL);
} }
// Devuelve el tipo de tile que hay en un punto
t_tile_map Map::getTile(SDL_Point p)
{
const int tile = tilemap[((p.y / tile_width) * map_width) + (p.x / tile_width)];
const int png_width = 16;
if (tile >= 0 && tile < 4 * png_width)
{
return nothing;
}
else if (tile >= (4 * png_width) && tile < 8 * png_width)
{
return wall;
}
else
{
return travessable;
}
}

View File

@@ -12,6 +12,13 @@
#ifndef MAP_H #ifndef MAP_H
#define MAP_H #define MAP_H
enum t_tile_map
{
nothing,
wall,
travessable
};
// The player // The player
class Map class Map
{ {
@@ -29,6 +36,10 @@ private:
LTexture *texture_bg; // Textura con los graficos de fondo de la habitación LTexture *texture_bg; // Textura con los graficos de fondo de la habitación
SDL_Texture *map_texture; // Textura para dibujar el mapa de la habitación SDL_Texture *map_texture; // Textura para dibujar el mapa de la habitación
int tile_width; // Ancho del tile en pixels
int map_width; // Ancho del mapa en tiles
int map_height; // Alto del mapa en tiles
// Carga las variables desde un fichero // Carga las variables desde un fichero
bool load(std::string file); bool load(std::string file);
@@ -50,6 +61,9 @@ public:
// Dibuja el objeto // Dibuja el objeto
void render(); void render();
// Devuelve el tipo de tile que hay en un punto
t_tile_map getTile(SDL_Point p);
}; };
#endif #endif

View File

@@ -15,6 +15,8 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
// Establece la posición X,Y del sprite // Establece la posición X,Y del sprite
setPosX(x); setPosX(x);
setPosY(y); setPosY(y);
mPosXPrev = x;
mPosYPrev = y;
// Establece la velocidad X,Y del sprite // Establece la velocidad X,Y del sprite
setVelX(velx); setVelX(velx);
@@ -43,7 +45,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
setSpriteClip(0, 0, w, h); setSpriteClip(0, 0, w, h);
// Establece el centro de rotación // Establece el centro de rotación
mCenter = {0,0}; mCenter = {0, 0};
// Establece el tipo de volteado // Establece el tipo de volteado
mFlip = SDL_FLIP_NONE; mFlip = SDL_FLIP_NONE;
@@ -84,6 +86,9 @@ void MovingSprite::move()
{ {
if (mEnabled) if (mEnabled)
{ {
mPosXPrev = mPosX;
mPosYPrev = mPosY;
mPosX += mVelX; mPosX += mVelX;
mPosY += mVelY; mPosY += mVelY;
@@ -153,6 +158,13 @@ double MovingSprite::getAngle()
return mAngle; return mAngle;
} }
// Establece la posición del objeto
void MovingSprite::setPos(SDL_Rect rect)
{
mPosX = (float)rect.x;
mPosY = (float)rect.y;
}
// Establece el valor de la variable // Establece el valor de la variable
void MovingSprite::setPosX(float x) void MovingSprite::setPosX(float x)
{ {
@@ -303,3 +315,28 @@ SDL_Rect MovingSprite::getRect()
SDL_Rect rect = {(int)getPosX(), (int)getPosY(), getWidth(), getHeight()}; SDL_Rect rect = {(int)getPosX(), (int)getPosY(), getWidth(), getHeight()};
return rect; return rect;
} }
// Deshace el último movimiento
void MovingSprite::undoMove()
{
mPosX = mPosXPrev;
mPosY = mPosYPrev;
}
// Deshace el último movimiento en el eje X
void MovingSprite::undoMoveX()
{
mPosX = mPosXPrev;
}
// Deshace el último movimiento en el eje Y
void MovingSprite::undoMoveY()
{
mPosY = mPosYPrev;
}
// Pone a cero las velocidades de desplacamiento
void MovingSprite::clearVel()
{
mVelX = mVelY = 0;
}

View File

@@ -12,6 +12,9 @@ protected:
float mPosX; // Posición en el eje X float mPosX; // Posición en el eje X
float mPosY; // Posición en el eje Y float mPosY; // Posición en el eje Y
float mPosXPrev; // Posición anterior en el eje X
float mPosYPrev; // Posición anterior en el eje Y
float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse float mVelX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse float mVelY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
@@ -84,6 +87,9 @@ public:
// Obtiene el valor de la variable // Obtiene el valor de la variable
Uint16 getRotateSpeed(); Uint16 getRotateSpeed();
// Establece la posición del objeto
void setPos(SDL_Rect rect);
// Establece el valor de la variable // Establece el valor de la variable
void setPosX(float x); void setPosX(float x);
@@ -140,6 +146,18 @@ public:
// Devuelve el rectangulo donde está el sprite // Devuelve el rectangulo donde está el sprite
SDL_Rect getRect(); SDL_Rect getRect();
// Deshace el último movimiento
void undoMove();
// Deshace el último movimiento en el eje X
void undoMoveX();
// Deshace el último movimiento en el eje Y
void undoMoveY();
// Pone a cero las velocidades de desplacamiento
void clearVel();
}; };
#endif #endif

View File

@@ -1,11 +1,12 @@
#include "player.h" #include "player.h"
// Constructor // Constructor
Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input) Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map)
{ {
this->asset = asset; this->asset = asset;
this->renderer = renderer; this->renderer = renderer;
this->input = input; this->input = input;
this->map = map;
sound_jump = JA_LoadSound(asset->get("sound_player_jump.wav").c_str()); sound_jump = JA_LoadSound(asset->get("sound_player_jump.wav").c_str());
sound_death = JA_LoadSound(asset->get("sound_player_death.wav").c_str()); sound_death = JA_LoadSound(asset->get("sound_player_death.wav").c_str());
@@ -15,10 +16,17 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input)
loadTextureFromFile(texture, asset->get("player.png"), renderer); loadTextureFromFile(texture, asset->get("player.png"), renderer);
sprite = new AnimatedSprite(texture, renderer, asset->get("player.ani")); sprite = new AnimatedSprite(texture, renderer, asset->get("player.ani"));
sprite->setPosX(16);
sprite->setPosY(168);
sprite->setCurrentAnimation("stand");
x = 3 * 16;
y = 40;
vx = 0;
vy = 0;
const SDL_Rect rect = {(int)x, (int)y, 16, 24};
sprite->setPos(rect);
sprite->setCurrentAnimation("stand");
sprite->setFlip(SDL_FLIP_HORIZONTAL);
gravity = 0.3f;
can_jump = true; can_jump = true;
standing = true; standing = true;
invulnerable = true; invulnerable = true;
@@ -28,6 +36,8 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input)
lifes = 10; lifes = 10;
coins = 0; coins = 0;
key.insert(key.end(), {0, 0, 0, 0, 0, 0}); key.insert(key.end(), {0, 0, 0, 0, 0, 0});
const SDL_Point p = {0, 0};
collider.insert(collider.end(), {p, p, p, p, p, p});
} }
// Destructor // Destructor
@@ -47,7 +57,8 @@ Player::~Player()
void Player::update() void Player::update()
{ {
checkInput(); checkInput();
sprite->update(); addGravity();
move();
} }
// Dibuja el objeto // Dibuja el objeto
@@ -63,19 +74,96 @@ void Player::checkInput()
// Solo comprueba las entradas de dirección cuando está de pie // Solo comprueba las entradas de dirección cuando está de pie
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE)) if (input->checkInput(INPUT_LEFT, REPEAT_TRUE))
{ {
sprite->setVelX(-speed); vx = -speed;
sprite->setFlip(SDL_FLIP_NONE); sprite->setFlip(SDL_FLIP_NONE);
sprite->setCurrentAnimation("walk"); sprite->setCurrentAnimation("walk");
} }
else if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE)) else if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE))
{ {
sprite->setVelX(speed); vx = speed;
sprite->setFlip(SDL_FLIP_HORIZONTAL); sprite->setFlip(SDL_FLIP_HORIZONTAL);
sprite->setCurrentAnimation("walk"); sprite->setCurrentAnimation("walk");
} }
else else
{ {
sprite->setVelX(0); vx = 0;
sprite->setCurrentAnimation("stand"); sprite->setCurrentAnimation("stand");
} }
if (input->checkInput(INPUT_UP, REPEAT_FALSE))
{
vy = -5.0f;
}
}
// Aplica la gravedad
void Player::addGravity()
{
vy = std::min(vy += gravity, 2.0f);
}
// Actualiza los puntos de colisión
void Player::updateColliders()
{
const SDL_Point p = {(int)x, (int)y};
collider[0] = p;
collider[1] = {p.x, p.y + 12};
collider[2] = {p.x, p.y + 23};
collider[3] = {p.x + 15, p.y};
collider[4] = {p.x + 15, p.y + 12};
collider[5] = {p.x + 15, p.y + 23};
}
// Compruena las colisiones con el mapa
bool Player::checkMapCollisions()
{
bool collision = false;
updateColliders();
for (auto c : collider)
{
collision |= (map->getTile(c) == wall);
}
return collision;
}
// Mueve al jugador en función de la velocidad/desplazamiento
void Player::move()
{
const float old_x = x;
x += vx;
if (checkMapCollisions())
{
x = old_x;
}
// const float old_y = y;
y += vy;
if (checkMapCollisions())
{
// y = old_y;
if (vy > 0)
{
do
{
y--;
} while (checkMapCollisions());
}
else
{
do
{
y++;
} while (checkMapCollisions());
}
vy = 0;
}
sprite->setPosX(x);
sprite->setPosY(y);
sprite->update();
} }

View File

@@ -5,6 +5,7 @@
#include "input.h" #include "input.h"
#include "animatedsprite.h" #include "animatedsprite.h"
#include "asset.h" #include "asset.h"
#include "map.h"
#ifndef PLAYER_H #ifndef PLAYER_H
#define PLAYER_H #define PLAYER_H
@@ -12,32 +13,51 @@
// The player // The player
class Player class Player
{ {
private: public:
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
Input *input; // Objeto Input para gestionar las entradas Input *input; // Objeto Input para gestionar las entradas
AnimatedSprite *sprite; // Objeto con los graficos, animaciones y posición del jugador AnimatedSprite *sprite; // Objeto con los graficos, animaciones y posición del jugador
LTexture *texture; // Textura con los graficos del jugador LTexture *texture; // Textura con los graficos del jugador
Map *map; // Objeto con el mapa
bool can_jump; // Si puede saltar float x; // Posición del jugador en el eje X
bool enabled; // Si está habilitado float y; // Posición del jugador en el eje Y
bool standing; // Si esta de pie (o quieto?) float vx; // Velocidad/desplazamiento del jugador en el eje X
bool invulnerable; // Si es invulnerable float vy; // Velocidad/desplazamiento del jugador en el eje Y
int coins; // Cantidad de monedas bool can_jump; // Si puede saltar
int cooldown; // Tiempo de inhabilitación bool enabled; // Si está habilitado
int jumpforce; // Cantidad de pixels a desplazarse y velocidad que pilla al saltar bool standing; // Si esta de pie (o quieto?)
int lifes; // Cantidad de vidas bool invulnerable; // Si es invulnerable
std::vector<bool> key; // Indica las llaves que posee el jugador int coins; // Cantidad de monedas
JA_Sound sound_coin; // Sonido al coger monedas int cooldown; // Tiempo de inhabilitación
JA_Sound sound_death; // Sonido al morir int jumpforce; // Cantidad de pixels a desplazarse y velocidad que pilla al saltar
JA_Sound sound_jump; // Sonido al saltar int lifes; // Cantidad de vidas
float gravity; // Gravedad
std::vector<bool> key; // Indica las llaves que posee el jugador
std::vector<SDL_Point> collider; // Contiene los puntos de colisión del jugador con el mapa
JA_Sound sound_coin; // Sonido al coger monedas
JA_Sound sound_death; // Sonido al morir
JA_Sound sound_jump; // Sonido al saltar
// Comprueba las entradas y modifica variables // Comprueba las entradas y modifica variables
void checkInput(); void checkInput();
// Aplica la gravedad
void addGravity();
// Actualiza los puntos de colisión
void updateColliders();
// Compruena las colisiones con el mapa
bool checkMapCollisions();
// Mueve al jugador en función de la velocidad/desplazamiento
void move();
public: public:
// Constructor // Constructor
Player(SDL_Renderer *renderer, Asset *asset, Input *input); Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map);
// Destructor // Destructor
~Player(); ~Player();

View File

@@ -168,6 +168,10 @@ bool Prog::setFileList()
asset->add("/media/music/music_surface.ogg", music); asset->add("/media/music/music_surface.ogg", music);
asset->add("/media/music/music_volcano.ogg", music); asset->add("/media/music/music_volcano.ogg", music);
// Texto
asset->add("/media/font/debug.png", font);
asset->add("/media/font/debug.txt", font);
return asset->check(); return asset->check();
} }

View File

@@ -87,6 +87,13 @@ int Sprite::getHeight()
return mHeight; return mHeight;
} }
// Establece la posición del objeto
void Sprite::setPos(SDL_Rect rect)
{
mPosX = rect.x;
mPosY = rect.y;
}
// Establece el valor de la variable // Establece el valor de la variable
void Sprite::setPosX(int x) void Sprite::setPosX(int x)
{ {

View File

@@ -43,6 +43,9 @@ public:
// Obten el valor de la variable // Obten el valor de la variable
int getHeight(); int getHeight();
// Establece la posición del objeto
void setPos(SDL_Rect rect);
// Establece el valor de la variable // Establece el valor de la variable
void setPosX(int x); void setPosX(int x);

View File

@@ -4,13 +4,16 @@
#include <fstream> #include <fstream>
// Constructor // Constructor
Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer) Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
{ {
texture = new LTexture();
loadTextureFromFile(texture, bitmapFile, renderer);
SDL_Rect rect = {0,0,0,0}; SDL_Rect rect = {0,0,0,0};
mSprite = new Sprite(rect, texture, renderer); mSprite = new Sprite(rect, texture, renderer);
mSprite->setTexture(texture); mSprite->setTexture(texture);
mSprite->setRenderer(renderer); mSprite->setRenderer(renderer);
mFile = file; mFile = textFile;
init(); init();
} }
@@ -18,6 +21,10 @@ Text::Text(std::string file, LTexture *texture, SDL_Renderer *renderer)
// Destructor // Destructor
Text::~Text() Text::~Text()
{ {
texture->unload();
delete texture;
texture = nullptr;
delete mSprite; delete mSprite;
mSprite = nullptr; mSprite = nullptr;
} }
@@ -144,7 +151,6 @@ void Text::initOffsetFromFile()
if (rfile.is_open() && rfile.good()) if (rfile.is_open() && rfile.good())
{ {
std::string buffer; std::string buffer;
//printf("Reading %s file\n", mFile.c_str());
// Lee los dos primeros valores del fichero // Lee los dos primeros valores del fichero
std::getline(rfile, buffer); std::getline(rfile, buffer);

View File

@@ -27,20 +27,21 @@ private:
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
std::string mFile; // Fichero con los descriptores de la fuente std::string mFile; // Fichero con los descriptores de la fuente
LTexture *texture; // Textura con los bitmaps del texto
// Inicializador
void init();
// Inicializa el vector de offsets desde un fichero // Inicializa el vector de offsets desde un fichero
void initOffsetFromFile(); void initOffsetFromFile();
public: public:
// Constructor // Constructor
Text(std::string file, LTexture *texture, SDL_Renderer *renderer); Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
// Destructor // Destructor
~Text(); ~Text();
// Inicializador
void init();
// Escribe el texto en pantalla // Escribe el texto en pantalla
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1); void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);