forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida música
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
name=void main
|
||||
bgColor=light_black
|
||||
bgColor=black
|
||||
tileset=standard.png
|
||||
roomUp=0
|
||||
roomDown=0
|
||||
|
||||
BIN
media/music/jd.ogg
Normal file
BIN
media/music/jd.ogg
Normal file
Binary file not shown.
@@ -18,7 +18,7 @@ frames=0,1,2,3
|
||||
|
||||
[animation]
|
||||
name=walk_menu
|
||||
speed=50
|
||||
speed=0
|
||||
loop=0
|
||||
frames=0,1,2,3
|
||||
[/animation]
|
||||
@@ -48,8 +48,11 @@ int AnimatedSprite::getIndex(std::string name)
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void AnimatedSprite::animate()
|
||||
{
|
||||
if (enabled)
|
||||
if (!enabled || animation[currentAnimation].speed == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcula el frame actual a partir del contador
|
||||
animation[currentAnimation].currentFrame = animation[currentAnimation].counter / animation[currentAnimation].speed;
|
||||
|
||||
@@ -77,13 +80,15 @@ void AnimatedSprite::animate()
|
||||
// Incrementa el contador de la animacion
|
||||
animation[currentAnimation].counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void AnimatedSprite::setCurrentFrame(std::string name, int num)
|
||||
void AnimatedSprite::setCurrentFrame(int num)
|
||||
{
|
||||
animation[getIndex(name)].currentFrame = num;
|
||||
animation[currentAnimation].currentFrame = num;
|
||||
|
||||
// Escoge el frame correspondiente de la animación
|
||||
setSpriteClip(animation[currentAnimation].frames[animation[currentAnimation].currentFrame]);
|
||||
}
|
||||
|
||||
// Establece el valor del contador
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
void animate();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void setCurrentFrame(std::string name, int num);
|
||||
void setCurrentFrame(int num);
|
||||
|
||||
// Establece el valor del contador
|
||||
void setAnimationCounter(std::string name, int num);
|
||||
|
||||
@@ -184,6 +184,8 @@ bool Director::setFileList()
|
||||
|
||||
asset->add("/media/items/items.png", bitmap);
|
||||
|
||||
asset->add("/media/music/jd.ogg", music);
|
||||
|
||||
return asset->check();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
debugText = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||
music = JA_LoadMusic(asset->get("jd.ogg").c_str());
|
||||
|
||||
// Inicializa variables
|
||||
ticks = 0;
|
||||
@@ -64,6 +65,8 @@ Game::~Game()
|
||||
// Bucle para el juego
|
||||
section_t Game::run()
|
||||
{
|
||||
JA_PlayMusic(music);
|
||||
|
||||
while (section.name == SECTION_PROG_GAME)
|
||||
{
|
||||
// Sección juego jugando
|
||||
@@ -74,6 +77,8 @@ section_t Game::run()
|
||||
}
|
||||
}
|
||||
|
||||
JA_StopMusic();
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
@@ -103,6 +108,10 @@ void Game::update()
|
||||
debug = !debug;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_M:
|
||||
(JA_GetMusicState() == JA_MUSIC_PLAYING) ? JA_PauseMusic() : JA_ResumeMusic();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F:
|
||||
screen->switchVideoMode();
|
||||
break;
|
||||
|
||||
@@ -33,6 +33,7 @@ private:
|
||||
Text *text; // Objeto para los textos del juego
|
||||
Text *debugText; // Objeto para los textos de debug del juego
|
||||
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
||||
JA_Music music; // Musica que suena durante el juego
|
||||
int ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
int ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
section_t section; // Seccion actual dentro del juego
|
||||
|
||||
@@ -14,6 +14,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset)
|
||||
loadTextureFromFile(texture, asset->get("player01.png"), renderer);
|
||||
sprite = new AnimatedSprite(texture, renderer, asset->get("player01.ani"));
|
||||
sprite->setCurrentAnimation("walk_menu");
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
|
||||
// Inicializa las variables
|
||||
counter = 0;
|
||||
@@ -37,6 +38,30 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset)
|
||||
|
||||
c = stringToColor("yellow");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("white");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_blue");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_red");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_purple");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_green");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_cyan");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_yellow");
|
||||
color.push_back(c);
|
||||
|
||||
c = stringToColor("light_white");
|
||||
color.push_back(c);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -48,6 +73,9 @@ ScoreBoard::~ScoreBoard()
|
||||
|
||||
delete sprite;
|
||||
sprite = nullptr;
|
||||
|
||||
delete text;
|
||||
text = nullptr;
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
@@ -58,12 +86,15 @@ void ScoreBoard::render()
|
||||
|
||||
// Dibuja el fondo del marcador
|
||||
const SDL_Rect rect = {0, 17 * BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_HEIGHT - PLAY_AREA_HEIGHT};
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
// Dibuja las vidas
|
||||
sprite->setPosY(18 * BLOCK);
|
||||
int index;
|
||||
int desp = (counter / 40) % 8;
|
||||
const int desp = (counter / 40) % 8;
|
||||
const int frame = desp % 4;
|
||||
sprite->setCurrentFrame(frame);
|
||||
|
||||
for (int i = 0; i < num_lives; i++)
|
||||
{
|
||||
@@ -72,6 +103,11 @@ void ScoreBoard::render()
|
||||
sprite->getTexture()->setColor(color[index].r, color[index].g, color[index].b);
|
||||
sprite->render();
|
||||
}
|
||||
|
||||
// Escribe los textos
|
||||
const std::string text = "Items collected 008 Time 88875";
|
||||
const color_t color = stringToColor("white");
|
||||
this->text->writeColored(BLOCK, 21 * BLOCK, text, color);
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "text.h"
|
||||
#include "asset.h"
|
||||
#include "animatedsprite.h"
|
||||
#include "const.h"
|
||||
@@ -18,6 +19,7 @@ private:
|
||||
AnimatedSprite *sprite; // Sprite para mostrar las vidas en el marcador
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Text *text; // Objeto para escribir texto
|
||||
std::vector<color_t> color; // Vector con los colores del objeto
|
||||
int counter; // Contador interno
|
||||
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
|
||||
|
||||
Reference in New Issue
Block a user