Ya pinta al jugador
This commit is contained in:
@@ -11,6 +11,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -18,6 +19,7 @@ Game::~Game()
|
|||||||
{
|
{
|
||||||
delete eventHandler;
|
delete eventHandler;
|
||||||
delete map;
|
delete map;
|
||||||
|
delete player;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
@@ -80,8 +82,9 @@ void Game::render()
|
|||||||
screen->start();
|
screen->start();
|
||||||
screen->clean();
|
screen->clean();
|
||||||
|
|
||||||
// Dibuja el mapa
|
// Dibuja los objetos
|
||||||
map->render();
|
map->render();
|
||||||
|
player->render();
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
@@ -21,6 +22,7 @@ private:
|
|||||||
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
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ private:
|
|||||||
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
||||||
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
||||||
std::string room_right; // Identificador de la habitación que se encuentra a la derecha
|
std::string room_right; // Identificador de la habitación que se encuentra a la derecha
|
||||||
std::string tileset_img; // Imagen con los graficos para la habitación
|
std::string tileset_img; // Imagen con los graficos para la habitación
|
||||||
std::string bg_img; // Imagen con los graficos para la habitación
|
std::string bg_img; // Imagen con los graficos para la habitación
|
||||||
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
|
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
|
||||||
LTexture *texture_tile; // Textura con los graficos de los tiles habitación
|
LTexture *texture_tile; // Textura con los graficos de los tiles habitación
|
||||||
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
|
||||||
|
|||||||
@@ -1,13 +1,60 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
|
#define LEFT 0
|
||||||
|
#define RIGHT 1
|
||||||
|
|
||||||
|
#define BASE_SPEED 0.5;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player()
|
Player::Player(SDL_Renderer *renderer, Asset *asset)
|
||||||
{
|
{
|
||||||
|
this->asset = asset;
|
||||||
|
this->renderer = renderer;
|
||||||
|
|
||||||
|
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_coin = JA_LoadSound(asset->get("sound_player_coin.wav").c_str());
|
||||||
|
|
||||||
|
texture = new LTexture();
|
||||||
|
loadTextureFromFile(texture, asset->get("player.png"), renderer);
|
||||||
|
|
||||||
|
sprite = new AnimatedSprite(texture, renderer);
|
||||||
|
sprite->setPosX(0);
|
||||||
|
sprite->setPosY(0);
|
||||||
|
sprite->setSpriteClip(0, 0, 16, 24);
|
||||||
|
|
||||||
|
direction = RIGHT;
|
||||||
|
respawn_x = sprite->getPosX();
|
||||||
|
respawn_y = sprite->getPosY();
|
||||||
|
respawn_direction = direction;
|
||||||
|
speed_x = BASE_SPEED;
|
||||||
|
speed_y = 0;
|
||||||
|
can_jump = true;
|
||||||
|
jump_pressed_now = false;
|
||||||
|
jump_pressed_before = false;
|
||||||
|
standing = true;
|
||||||
|
invulnerable = true;
|
||||||
|
jumpforce = 10;
|
||||||
|
active_animation = 0;
|
||||||
|
enabled = true;
|
||||||
|
cooldown = 0;
|
||||||
|
lifes = 10;
|
||||||
|
coins = 0;
|
||||||
|
for (Uint8 i = 0; i < 6; i++)
|
||||||
|
key[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
{
|
{
|
||||||
|
JA_DeleteSound(sound_jump);
|
||||||
|
JA_DeleteSound(sound_death);
|
||||||
|
JA_DeleteSound(sound_coin);
|
||||||
|
|
||||||
|
texture->unload();
|
||||||
|
delete texture;
|
||||||
|
|
||||||
|
delete sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza todas las variables
|
// Actualiza todas las variables
|
||||||
@@ -18,4 +65,5 @@ void Player::update()
|
|||||||
// Dibuja el objeto
|
// Dibuja el objeto
|
||||||
void Player::render()
|
void Player::render()
|
||||||
{
|
{
|
||||||
|
sprite->render();
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "jail_audio.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "animatedsprite.h"
|
||||||
|
#include "asset.h"
|
||||||
|
|
||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|
||||||
@@ -6,10 +12,37 @@
|
|||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
AnimatedSprite *sprite; // Objeto con los graficos, animaciones y posición del jugador
|
||||||
|
LTexture *texture; // Textura con los graficos del jugador
|
||||||
|
|
||||||
|
bool can_jump; // Si puede saltar
|
||||||
|
bool enabled; // Si está habilitado
|
||||||
|
bool jump_pressed_before; // Si se ha pulsado el botón de salto previamente
|
||||||
|
bool jump_pressed_now; // Si se acaba de pulsar el salto
|
||||||
|
bool key[6]; // Indica las llaves que posee el jugador
|
||||||
|
bool standing; // Si esta de pie (o quieto?)
|
||||||
|
bool was_on_background; // Si viene de una zona atravesable
|
||||||
|
bool invulnerable; // Si es invulnerable
|
||||||
|
int coins; // Cantidad de monedas
|
||||||
|
int cooldown; // Tiempo de inhabilitación
|
||||||
|
int jumpforce; // Cantidad de pixels a desplazarse y velocidad que pilla al saltar
|
||||||
|
int respawn_x; // Coordenadas para revivir
|
||||||
|
int respawn_y; // Coordenades para revivir
|
||||||
|
int speed_x; // Cantidad de pixeles a desplazarse
|
||||||
|
int speed_y; // Cantidad de pixels a desplazarse
|
||||||
|
JA_Sound sound_coin; // Sonido al coger monedas
|
||||||
|
JA_Sound sound_death; // Sonido al morir
|
||||||
|
JA_Sound sound_jump; // Sonido al saltar
|
||||||
|
Uint8 active_animation; // Animación activa
|
||||||
|
Uint8 direction; // Sentido del desplazamiento
|
||||||
|
Uint8 lifes; // Cantidad de vidas
|
||||||
|
Uint8 respawn_direction; // Dirección para revivir
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Player();
|
Player(SDL_Renderer *renderer, Asset *asset);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Player();
|
~Player();
|
||||||
|
|||||||
Reference in New Issue
Block a user