Cleaning up

This commit is contained in:
Anonymus Raccoon
2020-03-27 14:28:03 +01:00
parent 97e73361fb
commit a58891d94f
44 changed files with 15 additions and 995 deletions
+6 -20
View File
@@ -211,7 +211,6 @@ add_executable(my_rpg
lib/my/my/my_str_replace.c
lib/gamacon/src/sfml_renderer/sfml_init.c
lib/gamacon/src/sfml_renderer/sfml_events.c
lib/gamacon/src/isometry/map_utils.c
lib/gamacon/include/map_utils.h
lib/xmlparser/src/otherget.c
src/options.c
@@ -221,48 +220,35 @@ add_executable(my_rpg
src/options.c
lib/gamacon/src/components/input_component.c
lib/gamacon/include/components/input_component.h
src/systems/teams_system.c
include/systems/teams_system.h
include/components/teams_component.h
src/components/teams_component.c
lib/gamacon/src/components/tag_component.c
lib/gamacon/include/components/tag_component.h
src/components/game_manager.c
include/components/game_manager.h
include/dpr_errors.h
include/components/game_display.h
src/components/game_display.c
src/systems/game_display_system.c
src/isometry/tile_collision_manager.c
include/errors_str.h
lib/gamacon/include/tile_collision_manager.h
lib/gamacon/src/engine/event_manager.c
lib/gamacon/include/event_manager.h
src/teams/absent.c
src/teams/forgot.c include/teams.h
src/systems/game_manager_system.c
include/systems/game_manager_system.h
lib/gamacon/include/keybindings.h
src/isometry/map_interactions.c
include/map_interactions.h
lib/gamacon/include/keybindings.h
lib/gamacon/src/ui/tooltip.c
lib/gamacon/src/components/tooltip_component.c
lib/gamacon/include/components/tooltip_component.h
lib/gamacon/src/systems/tooltip_system.c
src/components/map_manager_component.c
include/components/isometry/map_manager_component.h
lib/gamacon/src/isometry/vertex_data_loader.c
lib/gamacon/src/isometry/map_utils.c
lib/gamacon/src/isometry/tile_collisions.c
lib/gamacon/include/vertex_data_loader.h
src/toolbar.c
lib/gamacon/include/callbacks.h src/selectors.c
lib/gamacon/include/callbacks.h
src/framerate.c
lib/gamacon/src/isometry/isometry.c
lib/gamacon/include/isometry.h
)
lib/gamacon/src/components/renderers/anim_utils.c)
add_compile_options(-W -Wall -Wextra -Wshadow)
target_link_libraries(My3D
target_link_libraries(my_rpg
csfml-system
csfml-graphics
csfml-audio
+4 -15
View File
@@ -10,19 +10,8 @@ SRC = src/main.c \
src/framerate.c \
src/main_menu.c \
src/options.c \
src/selectors.c \
src/toolbar.c \
src/teams/absent.c \
src/teams/forgot.c \
src/systems/game_display_system.c \
src/systems/game_manager_system.c \
src/systems/teams_system.c \
src/isometry/map_interactions.c \
src/isometry/tile_collision_manager.c \
src/components/map_manager_component.c \
src/components/game_display.c \
src/components/game_manager.c \
src/components/teams_component.c
src/components/game_manager.c
OBJ = $(SRC:%.c=%.o)
@@ -30,8 +19,8 @@ INCLUDE = -I ./include -I lib/gamacon/include -I lib/gamacon/lib/xmlparser/inclu
CFLAGS = $(INCLUDE) -Wall -Wshadow -Wextra -Wno-unused-parameter
LDFLAGS = -L lib/gamacon -L lib/my -L lib/xmlparser -L lib/quadtree\
-lgamacon -lxmlparser -lquadtree -lmy -lcsfml-system -lcsfml-graphics -lcsfml-audio -lcsfml-window -lm
LDFLAGS = -L lib/gamacon -L lib/my -L lib/xmlparser -L lib/quadtree \
-lgamacon -lxmlparser -lquadtree -lmy -lcsfml-system -lcsfml-graphics -lcsfml-audio -lcsfml-window -lm
NAME = my_rpg
@@ -72,4 +61,4 @@ dbg: clean $(OBJ)
$(MAKE) -C lib/quadtree dbg
$(CC) -o $(NAME) $(OBJ) $(LDFLAGS)
.PHONY: all build clean fclean ffclean
.PHONY: all build clean fclean ffclean dbg re
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 468 B

-26
View File
@@ -1,26 +0,0 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_COMPONENT_C_
#define _TEAMS_COMPONENT_H_
#include "component.h"
typedef enum display_type
{
HAPPINESS_DISPLAY,
STUPIDITY_DISPLAY,
SELECT_TILE_DISPLAY
} display_type_enum;
struct game_display
{
gc_component base;
display_type_enum type;
};
const struct game_display game_display;
const struct gc_system game_display_system;
#endif //_TEAMS_COMPONENT_C_
-2
View File
@@ -10,8 +10,6 @@
struct game_manager
{
gc_component base;
int happiness;
int stupidity;
};
const struct game_manager game_manager;
@@ -1,28 +0,0 @@
//
// Created by anonymus-raccoon on 3/10/20.
//
#ifndef _MAP_MANAGER_COMPONENT_H_
#define _MAP_MANAGER_COMPONENT_H_
#include "component.h"
enum brush
{
MOVE,
RESET,
ROTATE,
TEXTURE
};
struct map_manager_component
{
gc_component base;
bool tile_mode;
enum brush brush;
void *selected_texture;
};
const struct map_manager_component map_manager_component;
#endif //_MAP_MANAGER_COMPONENT_H_
-25
View File
@@ -1,25 +0,0 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_COMPONENT_C_
#define _TEAMS_COMPONENT_H_
#include "component.h"
struct teams_component
{
gc_component base;
float next_teams;
float delay;
char **prefabs;
int *prefabs_size;
int prefab_count;
};
const struct teams_component teams_component;
bool teams_move_up(gc_scene *scene, float amount, float y_level);
void pm_clicked(gc_engine *engine, gc_entity *entity);
#endif //_TEAMS_COMPONENT_C_
-28
View File
@@ -1,28 +0,0 @@
/*
** EPITECH PROJECT, 2020
** Gamacon
** File description:
** map_interactions
*/
#ifndef MY3D_MAP_INTERACTIONS_H
#define MY3D_MAP_INTERACTIONS_H
#include "engine.h"
#include "components/vertex_component.h"
#include "keybindings.h"
enum modes_on_tile {
VERTEX_0 = 2,
VERTEX_1 = 4,
VERTEX_2 = 8,
VERTEX_3 = 16,
ALL_VERTICES = 30,
INVERT_ADD_VALUE = 1
};
bool map_onclick(gc_engine *engine, gc_entity *entity, gc_vector2 pos, \
enum gc_mousekeys key);
#endif //MY3D_MAP_INTERACTIONS_H
+1 -9
View File
@@ -27,12 +27,4 @@ bool fullscreen(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool resolution_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool resolution_up(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool framerate_up(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool framerate_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool tile_select(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool vertex_select(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool up_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool reset(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool rotate(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool switch_texture(gc_engine *engine, gc_entity *entity, gc_vector2 _);
bool framerate_down(gc_engine *engine, gc_entity *entity, gc_vector2 _);
-12
View File
@@ -1,12 +0,0 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_SYSTEM_H_
#define _TEAMS_SYSTEM_H_
#include "system.h"
const gc_system teams_system;
#endif //_TEAMS_SYSTEM_H_
-17
View File
@@ -1,17 +0,0 @@
//
// Created by anonymus-raccoon on 3/9/20.
//
#ifndef _TEAMS_H_
#define _TEAMS_H_
#include <stdbool.h>
#include "engine.h"
bool absent_check(gc_engine *engine, int entity_id, gc_vector2 _);
bool absent_cross(gc_engine *engine, int entity_id, gc_vector2 _);
bool forgot_lmfao(gc_engine *engine, int entity_id, gc_vector2 _);
bool forgot_ok(gc_engine *engine, int entity_id, gc_vector2 _);
#endif //_TEAMS_H_
-40
View File
@@ -5,14 +5,6 @@
<sprite name="cross" src="assets/ui/cross.png" />
<sprite name="front_panel" src="assets/ui/front_panel.png" />
<sprite name="button_background" src="assets/ui/button_background.png" />
<sprite name="happiness" src="assets/ui/happiness.png" />
<sprite name="clown" src="assets/ui/clown.png" />
<sprite name="tile_select" src="assets/ui/tile_select.png" />
<sprite name="vertex_select" src="assets/ui/vertex_select.png" />
<sprite name="up_down" src="assets/ui/up_down.png" />
<sprite name="reset" src="assets/ui/reset.png" />
<sprite name="rotate" src="assets/ui/rotate.png" />
<sprite name="texture" src="assets/ui/texture.png" />
<sprite name="cobblestone" src="assets/sprites/cobblestone.png" />
<sprite name="comparator_on" src="assets/sprites/comparator_on.png" />
<sprite name="mossy_cobblestone" src="assets/sprites/cobblestone_mossy.png" />
@@ -35,8 +27,6 @@
<gc_entities>
<camera x="0" y="0" />
<gc_entity>
<clickable_component click="map_manage_click"/>
<map_manager_component />
<transform_component>
<Position x="0" y="300" />
<Size x="100000000" y="100000000" />
@@ -49,36 +39,6 @@
<gc_entity>
<game_manager happiness="50%" stupidity="0%" />
<teams_component delay="10">
<prefab src="prefabs/teams/forgot_register.gcprefab" height="20%" />
<prefab src="prefabs/teams/absent.gcprefab" height="20%" />
</teams_component>
</gc_entity>
<panel src="panel" x="7%" y="3%" width="37%" height="6%"/>
<button sprite="tile_select" x="3%" y="3%" width="%" height="3%" tooltip="Select a tile." tooltip_x="5" tooltip_y="-5" size="15" click="tile_select" />
<button sprite="vertex_select" x="7%" y="3%" width="%" height="3%" tooltip="Select a Vertex." tooltip_y="-5" size="15" click="vertex_select" />
<button sprite="up_down" x="12%" y="3%" width="%" height="3%" tooltip="Move a tiles.\n - Up with left click.\n - Down with right click" tooltip_y="-15" size="15" click="up_down" />
<button sprite="reset" x="15%" y="3%" width="%" height="3%" tooltip="Reset the height of a tile." tooltip_y="-5" size="15" click="reset" />
<button sprite="rotate" x="19%" y="3%" width="%" height="3%" tooltip="Rotate a texture" tooltip_y="-5" size="15" click="rotate" />
<button sprite="texture" x="23%" y="3%" width="%" height="3%" tooltip="Change the texture of a tile" tooltip_y="-5" size="15" click="texture" />
<panel src="panel" x="30%" y="3%" width="%" height="6%"/>
<button sprite="texture" x="30%" y="3%" width="%" height="3%" tooltip="Select the texture to draw." tooltip_y="-5" size="15" click="switch_texture">
<game_display stats="selected_tile" />
</button>
<panel src="panel" x="100%" y="50%" width="50%" height="120%"/>
<text text="TEAMS" x="88%" y="40"/>
<panel src="panel" x="50%" y="98%" width="120%" height="4%"/>
<panel src="happiness" x="3%" y="98%" width="%" height="3%"/>
<text text="100%" x="6%" y="98%" size="13" tooltip="The level of happiness of your students.\n" padding_x="17" tooltip_x="10" tooltip_y="5">
<game_display stats="happiness" />
</text>
<panel src="clown" x="10%" y="98%" width="%" height="3%" />
<text text="100%" x="13%" y="98%" size="13" tooltip="The level of stupidity of your students.\nThey start doing stupid things if you'are too kind with them.\n\nYou will loose if this stat reach 100%" padding_x="17" tooltip_x="10" tooltip_y="5">
<game_display stats="stupidity" />
</text>
</gc_entities>
</gc_scene>
+1 -1
View File
@@ -7,7 +7,7 @@
<gc_entities>
<camera x="0" y="0" />
<panel src="panel" x="50%" y="45%" width="300" height="69%"/>
<text text="Forcast Village" x="50%" y="25%" resize="false"/>
<text text="Forecasting Village" x="50%" y="25%" resize="false"/>
<button text="Start Game" x="50%" y="50%" click="start_button" color="black" width="200" resize="false" />
<button text="Options" x="50%" y="61%" click="options" color="black" width="200" resize="false" />
<button text="Quit game" x="50%" y="72%" click="quit" color="black" width="200" resize="false" />
-6
View File
@@ -1,6 +0,0 @@
<gc_entities>
<panel src="front_panel" x="89%" y="80%" width="20%" height="8%" tag="teams" />
<text text="I was absent today at the talk.\nCould you set my status as present?" x="89%" y="82%" color="black" size="9" tag="teams" />
<button sprite="check" x="85%" y="85%" width="3%" height="%" click="absent_check" tag="teams" />
<button sprite="cross" x="93%" y="85%" width="3%" height="%" click="absent_cross" tag="teams" />
</gc_entities>
-6
View File
@@ -1,6 +0,0 @@
<gc_entities>
<panel src="front_panel" x="89%" y="80%" width="20%" height="8%" tag="teams" />
<text text="I forgot to register for the module,\n could you register me?" x="89%" y="82%" color="black" size="9" tag="teams" />
<button sprite="front_panel" text="LMFAO" color="black" size="9" x="89%" y="86%" width="17%" height="5%" click="forgot_lmfao" tag="teams" />
<button sprite="front_panel" text="It's the first and the last time." color="black" size="9" x="89%" y="90%" width="17%" height="5%" click="forgot_ok" tag="teams" />
</gc_entities>
-71
View File
@@ -1,71 +0,0 @@
/*
** EPITECH PROJECT, 2020
** DPR
** File description:
** game_stats
*/
#include <components/renderer.h>
#include <text.h>
#include "dpr_errors.h"
#include "xml.h"
#include "component.h"
#include "utility.h"
#include "components/game_display.h"
#include <malloc.h>
static void ctr(void *component, va_list args)
{
struct game_display *cmp = (struct game_display *)component;
cmp->type = va_arg(args, display_type_enum);
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct game_display *cmp = (struct game_display *)component;
struct renderer *rend = GETCMP(entity, renderer);
char *display_type = xml_gettempprop(n, "stats");
if (!my_strcmp(display_type, "selected_tile")) {
cmp->type = SELECT_TILE_DISPLAY;
return;
}
if (!my_strcmp(display_type, "happiness"))
cmp->type = HAPPINESS_DISPLAY;
else
cmp->type = STUPIDITY_DISPLAY;
if (!rend || rend->type != GC_TXTREND) {
my_printf("Using a game display without a text renderer.\n");
return;
}
((gc_text *)rend->data)->text = malloc(sizeof(char) * 10);
if (((gc_text *)rend->data)->text)
((gc_text *)rend->data)->text[0] = '\0';
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct game_display game_display = {
base: {
name: "game_display",
size: sizeof(struct game_display),
dependencies: (char *[]) {
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
}
};
+1 -7
View File
@@ -5,7 +5,7 @@
** game_stats
*/
#include "dpr_errors.h"
#include "errors_str.h"
#include "xml.h"
#include "component.h"
#include "utility.h"
@@ -14,17 +14,11 @@
static void ctr(void *component, va_list args)
{
struct game_manager *cmp = (struct game_manager *)component;
cmp->happiness = va_arg(args, int);
cmp->stupidity = va_arg(args, int);
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct game_manager *cmp = (struct game_manager *)component;
cmp->happiness = xml_getintprop(n, "happiness");
cmp->stupidity = xml_getintprop(n, "stupidity");
if (scene->get_entity_by_cmp(scene, "game_manager"))
my_printf(MULTIPLE_GAME_MGR_ERROR);
}
-58
View File
@@ -1,58 +0,0 @@
/*
** EPITECH PROJECT, 2020
** My3D
** File description:
** map_manager_component
*/
#include <components/isometry/map_manager_component.h>
#include "engine.h"
#include "entity.h"
#include "xml.h"
#include "my.h"
static void ctr(void *comp, va_list args)
{
struct map_manager_component *cmp = (struct map_manager_component *)comp;
cmp->tile_mode = true;
cmp->brush = MOVE;
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *comp, node *n)
{
struct map_manager_component *cmp = (struct map_manager_component *)comp;
void **data = scene->get_data(scene, "tiles", NULL);
cmp->tile_mode = true;
cmp->brush = MOVE;
if (data)
cmp->selected_texture = data[0];
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct map_manager_component map_manager_component = {
base: {
name: "map_manager_component",
size: sizeof(struct map_manager_component),
dependencies: (char *[]){
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
}
};
-69
View File
@@ -1,69 +0,0 @@
/*
** EPITECH PROJECT, 2020
** Twac
** File description:
** camera_follow
*/
#include "xml.h"
#include "component.h"
#include "components/teams_component.h"
#include "utility.h"
#include <stdlib.h>
static void ctr(void *component, va_list args)
{
struct teams_component *cmp = (struct teams_component *)component;
cmp->delay = va_arg(args, double);
cmp->next_teams = cmp->delay;
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct teams_component *cmp = (struct teams_component *)component;
cmp->delay = xml_getfloatprop(n, "delay");
cmp->next_teams = cmp->delay;
cmp->prefab_count = xml_getchildcount_filtered(n, "prefab");
cmp->prefabs = malloc(sizeof(char *) * cmp->prefab_count);
cmp->prefabs_size = malloc(sizeof(int) * cmp->prefab_count);
n = n->child;
if (!cmp->prefabs || !cmp->prefab_count) {
cmp->prefabs = NULL;
cmp->prefabs_size = NULL;
cmp->prefab_count = 0;
return;
}
for (int i = 0; i < cmp->prefab_count; i++) {
cmp->prefabs[i] = xml_getproperty(n, "src");
cmp->prefabs_size[i] = xml_getintprop(n, "height");
n = n->next;
}
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct teams_component teams_component = {
base: {
name: "teams_component",
size: sizeof(struct teams_component),
dependencies: (char *[]) {
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
}
};
+1 -24
View File
@@ -7,16 +7,10 @@
#include "engine.h"
#include "setup.h"
#include "components/teams_component.h"
#include "components/isometry/map_manager_component.h"
#include "systems/teams_system.h"
#include <SFML/System.h>
#include "teams.h"
#include "callbacks.h"
#include "components/game_display.h"
#include "components/game_manager.h"
#include "systems/game_manager_system.h"
#include "map_interactions.h"
#include "my.h"
const struct callback callbacks[] = {
@@ -25,37 +19,20 @@ const struct callback callbacks[] = {
{"goto_main_menu", &goto_main_menu},
{"quit", &quit},
{"fullscreen", &fullscreen},
{"map_manage_click", &map_onclick},
{"resolution_down", &resolution_down},
{"resolution_up", &resolution_up},
{"framerate_up", &framerate_up},
{"framerate_down", &framerate_down},
{"absent_check", &absent_check},
{"absent_cross", &absent_cross},
{"forgot_lmfao", &forgot_lmfao},
{"forgot_ok", &forgot_ok},
{"catch", &catch},
{"toggle_pause", &toggle_pause},
{"toggle_pause", &toggle_pause},
{"tile_select", &tile_select},
{"vertex_select", &vertex_select},
{"up_down", &up_down},
{"reset", &reset},
{"rotate", &rotate},
{"texture", &texture},
{"switch_texture", &switch_texture},
{NULL, NULL}
};
int register_customcmps(gc_engine *engine)
{
engine->add_component(engine, &map_manager_component);
engine->add_component(engine, &game_manager);
engine->add_system(engine, new_system(&game_manager_system, engine));
engine->add_component(engine, &game_display);
engine->add_system(engine, &game_display_system);
engine->add_component(engine, &teams_component);
engine->add_system(engine, &teams_system);
engine->finish_physics(engine);
for (int i = 0; callbacks[i].func; i++)
engine->add_callback(engine, my_strdup(callbacks[i].name), \
@@ -80,7 +57,7 @@ int start_game(void)
gc_engine *engine = engine_create();
sfClock *clock = sfClock_create();
if (!engine || engine_use_sfml(engine, "DPR tycoon", 60) < 0)
if (!engine || engine_use_sfml(engine, "Forecasting village", 60) < 0)
return (ERROR);
if (create_game_scene(engine) < 0)
return (ERROR);
-71
View File
@@ -1,71 +0,0 @@
/*
** EPITECH PROJECT, 2020
** Gamacon
** File description:
** map_interactions
*/
#include "map_interactions.h"
#include "components/clickable_component.h"
#include "entity.h"
#include "my.h"
#include <math.h>
#include "components/transform_component.h"
#include "map_utils.h"
#include <stdlib.h>
#include "components/isometry/map_manager_component.h"
void click_tile(gc_engine *engine, struct map_manager_component *manager, \
struct tile *ret, bool is_left)
{
bool r = manager->brush == RESET;
switch (manager->brush) {
case ROTATE:
ret->data = (ret->data + (is_left ? 1 : -1U)) % 4;
break;
case TEXTURE:
ret->texture = manager->selected_texture;
break;
case MOVE:
case RESET:
move_verticies(engine, ret, ALL_VERTICES | is_left, r);
break;
}
}
bool map_onclick(gc_engine *engine, gc_entity *entity, gc_vector2 pos, \
enum gc_mousekeys key)
{
struct vertex_component *map = GETCMP(entity, vertex_component);
struct map_manager_component *m = GETCMP(entity, map_manager_component);
struct transform_component *tc = GETCMP(entity, transform_component);
struct tile *t = get_tile_from_pos(map, gc_vector2_add(pos, tc->position));
bool r;
int ind;
if (!map || !m) {
my_printf("map not found\n");
return (false);
}
r = m->brush == RESET;
if (!t)
return (false);
if (m->tile_mode)
click_tile(engine, m, t, key == GC_LEFT);
else {
ind = get_index_nearest_vertex(t, gc_vector2_add(pos, tc->position));
move_verticies(engine, t, (int)pow(2, ind + 1) | (key == GC_LEFT), r);
}
return (false);
}
void move_verticies(gc_engine *engine, struct tile *ret, char mode, bool r)
{
int val = (mode & INVERT_ADD_VALUE) ? ADD_VALUE : -ADD_VALUE;
for (int i = 0; i < 4; i++) {
if (mode & (int)pow(2, i + 1))
ret->corners[i]->z += (r) ? -ret->corners[i]->z : val;
}
}
-82
View File
@@ -1,82 +0,0 @@
/*
** EPITECH PROJECT, 2020
** Gamacon
** File description:
** tile collision_managment
*/
#include "tile_collision_manager.h"
#include "map_utils.h"
#include <math.h>
#define INF 10000
bool is_on_segment(gc_vector2 p, gc_vector2 q, gc_vector2 r)
{
if (q.x <= fmaxf(p.x, r.x) && q.x >= fminf(p.x, r.x) && \
q.y <= fmaxf(p.y, r.y) && q.y >= fminf(p.y, r.y))
return (true);
return (false);
}
int orientation(gc_vector2 p, gc_vector2 q, gc_vector2 r)
{
int tmp = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
if (tmp == 0)
return (0);
return ((tmp > 0) ? 1 : 2);
}
bool gc_vector2_do_intersect(gc_vector2 p1, gc_vector2 q1, \
gc_vector2 p2, gc_vector2 q2)
{
int o1 = orientation(p1, q1, p2);
int o2 = orientation(p1, q1, q2);
int o3 = orientation(p2, q2, p1);
int o4 = orientation(p2, q2, q1);
if (o1 != o2 && o3 != o4)
return (true);
if (o1 == 0 && is_on_segment(p1, p2, q1))
return (true);
if (o2 == 0 && is_on_segment(p1, q2, q1))
return (true);
if (o3 == 0 && is_on_segment(p2, p1, q2))
return (true);
if (o4 == 0 && is_on_segment(p2, q1, q2))
return (true);
return (false);
}
bool is_point_in_polygon(gc_vector2 *polygon, int n, gc_vector2 p)
{
gc_vector2 segment = {-INF, p.y};
int count = 0;
int next = 0;
int i = 0;
if (n < 3)
return (false);
do {
next = (i + 1) % n;
if (gc_vector2_do_intersect(polygon[i], polygon[next], p, segment)) {
if (orientation(polygon[i], p, polygon[next]) == 0)
return (is_on_segment(polygon[i], p, polygon[next]));
count++;
}
i = next;
} while (i != 0);
return (count & 1);
}
bool is_pos_in_tile(gc_vector2 pos, struct tile *tile)
{
struct vertex **c = tile->corners;
gc_vector2 corners[4];
pos.y *= -1;
for (int i = 0; i < 4; i++)
corners[i] = gc_vector2_from_coords(c[i]->x, c[i]->y, c[i]->z);
return (is_point_in_polygon(corners, 4, pos));
}
-37
View File
@@ -1,37 +0,0 @@
/*
** EPITECH PROJECT, 2020
** My3D
** File description:
** selectors
*/
#include <stdbool.h>
#include <components/isometry/map_manager_component.h>
#include "engine.h"
#include "entity.h"
bool tile_select(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
manager->tile_mode = true;
return (true);
}
bool vertex_select(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
manager->tile_mode = false;
return (true);
}
-69
View File
@@ -1,69 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** teams_system
*/
#include "entity.h"
#include "system.h"
#include <stddef.h>
#include "components/game_display.h"
#include "components/game_manager.h"
#include "components/isometry/map_manager_component.h"
#include "text.h"
#include "components/renderer.h"
#include <malloc.h>
#include "sprite.h"
void display_current_texture(gc_scene *scene, struct renderer *rend)
{
gc_list *li = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *map;
if (!li)
return;
map = GETCMP(li->data, map_manager_component);
((gc_sprite *)rend->data)->texture = map->selected_texture;
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
struct game_display *disp = GETCMP(entity, game_display);
struct renderer *rend = GETCMP(entity, renderer);
struct game_manager *manager;
gc_scene *scene = engine->scene;
gc_list *entities = scene->get_entity_by_cmp(scene, "game_manager");
if (!entities)
return;
manager = GETCMP(entities->data, game_manager);
if (disp->type == SELECT_TILE_DISPLAY && rend->type == GC_TEXTUREREND){
display_current_texture(scene, rend);
return;
}
if (rend->type != GC_TXTREND)
return;
if (disp->type == HAPPINESS_DISPLAY)
sprintf(((gc_text *)rend->data)->text, "%d%%", manager->happiness);
else
sprintf(((gc_text *)rend->data)->text, "%d%%", manager->stupidity);
}
static void destroy(void *system)
{
(void)system;
}
const gc_system game_display_system = {
name: "game_display_system",
component_name: "game_display",
size: sizeof(gc_system),
ctr: NULL,
dtr: NULL,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
destroy: &destroy
};
-19
View File
@@ -42,25 +42,6 @@ static void key_pressed(gc_engine *engine, va_list args)
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
struct game_manager *manager = GETCMP(entity, game_manager);
struct sfml_renderer_system *rend = GETSYS(engine, sfml_renderer_system);
gc_scene *gameover_scene = NULL;
if (manager->happiness <= 0)
gameover_scene = scene_create(engine, "prefabs/go/happiness.gcprefab");
if (manager->stupidity >= 100)
gameover_scene = scene_create(engine, "prefabs/go/stupidity.gcprefab");
if (gameover_scene)
engine->change_scene(engine, gameover_scene);
if (engine->is_keypressed(sfKeyLeft))
sfView_move(rend->view, (sfVector2f){-10, 0});
if (engine->is_keypressed(sfKeyRight))
sfView_move(rend->view, (sfVector2f){10, 0});
if (engine->is_keypressed(sfKeyDown))
sfView_move(rend->view, (sfVector2f){0, 10});
if (engine->is_keypressed(sfKeyUp))
sfView_move(rend->view, (sfVector2f){0, -10});
}
static void ctr(void *system, va_list list)
-94
View File
@@ -1,94 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** teams_system
*/
#include "entity.h"
#include "system.h"
#include "prefab.h"
#include "components/teams_component.h"
#include <stddef.h>
#include <stdlib.h>
#include "components/tag_component.h"
#include "components/fixed_to_cam_component.h"
#include "components/game_manager.h"
#include "my.h"
void pm_destroy(gc_scene *scene, int prefab_id)
{
for (gc_list *ent = scene->entities; ent; ent = ent->next)
if (((gc_entity *)ent->data)->prefab_id == prefab_id)
((gc_entity *)ent->data)->destroy(ent->data, scene);
}
void pm_clicked(gc_engine *engine, gc_entity *entity)
{
float y_pos = GETCMP(entity, fixed_to_cam)->pos.y;
pm_destroy(engine->scene, entity->prefab_id);
teams_move_up(engine->scene, -15, y_pos);
}
bool teams_move_up(gc_scene *scene, float amount, float y_level)
{
gc_list *list = scene->get_entity_by_cmp(scene, "tag_component");
struct fixed_to_cam *fc;
struct tag_component *tc;
int pm_to_destroy = -1;
for (; list; list = list->next) {
tc = GETCMP(list->data, tag_component);
if (my_strcmp(tc->tag, "teams"))
continue;
fc = GETCMP(list->data, fixed_to_cam);
if (!fc || fc->pos.y > y_level)
continue;
fc->pos.y -= amount;
if (fc->pos.y < 15)
pm_to_destroy = ((gc_entity *)list->data)->prefab_id;
}
if (pm_to_destroy != -1)
pm_destroy(scene, pm_to_destroy);
return (pm_to_destroy != -1);
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
struct teams_component *team = GETCMP(entity, teams_component);
struct game_manager *manager = GETCMP(entity, game_manager);
int index;
if (!manager) {
my_printf("No game manager found. Teams is disabled.\n");
return;
}
if (engine->scene->is_paused)
return;
team->next_teams -= dtime;
if (team->next_teams < 0 && team->prefab_count) {
index = random() % team->prefab_count;
team->next_teams = team->delay;
if (teams_move_up(engine->scene, team->prefabs_size[index], 1000))
manager->happiness -= 10;
prefab_load(engine, team->prefabs[index]);
}
}
static void destroy(void *system)
{
(void)system;
}
const gc_system teams_system = {
name: "teams_system",
component_name: "teams_component",
size: sizeof(gc_system),
ctr: NULL,
dtr: NULL,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
destroy: &destroy
};
-38
View File
@@ -1,38 +0,0 @@
/*
** EPITECH PROJECT, 2020
** My3D
** File description:
** absent
*/
#include <stdbool.h>
#include "components/game_manager.h"
#include <stdlib.h>
#include "components/teams_component.h"
#include "engine.h"
bool absent_check(gc_engine *engine, gc_entity *entity)
{
gc_scene *scene = engine->scene;
gc_list *li = scene->get_entity_by_cmp(scene, "game_manager");
if (!li)
return (false);
GETCMP(li->data, game_manager)->happiness += 3;
GETCMP(li->data, game_manager)->stupidity += random() % 5;
pm_clicked(engine, entity);
return (true);
}
bool absent_cross(gc_engine *engine, gc_entity *entity)
{
gc_scene *scene = engine->scene;
gc_list *li = scene->get_entity_by_cmp(scene, "game_manager");
if (!li)
return (false);
GETCMP(li->data, game_manager)->happiness -= 3;
GETCMP(li->data, game_manager)->stupidity -= random() % 5;
pm_clicked(engine, entity);
return (true);
}
-37
View File
@@ -1,37 +0,0 @@
/*
** EPITECH PROJECT, 2020
** My3D
** File description:
** forgot
*/
#include <stdbool.h>
#include "components/game_manager.h"
#include "components/teams_component.h"
#include "engine.h"
bool forgot_lmfao(gc_engine *engine, gc_entity *entity)
{
gc_scene *scene = engine->scene;
gc_list *li = scene->get_entity_by_cmp(scene, "game_manager");
if (!li)
return (false);
GETCMP(li->data, game_manager)->happiness -= 5;
GETCMP(li->data, game_manager)->stupidity -= 5;
pm_clicked(engine, entity);
return (true);
}
bool forgot_ok(gc_engine *engine, gc_entity *entity)
{
gc_scene *scene = engine->scene;
gc_list *li = scene->get_entity_by_cmp(scene, "game_manager");
if (!li)
return (false);
GETCMP(li->data, game_manager)->happiness += 2;
GETCMP(li->data, game_manager)->stupidity += 6;
pm_clicked(engine, entity);
return (true);
}
-83
View File
@@ -1,83 +0,0 @@
/*
** EPITECH PROJECT, 2020
** My3D
** File description:
** toolbar
*/
#include <stdbool.h>
#include <components/isometry/map_manager_component.h>
#include <utility.h>
#include "engine.h"
#include "entity.h"
bool up_down(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
manager->brush = MOVE;
return (true);
}
bool reset(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
manager->brush = RESET;
return (true);
}
bool rotate(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
manager->brush = ROTATE;
return (true);
}
bool texture(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
manager->brush = TEXTURE;
return (true);
}
bool switch_texture(gc_engine *engine, gc_entity *entity, gc_vector2 _)
{
gc_scene *scene = engine->scene;
gc_list *list = scene->get_entity_by_cmp(scene, "map_manager_component");
struct map_manager_component *manager;
void **data = scene->get_data(scene, "tiles", NULL);
static int index = 0;
void *next = NULL;
if (!list)
return (false);
manager = GETCMP(list->data, map_manager_component);
index++;
if (data)
next = data[index % (arraylen(data) - 1)];
manager->selected_texture = next;
return (true);
}