Merging the options

This commit is contained in:
Anonymus Raccoon
2020-05-03 19:30:04 +02:00
11 changed files with 89 additions and 7 deletions

View File

@@ -297,6 +297,7 @@ add_executable(my_rpg
include/components/attack_component.h
src/systems/combat_methods.c
src/combat/attacks.c
src/sound.c
src/player_utilities.c
include/player_utilities.h
include/systems/inventory.h
@@ -324,7 +325,9 @@ add_executable(my_rpg
src/npc/mage.c
src/combat/boss.c
src/components/combat_holder.c
src/systems/combat_utility.c src/systems/particule_methods.c)
src/systems/combat_utility.c
src/systems/particule_methods.c
)
add_compile_options(-W -Wall -Wextra -Wshadow)

View File

@@ -51,7 +51,8 @@ SRC = src/main.c \
src/components/particule_component.c \
src/systems/particule_system.c \
src/systems/combat_utility.c \
src/systems/particule_methods.c
src/systems/particule_methods.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, float vol);
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

@@ -14,6 +14,7 @@ struct game_manager_system {
gc_system base;
bool is_inventory;
bool has_message;
gc_scene *game_scene;
};
extern const struct game_manager_system game_manager_system;

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

@@ -1,6 +1,7 @@
<gc_entities>
<panel src="panel" x="50%" y="45%" width="40%" height="69%" tag="pause" />
<text text="Pause" x="50%" y="25%" resize="false" tag="pause"/>
<button text="Resume" x="50%" y="50%" click="toggle_pause" color="black" width="30%" height="20%" resize="false" tag="pause" />
<button text="Resume" x="50%" y="35%" click="toggle_pause" color="black" width="30%" height="20%" resize="false" tag="pause" />
<button text="Options" x="50%" y="50%" click="options" color="black" width="30%" height="20%" resize="false" tag="pause" />
<button text="Quit to menu" x="50%" y="65%" click="goto_main_menu" color="black" width="30%" height="20%" resize="false" tag="pause" />
</gc_entities>

View File

@@ -43,6 +43,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},

View File

@@ -5,6 +5,8 @@
** main_menu
*/
#include <systems/combat_manager.h>
#include <systems/game_manager_system.h>
#include "systems/sfml_renderer_system.h"
#include "components/dialog_holder.h"
#include "components/dialog_holder.h"
@@ -53,6 +55,8 @@ enum gc_mousekeys __)
my_printf("The option scene couldn't be loaded.\n");
return (true);
}
GETSYS(engine, game_manager_system)->game_scene = engine->scene;
engine->scene = NULL;
engine->change_scene(engine, scene);
entity = engine->scene->get_entity(engine->scene, 50);
if (rend)
@@ -61,13 +65,18 @@ enum gc_mousekeys __)
resolution_set_txt(entity, engine, 0);
entity = engine->scene->get_entity(engine->scene, 52);
framerate_set_text(entity, engine, 0);
entity = engine->scene->get_entity(engine->scene, 53);
sound_set_text(entity, engine, -1);
return (true);
}
bool goto_main_menu(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __)
{
gc_scene *scene = scene_create(engine, "prefabs/mainmenu.gcprefab");
gc_scene *scene = GETSYS(engine, game_manager_system)->game_scene;
if (!scene)
scene = scene_create(engine, "prefabs/mainmenu.gcprefab");
if (!scene) {
engine->should_close = true;
my_printf("The option scene couldn't be loaded.\n");

55
src/sound.c Normal file
View File

@@ -0,0 +1,55 @@
/*
** EPITECH PROJECT, 2020
** Myrpg
** File description:
** sound
*/
#include "entity.h"
#include "engine.h"
#include <malloc.h>
#include <SFML/Audio.h>
#include "utility.h"
#include "components/renderer.h"
#include "systems/sfml_renderer_system.h"
#include "limits.h"
void sound_set_text(gc_entity *entity, gc_engine *engine, float vol)
{
struct sfml_renderer_system *rend = GETSYS(engine, sfml_renderer_system);
struct renderer *renderer;
static char volume[10];
if (!entity)
return;
if (vol == -1)
vol = sfListener_getGlobalVolume();
renderer = GETCMP(entity, renderer);
if (!rend || !renderer || renderer->type != GC_TXTREND)
return;
snprintf(volume, 10, "%.0f", vol);
((gc_text *)renderer->data)->text = volume;
renderer->destroy = &text_safe_destroy;
}
bool sound_down(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __)
{
float vol = sfListener_getGlobalVolume();
vol = MAX(vol - 5, 0);
sfListener_setGlobalVolume(vol);
sound_set_text(engine->scene->get_entity(engine->scene, 53), engine, vol);
return (true);
}
bool sound_up(gc_engine *engine, gc_entity *entity, gc_vector2 _, \
enum gc_mousekeys __)
{
float vol = sfListener_getGlobalVolume();
vol = MIN(vol + 5, 100);
sfListener_setGlobalVolume(vol);
sound_set_text(engine->scene->get_entity(engine->scene, 53), engine, vol);
return (true);
}

View File

@@ -70,6 +70,7 @@ static void ctr(void *system, va_list list)
engine->add_event_listener(engine, "combat_ended", &combat_ended);
this->has_message = false;
this->is_inventory = false;
this->game_scene = NULL;
}
static void dtr(void *system, gc_engine *engine)