forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya sube cuestas pero no las baja
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
@@ -164,11 +164,13 @@ bool Director::setFileList()
|
|||||||
asset->add("/data/room/03.room", room);
|
asset->add("/data/room/03.room", room);
|
||||||
asset->add("/data/room/04.room", room);
|
asset->add("/data/room/04.room", room);
|
||||||
asset->add("/data/room/05.room", room);
|
asset->add("/data/room/05.room", room);
|
||||||
|
asset->add("/data/room/06.room", room);
|
||||||
asset->add("/data/room/01.tmx", room);
|
asset->add("/data/room/01.tmx", room);
|
||||||
asset->add("/data/room/02.tmx", room);
|
asset->add("/data/room/02.tmx", room);
|
||||||
asset->add("/data/room/03.tmx", room);
|
asset->add("/data/room/03.tmx", room);
|
||||||
asset->add("/data/room/04.tmx", room);
|
asset->add("/data/room/04.tmx", room);
|
||||||
asset->add("/data/room/05.tmx", room);
|
asset->add("/data/room/05.tmx", room);
|
||||||
|
asset->add("/data/room/06.tmx", room);
|
||||||
|
|
||||||
asset->add("/media/tilesets/standard.png", bitmap);
|
asset->add("/media/tilesets/standard.png", bitmap);
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||||
{
|
{
|
||||||
// Inicia variables
|
// Inicia algunas variables
|
||||||
clock = SDL_GetTicks();
|
clock = SDL_GetTicks();
|
||||||
currentRoom = "01.room";
|
currentRoom = "01.room";
|
||||||
spawnPoint = {2 * 8, 12 * 8, 0, 0, 0, s_standing, SDL_FLIP_NONE};
|
spawnPoint = {16, 96, 0, 0, 0, s_standing, SDL_FLIP_NONE};
|
||||||
|
|
||||||
|
currentRoom = "06.room";
|
||||||
|
spawnPoint = {240, 96, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||||
|
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
@@ -24,7 +27,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
|||||||
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa el resto de variables
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
playerLives = 9;
|
playerLives = 9;
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// CAUTION!!!!! si no se gasta al final, quitar la referencia a la habitación
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Renderer *renderer, Asset *asset, Input *input, Room *room)
|
Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Renderer *renderer, Asset *asset, Input *input, Room *room)
|
||||||
{
|
{
|
||||||
@@ -40,12 +38,15 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren
|
|||||||
sprite->setHeight(16);
|
sprite->setHeight(16);
|
||||||
|
|
||||||
sprite->setFlip(ini.flip);
|
sprite->setFlip(ini.flip);
|
||||||
|
sprite->setCurrentAnimation("walk");
|
||||||
|
sprite->animate();
|
||||||
|
|
||||||
lastPosition = getRect();
|
lastPosition = getRect();
|
||||||
colliderBox = getRect();
|
colliderBox = getRect();
|
||||||
const SDL_Point p = {0, 0};
|
const SDL_Point p = {0, 0};
|
||||||
colliderPoints.insert(colliderPoints.end(), {p, p, p, p, p, p, p, p});
|
colliderPoints.insert(colliderPoints.end(), {p, p, p, p, p, p, p, p});
|
||||||
underFeet.insert(underFeet.end(), {p, p});
|
underFeet.insert(underFeet.end(), {p, p});
|
||||||
|
feet.insert(feet.end(), {p, p});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -236,6 +237,23 @@ void Player::move()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba colisiones con rampas
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const tile_e slope = checkSlopes();
|
||||||
|
// Se mueve hacia la derecha y cuesta hacia la derecha
|
||||||
|
if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_r)
|
||||||
|
{ // Recoloca
|
||||||
|
y = -h + room->getSlopeHeight(feet[1], t_slope_r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Se mueve hacia la izquierda y cuesta hacia la izquierda
|
||||||
|
if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_l)
|
||||||
|
{ // Recoloca
|
||||||
|
y = -h + room->getSlopeHeight(feet[0], t_slope_l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
y += vy;
|
y += vy;
|
||||||
if (checkWalls())
|
if (checkWalls())
|
||||||
{
|
{
|
||||||
@@ -309,6 +327,12 @@ void Player::move()
|
|||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// EXPERIMENTAL
|
||||||
|
else if (checkSlopes())
|
||||||
|
{
|
||||||
|
state = s_standing;
|
||||||
|
vy = 0.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,16 +344,10 @@ void Player::move()
|
|||||||
// Establece la animación del jugador
|
// Establece la animación del jugador
|
||||||
void Player::animate()
|
void Player::animate()
|
||||||
{
|
{
|
||||||
// Establece la animación
|
|
||||||
if (vx != 0)
|
if (vx != 0)
|
||||||
{
|
{
|
||||||
sprite->setCurrentAnimation("walk");
|
sprite->animate();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
sprite->setCurrentAnimation("stand");
|
|
||||||
}
|
|
||||||
sprite->animate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
||||||
@@ -353,7 +371,8 @@ bool Player::isOnFloor()
|
|||||||
|
|
||||||
for (auto f : underFeet)
|
for (auto f : underFeet)
|
||||||
{
|
{
|
||||||
onFloor |= ((room->getTile(f) == TILE_SOLID) || (room->getTile(f) == TILE_TRAVESSABLE));
|
const tile_e tile = (room->getTile(f));
|
||||||
|
onFloor |= (tile == t_wall || tile == t_passable || tile == t_slope_l || tile == t_slope_r);
|
||||||
}
|
}
|
||||||
|
|
||||||
return onFloor;
|
return onFloor;
|
||||||
@@ -370,12 +389,41 @@ bool Player::checkWalls()
|
|||||||
|
|
||||||
for (auto c : colliderPoints)
|
for (auto c : colliderPoints)
|
||||||
{
|
{
|
||||||
wall |= (room->getTile(c) == TILE_SOLID);
|
wall |= (room->getTile(c) == t_wall);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wall;
|
return wall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comprueba si el jugador está en una rampa
|
||||||
|
tile_e Player::checkSlopes()
|
||||||
|
{
|
||||||
|
// Actualiza los puntos de colisión
|
||||||
|
updateFeet();
|
||||||
|
|
||||||
|
// Comprueba si ha colisionado con una rampa
|
||||||
|
bool slope_l = false;
|
||||||
|
bool slope_r = false;
|
||||||
|
|
||||||
|
for (auto f : feet)
|
||||||
|
{
|
||||||
|
slope_l |= (room->getTile(f) == t_slope_l);
|
||||||
|
slope_r |= (room->getTile(f) == t_slope_r);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slope_l)
|
||||||
|
{
|
||||||
|
return t_slope_l;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slope_r)
|
||||||
|
{
|
||||||
|
return t_slope_r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return t_empty;
|
||||||
|
}
|
||||||
|
|
||||||
// Obtiene algunos parametros del jugador
|
// Obtiene algunos parametros del jugador
|
||||||
player_t Player::getSpawnParams()
|
player_t Player::getSpawnParams()
|
||||||
{
|
{
|
||||||
@@ -425,6 +473,9 @@ void Player::updateFeet()
|
|||||||
|
|
||||||
underFeet[0] = {p.x, p.y + h};
|
underFeet[0] = {p.x, p.y + h};
|
||||||
underFeet[1] = {p.x + 7, p.y + h};
|
underFeet[1] = {p.x + 7, p.y + h};
|
||||||
|
|
||||||
|
feet[0] = {p.x, p.y + h - 1};
|
||||||
|
feet[1] = {p.x + 7, p.y + h - 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
SDL_Rect colliderBox; // Caja de colisión con los enemigos u objetos
|
SDL_Rect colliderBox; // Caja de colisión con los enemigos u objetos
|
||||||
std::vector<SDL_Point> colliderPoints; // Puntos de colisión con el mapa
|
std::vector<SDL_Point> colliderPoints; // Puntos de colisión con el mapa
|
||||||
std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador
|
std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador
|
||||||
|
std::vector<SDL_Point> feet; // Contiene los puntos que hay en el pie del jugador
|
||||||
state_e state; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
state_e state; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||||
bool onBorder; // Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
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
|
int border; // Indica en cual de los cuatro bordes se encuentra
|
||||||
@@ -89,6 +90,9 @@ public:
|
|||||||
// Comprueba que el jugador no atraviese ninguna pared
|
// Comprueba que el jugador no atraviese ninguna pared
|
||||||
bool checkWalls();
|
bool checkWalls();
|
||||||
|
|
||||||
|
// Comprueba si el jugador está en una rampa
|
||||||
|
tile_e checkSlopes();
|
||||||
|
|
||||||
// Actualiza los puntos de colisión
|
// Actualiza los puntos de colisión
|
||||||
void updateColliderPoints();
|
void updateColliderPoints();
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset
|
|||||||
|
|
||||||
// Establece el color del borde
|
// Establece el color del borde
|
||||||
screen->setBorderColor(borderColor);
|
screen->setBorderColor(borderColor);
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
tileSize = 8;
|
||||||
|
mapWidth = 32;
|
||||||
|
mapHeight = 16;
|
||||||
|
tilesetWidth = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -499,29 +505,36 @@ std::string Room::getRoom(int border)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el tipo de tile que hay en ese pixel
|
// Devuelve el tipo de tile que hay en ese pixel
|
||||||
int Room::getTile(SDL_Point point)
|
tile_e Room::getTile(SDL_Point point)
|
||||||
{
|
{
|
||||||
int pos = ((point.y / 8) * 32) + (point.x / 8);
|
const int maxTile = mapWidth * mapHeight;
|
||||||
int tile = TILE_EMPTY;
|
const int pos = ((point.y / tileSize) * mapWidth) + (point.x / tileSize);
|
||||||
|
tile_e tile = t_empty;
|
||||||
|
|
||||||
if (pos < 512)
|
if (pos < maxTile)
|
||||||
{
|
{
|
||||||
// Los tiles entre el 1 y el 80 son solidos
|
// Las filas 0-7 son de tiles t_wall
|
||||||
if ((tilemap[pos] > 0) && (tilemap[pos] < 201))
|
if ((tilemap[pos] > 0) && (tilemap[pos] < 8 * tilesetWidth))
|
||||||
{
|
{
|
||||||
return TILE_SOLID;
|
return t_wall;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Los tiles mayores de 80 son atravesables
|
// La fila 8 es de tiles t_slope_r
|
||||||
if ((tilemap[pos] > 200) && (tilemap[pos] < 381))
|
else if ((tilemap[pos] >= 8 * tilesetWidth) && (tilemap[pos] < 9 * tilesetWidth))
|
||||||
{
|
{
|
||||||
return TILE_TRAVESSABLE;
|
return t_slope_r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Los tiles mayores de 80 son atravesables
|
// La fila 9 es de tiles t_slope_l
|
||||||
if ((tilemap[pos] > 380) && (tilemap[pos] < 400))
|
else if ((tilemap[pos] >= 9 * tilesetWidth) && (tilemap[pos] < 10 * tilesetWidth))
|
||||||
{
|
{
|
||||||
return TILE_KILL;
|
return t_slope_l;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Las filas 10-14 son de tiles t_passable
|
||||||
|
if ((tilemap[pos] >= 10 * tilesetWidth) && (tilemap[pos] < 15 * tilesetWidth))
|
||||||
|
{
|
||||||
|
return t_passable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,3 +595,29 @@ int Room::getTileSize()
|
|||||||
{
|
{
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||||
|
int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
||||||
|
{
|
||||||
|
// Calcula la base del tile
|
||||||
|
int base = ((p.y / tileSize) * tileSize) + tileSize;
|
||||||
|
printf("base %i\n", base);
|
||||||
|
|
||||||
|
// Calcula cuanto se ha entrado en el tile horizontalmente
|
||||||
|
const int pos = (p.x % tileSize); // esto da un valor entre 0 y 7
|
||||||
|
printf("pos %i\n", base);
|
||||||
|
|
||||||
|
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
||||||
|
if (slope == t_slope_r)
|
||||||
|
{
|
||||||
|
base -= pos+1;
|
||||||
|
printf("base_R %i\n", base);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base -= (tileSize - pos);
|
||||||
|
printf("base_L %i\n", base);
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
@@ -15,24 +15,29 @@
|
|||||||
#ifndef ROOM_H
|
#ifndef ROOM_H
|
||||||
#define ROOM_H
|
#define ROOM_H
|
||||||
|
|
||||||
#define TILE_EMPTY 0
|
|
||||||
#define TILE_SOLID 1
|
|
||||||
#define TILE_TRAVESSABLE 2
|
|
||||||
#define TILE_KILL 3
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cada habitación se crea y destruye cada vez que se entra o sale de la misma
|
Cada habitación se crea y destruye cada vez que se entra o sale de la misma
|
||||||
Cada habitacion si que tendra lo siguiente:
|
Cada habitacion tiene lo siguiente:
|
||||||
ID (numerico)
|
- ID (numerico)
|
||||||
NOMBRE (texto)
|
- NOMBRE (texto)
|
||||||
COLOR DE FONDO (texto)
|
- COLOR DE FONDO (texto)
|
||||||
SET DE TILES (texto, hace referencia a un png de la colección)
|
- COLOR DEL BORDE (texto)
|
||||||
LIMITE SUPERIOR (ID de la habitación superior), INFERIOR, IZQUIERDO y DERECHO
|
- SET DE TILES (texto, hace referencia a un png de la colección)
|
||||||
MAPA DE TILES (array con los indices de los tiles a utilizar) <-- hay que decidir si cada tile del set ya
|
- LIMITE SUPERIOR (ID de la habitación superior), INFERIOR, IZQUIERDO y DERECHO
|
||||||
tierne propiedades o se ponen en un mapa aparte
|
- MAPA DE TILES (array con los indices de los tiles a utilizar) <-- hay que decidir si cada tile del set ya
|
||||||
LISTADO DE ENEMIGOS (tipo, posicion, dx, dy)
|
tierne propiedades o se ponen en un mapa aparte
|
||||||
LISTADO DE ITEMS (tipo, posicion)
|
- LISTADO DE ENEMIGOS (tipo, posicion, dx, dy)
|
||||||
|
- LISTADO DE ITEMS (tipo, posicion)
|
||||||
*/
|
*/
|
||||||
|
enum tile_e
|
||||||
|
{
|
||||||
|
t_empty,
|
||||||
|
t_wall,
|
||||||
|
t_passable,
|
||||||
|
t_slope_l,
|
||||||
|
t_slope_r,
|
||||||
|
t_death
|
||||||
|
};
|
||||||
|
|
||||||
// Clase Room
|
// Clase Room
|
||||||
class Room
|
class Room
|
||||||
@@ -58,6 +63,11 @@ private:
|
|||||||
JA_Sound itemSound; // Sonido producido al coger un objeto
|
JA_Sound itemSound; // Sonido producido al coger un objeto
|
||||||
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
|
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
|
||||||
|
|
||||||
|
int tileSize; // Ancho del tile en pixels
|
||||||
|
int mapWidth; // Ancho del mapa en tiles
|
||||||
|
int mapHeight; // Alto del mapa en tiles
|
||||||
|
int tilesetWidth; // Ancho del tileset en tiles
|
||||||
|
|
||||||
// Carga las variables desde un fichero
|
// Carga las variables desde un fichero
|
||||||
bool load(std::string file_path);
|
bool load(std::string file_path);
|
||||||
|
|
||||||
@@ -102,7 +112,7 @@ public:
|
|||||||
std::string getRoom(int border);
|
std::string getRoom(int border);
|
||||||
|
|
||||||
// Devuelve el tipo de tile que hay en ese pixel
|
// Devuelve el tipo de tile que hay en ese pixel
|
||||||
int getTile(SDL_Point point);
|
tile_e getTile(SDL_Point point);
|
||||||
|
|
||||||
// Indica si hay colision con un enemigo a partir de un rectangulo
|
// Indica si hay colision con un enemigo a partir de un rectangulo
|
||||||
bool enemyCollision(SDL_Rect &rect);
|
bool enemyCollision(SDL_Rect &rect);
|
||||||
@@ -115,6 +125,10 @@ public:
|
|||||||
|
|
||||||
// Obten el tamaño del tile
|
// Obten el tamaño del tile
|
||||||
int getTileSize();
|
int getTileSize();
|
||||||
|
|
||||||
|
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||||
|
int getSlopeHeight(SDL_Point p, tile_e slope);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user