Audio añadido

parent 1cbd5419
No preview for this file type
#include "GestorPantallas.h" #include "GestorPantallas.h"
#include <SDL2/SDL_render.h> #include <SDL2/SDL_render.h>
#include <SDL2/SDL_mixer.h>
void Handle::reemplazamePor(shared_ptr<Pantalla> pant){ void Handle::reemplazamePor(shared_ptr<Pantalla> pant){
pant->init(); pant->init();
...@@ -64,6 +65,13 @@ bool GestorPantallas::inicializarSDL(){ ...@@ -64,6 +65,13 @@ bool GestorPantallas::inicializarSDL(){
return false; return false;
} }
if(Mix_Init(MIX_INIT_OGG | MIX_INIT_MP3) < 0){
std::cout << "Error at Mix_Init(Mix_INIT_OGG);"<<std::endl;
std::cout << "Error: " << SDL_GetError() << std::endl;
return false;
}
if (TTF_Init() < 0) { if (TTF_Init() < 0) {
std::cout << "Error at TTF_Init();"<<std::endl; std::cout << "Error at TTF_Init();"<<std::endl;
std::cout << "Error: " << SDL_GetError() << std::endl; std::cout << "Error: " << SDL_GetError() << std::endl;
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
#include "ColeccionPantallas.h" #include "ColeccionPantallas.h"
#include "PantallaInicio.h" #include "PantallaInicio.h"
#include "Video.h" #include "Video.h"
#include "SDL2/SDL_mixer.h"
PantallaInicio::PantallaInicio() : PantallaInicio::PantallaInicio() :
fuente1("assets/OpenSans-Italic.ttf", 100), fuente1("assets/OpenSans-Italic.ttf", 100),
Fondo1("assets/PantallaInicio.jpg"), Fondo1("assets/PantallaInicio.jpg"),
colisionCambioPantalla(1500,-1500,2000,1300) colisionCambioPantalla(1500,-1500,2000,1300),
AnuncioTitulo("assets/AgapitoTitulo.wav",false),
Cancion("assets/Spring In My Step - Silent Partner.wav",true)
{ {
Sprite sprIniciarPartida("assets/iniciarPartida.png"); Sprite sprIniciarPartida("assets/iniciarPartida.png");
...@@ -29,6 +31,7 @@ void PantallaInicio::manejarEntrada(Handle &handle) { ...@@ -29,6 +31,7 @@ void PantallaInicio::manejarEntrada(Handle &handle) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) { switch (event.key.keysym.sym) {
case 13: case 13:
Cancion.pausar();
play_video("assets/Encerrado.mp4", "es"); play_video("assets/Encerrado.mp4", "es");
handle.reemplazamePor(colPantallas[0]); handle.reemplazamePor(colPantallas[0]);
break; break;
...@@ -43,6 +46,7 @@ void PantallaInicio::manejarEntrada(Handle &handle) { ...@@ -43,6 +46,7 @@ void PantallaInicio::manejarEntrada(Handle &handle) {
zRaton*=(1080.0/handle.getTamY()); zRaton*=(1080.0/handle.getTamY());
cout<<"Raton x "<<xRaton<<" Raton z "<<zRaton<<endl; cout<<"Raton x "<<xRaton<<" Raton z "<<zRaton<<endl;
if(colisionesInterfaz[0].colisiona(xRaton, zRaton) ){ if(colisionesInterfaz[0].colisiona(xRaton, zRaton) ){
Cancion.pausar();
play_video("assets/Encerrado.mp4", "es"); play_video("assets/Encerrado.mp4", "es");
handle.reemplazamePor(colPantallas[0]); handle.reemplazamePor(colPantallas[0]);
} }
...@@ -55,7 +59,12 @@ void PantallaInicio::manejarEntrada(Handle &handle) { ...@@ -55,7 +59,12 @@ void PantallaInicio::manejarEntrada(Handle &handle) {
} }
void PantallaInicio::renderizar(SDL_Renderer *renderer, int tamx, int tamy) { void PantallaInicio::renderizar(SDL_Renderer *renderer, int tamx, int tamy) {
if(!AnuncioTitulo.getTocada()){
AnuncioTitulo.play();
}
if(AnuncioTitulo.acabado() && !Cancion.getTocada()){
Cancion.play();
}
Fondo1.renderizar(renderer, 0, 0,1920,1080, tamx, tamy); Fondo1.renderizar(renderer, 0, 0,1920,1080, tamx, tamy);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "Sprite.h" #include "Sprite.h"
#include "Texto.h" #include "Texto.h"
#include "Fuente.h" #include "Fuente.h"
#include "Sonido.h"
class PantallaInicio : public Pantalla { class PantallaInicio : public Pantalla {
...@@ -16,6 +17,9 @@ class PantallaInicio : public Pantalla { ...@@ -16,6 +17,9 @@ class PantallaInicio : public Pantalla {
Hitbox colisionCambioPantalla; Hitbox colisionCambioPantalla;
Fuente fuente1; Fuente fuente1;
Sprite Fondo1; Sprite Fondo1;
Sonido AnuncioTitulo;
Sonido Cancion;
public: public:
......
#include "Sonido.h"
Sonido::Sonido(string ruta, bool cancion){
if(Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,1024)==-1){
printf("Mix_OpenAudio: %s\n", Mix_GetError());
exit(2);
}else{
archivo=Mix_LoadMUS(ruta.c_str());
this->cancion=cancion;
}
}
Sonido::~Sonido(){
Mix_FreeMusic(archivo);
}
//-1 es loop
void Sonido::play(){
if(archivo==nullptr){
cout<<"No hay cancion nano"<<endl;
}
if(cancion){
Mix_PlayMusic(archivo,-1);
cout<<"Ha sonado";
}else{
Mix_PlayMusic(archivo,1);
cout<<"Ha sonado";
}
tocada=true;
}
void Sonido::pausar(){
Mix_Pause(-1);
}
bool Sonido::getTocada(){return tocada;}
bool Sonido::acabado(){
acaba=!Mix_PlayingMusic();
return acaba;
}
\ No newline at end of file
#pragma once
#include <SDL2/SDL_mixer.h>
#include <iostream>
using namespace std;
class Sonido{
bool cancion;
Mix_Music *archivo;
bool tocada=false;
bool acaba=false;
public:
Sonido(string ruta, bool cancion);
~Sonido();
void play();
void pausar();
bool getTocada();
bool acabado();
};
\ No newline at end of file
No preview for this file type
The file could not be displayed because it is too large.
CC = g++ CC = g++
CodeFiles = main.cpp Personaje.cpp Sprite.cpp Objeto.cpp Hitbox.cpp Texto.cpp GestorPantallas.cpp PantallaPrincipal.cpp PantallaPrincipal2.cpp ColeccionPantallas.cpp Video.cpp PantallaInicio.cpp PantallaMundo.cpp CodeFiles = main.cpp Personaje.cpp Sprite.cpp Objeto.cpp Hitbox.cpp Texto.cpp GestorPantallas.cpp PantallaPrincipal.cpp PantallaPrincipal2.cpp ColeccionPantallas.cpp Video.cpp PantallaInicio.cpp PantallaMundo.cpp Sonido.cpp
bin = Executable bin = Executable
...@@ -9,7 +9,7 @@ code_files_in_obj = $(CodeFiles:%=$(objdir)/%) ...@@ -9,7 +9,7 @@ code_files_in_obj = $(CodeFiles:%=$(objdir)/%)
objs = $(code_files_in_obj:.cpp=.o) objs = $(code_files_in_obj:.cpp=.o)
deps = $(code_files_in_obj:.cpp=.d) deps = $(code_files_in_obj:.cpp=.d)
link_flags = -lSDL2 -lSDL2_image -lSDL2_ttf link_flags = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
compile_flags = -w $(link_flags) compile_flags = -w $(link_flags)
$(bin): $(objs) $(bin): $(objs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment