add sound

This commit is contained in:
Ragot mathis
2020-05-03 17:35:42 +02:00
parent 974590c9f2
commit bf9ebf6b8d
5 changed files with 104 additions and 3 deletions

View File

@@ -44,7 +44,8 @@ SRC = src/main.c \
src/systems/game_over.c \
src/npc/mia.c \
src/npc/fisherman.c \
src/npc/lumberjack.c
src/npc/lumberjack.c \
src/sound.c
OBJ = $(SRC:%.c=%.o)

View File

@@ -32,6 +32,7 @@ void resolution_set_txt(gc_entity *entity, gc_engine *engine, \
enum gc_mousekeys __);
void framerate_set_text(gc_entity *entity, gc_engine *engine, \
enum gc_mousekeys __);
void sound_set_text(gc_entity *entity, gc_engine *engine);
bool fullscreen(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __);
@@ -43,6 +44,10 @@ bool framerate_up(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __);
bool framerate_down(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __);
bool sound_up(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __);
bool sound_down(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __);
bool dialog_input0(gc_engine *engine, gc_entity *entity, gc_vector2 pos, \
enum gc_mousekeys key);

View File

@@ -11,7 +11,7 @@
</data>
<gc_entities>
<panel src="background" x="50%" y="50%" width="100%" height="100%"/>
<panel src="panel" x="50%" y="55%" width="50%" height="50%" />
<panel src="panel" x="50%" y="55%" width="50%" height="80%" />
<text text="Framerate" x="41%" y="40%"/>
<button x="53%" y="40%" click="framerate_down" sprite="left" width="2%" height="4%" />
<text x="59%" y="40%" size="18" text_id="52" />
@@ -22,6 +22,10 @@
<button x="53%" y="60%" click="resolution_down" sprite="left" width="2%" height="4%" />
<text x="59%" y="60%" size="18" text_id="51" />
<button x="65%" y="60%" click="resolution_up" sprite="right" width="2%" height="4%" />
<button text="Back" x="50%" y="71%" click="goto_main_menu" color="black" width="20%" height="15%"resize="false" />
<text text="Volume" x="41%" y="70%"/>
<button x="53%" y="70%" click="sound_down" sprite="left" width="2%" height="4%" />
<text x="59%" y="70%" size="18" text_id="53" />
<button x="65%" y="70%" click="sound_up" sprite="right" width="2%" height="4%" />
<button text="Back" x="50%" y="84%" click="goto_main_menu" color="black" width="20%" height="15%"resize="false" />
</gc_entities>
</gc_scene>

View File

@@ -41,6 +41,8 @@ const struct callback callbacks[] = {
{"resolution_up", &resolution_up},
{"framerate_up", &framerate_up},
{"framerate_down", &framerate_down},
{"sound_down", &sound_down},
{"sound_up", &sound_up},
{"catch", &catch},
{"toggle_pause", &toggle_pause},
{"toggle_inventory", &toggle_inventory},

89
src/sound.c Normal file
View File

@@ -0,0 +1,89 @@
/*
** EPITECH PROJECT, 2020
** Myrpg
** File description:
** sound
*/
#include "entity.h"
#include "engine.h"
#include <malloc.h>
#include "utility.h"
#include "components/renderer.h"
#include "systems/sfml_renderer_system.h"
#include "limits.h"
static const float sound[] = {
0,
5,
10,
15,
20,
25,
30,
35,
40,
45,
50,
55,
60,
65,
70,
75,
80,
85,
90,
95,
100,
INT_MAX
};
void sound_set_text(gc_entity *entity, gc_engine *engine)
{
struct sfml_renderer_system *rend = GETSYS(engine, sfml_renderer_system);
struct renderer *renderer;
char *volume;
if (!entity)
return;
renderer = GETCMP(entity, renderer);
if (!rend || !renderer || renderer->type != GC_TXTREND)
return;
volume = tostr(rend->sound);
free(((gc_text *)renderer->data)->text);
((gc_text *)renderer->data)->text = volume;
}
bool sound_down(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __)
{
struct sfml_renderer_system *rend = GETSYS(engine, sfml_renderer_system);
int i = 2;
if (!rend || rend->is_fullscreen)
return (false);
while (i > 0 && sound[i] >= rend->sound)
i--;
sfListener_setGlobalVolume(sound[i]);
rend->sound = sound[i];
sound_set_text(engine->scene->get_entity(engine->scene, 53), engine);
return (true);
}
bool sound_up(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __)
{
struct sfml_renderer_system *rend = GETSYS(engine, sfml_renderer_system);
int i = 0;
if (!rend || rend->is_fullscreen)
return (false);
while (sound[i] <= rend->sound)
i++;
if (sound[i] == INT_MAX)
return (true);
sfListener_setGlobalVolume(sound[i]);
rend->sound = sound[i];
sound_set_text(engine->scene->get_entity(engine->scene, 53), engine);
return (true);
}