mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-06-04 11:15:11 +00:00
Adding a movable block of dirt
This commit is contained in:
+9
-7
@@ -15,10 +15,12 @@ include_directories(lib/xmlparser/include)
|
||||
add_executable(my_rpg
|
||||
include/my.h
|
||||
include/setup.h
|
||||
lib/gamacon/include/components/controllers/keyboard_controller.h
|
||||
include/components/controllers/keyboard_controller.h
|
||||
lib/gamacon/include/components/camerafollow_component.h
|
||||
lib/gamacon/include/components/collision_component.h
|
||||
lib/gamacon/include/components/controllable_component.h
|
||||
include/components/controllable_component.h
|
||||
include/systems/map_movement_system.h
|
||||
include/systems/game_manager_system.h
|
||||
lib/gamacon/include/components/fixed_to_cam_component.h
|
||||
lib/gamacon/include/components/friction_component.h
|
||||
lib/gamacon/include/components/friction_giver.h
|
||||
@@ -27,7 +29,7 @@ add_executable(my_rpg
|
||||
lib/gamacon/include/components/renderer.h
|
||||
lib/gamacon/include/components/transform_component.h
|
||||
lib/gamacon/include/components/vertex_component.h
|
||||
lib/gamacon/include/systems/controllers/keyboard_controller_system.h
|
||||
include/systems/controllers/keyboard_controller_system.h
|
||||
lib/gamacon/include/systems/camerafollow_system.h
|
||||
lib/gamacon/include/systems/collision_system.h
|
||||
lib/gamacon/include/systems/friction_system.h
|
||||
@@ -54,14 +56,14 @@ add_executable(my_rpg
|
||||
lib/gamacon/include/utility.h
|
||||
lib/gamacon/include/vector2.h
|
||||
lib/gamacon/include/xml.h
|
||||
lib/gamacon/src/components/controllers/keyboard_controller.c
|
||||
src/components/controllers/keyboard_controller.c
|
||||
lib/gamacon/src/components/renderers/anim_renderer.c
|
||||
lib/gamacon/src/components/renderers/map_renderer.c
|
||||
lib/gamacon/src/components/renderers/sprite_renderer.c
|
||||
lib/gamacon/src/components/renderers/text_renderer.c
|
||||
lib/gamacon/src/components/camera_follow.c
|
||||
lib/gamacon/src/components/collision_component.c
|
||||
lib/gamacon/src/components/controllable_component.c
|
||||
src/components/controllable_component.c
|
||||
lib/gamacon/src/components/fixed_to_cam.c
|
||||
lib/gamacon/src/components/friction_component.c
|
||||
lib/gamacon/src/components/friction_giver.c
|
||||
@@ -89,7 +91,7 @@ add_executable(my_rpg
|
||||
lib/gamacon/src/sfml_renderer/sfml_music_player.c
|
||||
lib/gamacon/src/sfml_renderer/sfml_vertex.c
|
||||
lib/gamacon/src/sfml_renderer/texture_utility.c
|
||||
lib/gamacon/src/systems/controllers/keyboard_controller_system.c
|
||||
src/systems/controllers/keyboard_controller_system.c
|
||||
lib/gamacon/src/systems/camera_follow_system.c
|
||||
lib/gamacon/src/systems/collision_system.c
|
||||
lib/gamacon/src/systems/fixed_to_cam_pseudosystem.c
|
||||
@@ -244,7 +246,7 @@ add_executable(my_rpg
|
||||
src/framerate.c
|
||||
lib/gamacon/src/isometry/isometry.c
|
||||
lib/gamacon/include/isometry.h
|
||||
lib/gamacon/src/components/renderers/anim_utils.c)
|
||||
lib/gamacon/src/components/renderers/anim_utils.c src/components/map_movement.c include/components/map_movement.h src/systems/map_movement_system.c)
|
||||
|
||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ SRC = src/main.c \
|
||||
src/main_menu.c \
|
||||
src/options.c \
|
||||
src/systems/game_manager_system.c \
|
||||
src/components/game_manager.c
|
||||
src/components/game_manager.c \
|
||||
src/components/map_movement.c \
|
||||
src/systems/map_movement_system.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** movable_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
struct controllable_component
|
||||
{
|
||||
gc_component base;
|
||||
int movement_x;
|
||||
int movement_y;
|
||||
int move_callback;
|
||||
};
|
||||
|
||||
extern const struct controllable_component controllable_component;
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** keyboard_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
struct keyboard_controller
|
||||
{
|
||||
gc_component base;
|
||||
int left_key;
|
||||
int right_key;
|
||||
int up_key;
|
||||
int down_key;
|
||||
};
|
||||
|
||||
extern const struct keyboard_controller keyboard_controller;
|
||||
@@ -5,8 +5,7 @@
|
||||
** runner
|
||||
*/
|
||||
|
||||
#ifndef _TEAMS_COMPONENT_C_
|
||||
#define _TEAMS_COMPONENT_H_
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
@@ -16,5 +15,3 @@ struct game_manager
|
||||
};
|
||||
|
||||
const struct game_manager game_manager;
|
||||
|
||||
#endif //_TEAMS_COMPONENT_C_
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** map_movement.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MY_RPG_MAP_MOVEMENT_H
|
||||
#define MY_RPG_MAP_MOVEMENT_H
|
||||
|
||||
#include "component.h"
|
||||
|
||||
struct map_movement
|
||||
{
|
||||
gc_component base;
|
||||
};
|
||||
|
||||
const struct map_movement map_movement;
|
||||
|
||||
#endif //MY_RPG_MAP_MOVEMENT_H
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** texture_renderer_system
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "system.h"
|
||||
|
||||
extern const gc_system keyboard_controller_system;
|
||||
@@ -5,11 +5,11 @@
|
||||
** runner
|
||||
*/
|
||||
|
||||
#ifndef _GAME_MANAGER_SYSTEM_H_
|
||||
#define _GAME_MANAGER_SYSTEM_H_
|
||||
#ifndef _MAP_MOVEMENT_SYSTEM_H_
|
||||
#define _MAP_MOVEMENT_SYSTEM_H_
|
||||
|
||||
#include "system.h"
|
||||
|
||||
const gc_system game_manager_system;
|
||||
|
||||
#endif //_GAME_MANAGER_SYSTEM_H_
|
||||
#endif //_MAP_MOVEMENT_SYSTEM_H__
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** runner
|
||||
*/
|
||||
|
||||
#ifndef _GAME_MANAGER_SYSTEM_H_
|
||||
#define _GAME_MANAGER_SYSTEM_H_
|
||||
|
||||
#include "system.h"
|
||||
|
||||
const gc_system map_movement_system;
|
||||
|
||||
#endif //_GAME_MANAGER_SYSTEM_H_
|
||||
+1
-1
Submodule lib/gamacon updated: 146fbb43db...469eeeb144
+16
-2
@@ -13,6 +13,7 @@
|
||||
<sprite name="crafting_table" src="assets/sprites/crafting_table_top.png" />
|
||||
<sprite name="grass_top" src="assets/sprites/grass_top.png" />
|
||||
<sprite name="grass_side" src="assets/sprites/grass_side.png" />
|
||||
<sprite name="player" src="assets/sprites/grass_side.png" />
|
||||
<music src="assets/musics/music.ogg"/>
|
||||
<font src="assets/fonts/roboto.ttf" />
|
||||
|
||||
@@ -25,7 +26,6 @@
|
||||
</tiles>
|
||||
</data>
|
||||
<gc_entities>
|
||||
<camera x="0" y="0" />
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="0" y="300" />
|
||||
@@ -38,7 +38,21 @@
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<game_manager happiness="50%" stupidity="0%" />
|
||||
<game_manager />
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="0" y="0" />
|
||||
<Size x="50" y="50" />
|
||||
</transform_component>
|
||||
<renderer src="player">
|
||||
<Rect height="auto" width="auto" top="0" left="0" />
|
||||
</renderer>
|
||||
<camerafollow_component/>
|
||||
<controllable_component />
|
||||
<keyboard_controller left="16" right="3" up="25" down="18" />
|
||||
<map_movement />
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
</gc_scene>
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** controllable_component
|
||||
*/
|
||||
|
||||
#include "xml.h"
|
||||
#include "component.h"
|
||||
#include "components/controllable_component.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void controllable_ctr(void *component, va_list args)
|
||||
{
|
||||
struct controllable_component *cmp = (struct controllable_component *)\
|
||||
component;
|
||||
|
||||
cmp->movement_x = 0;
|
||||
cmp->movement_y = 0;
|
||||
cmp->move_callback = 0;
|
||||
(void)args;
|
||||
}
|
||||
|
||||
static void controllable_fdctr(gc_entity *entity, gc_scene *scene, \
|
||||
void *component, node *n)
|
||||
{
|
||||
struct controllable_component *cmp = (struct controllable_component *)\
|
||||
component;
|
||||
|
||||
cmp->movement_x = 0;
|
||||
cmp->movement_y = 0;
|
||||
cmp->move_callback = 0;
|
||||
(void)scene;
|
||||
(void)entity;
|
||||
(void)n;
|
||||
}
|
||||
|
||||
static void controllable_dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *controllable_serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct controllable_component controllable_component = {
|
||||
base: {
|
||||
name: "controllable_component",
|
||||
size: sizeof(struct controllable_component),
|
||||
dependencies: (char *[]){
|
||||
"movable_component",
|
||||
"transform_component",
|
||||
NULL
|
||||
},
|
||||
ctr: &controllable_ctr,
|
||||
fdctr: &controllable_fdctr,
|
||||
dtr: &controllable_dtr,
|
||||
serialize: &controllable_serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** keyboard_controller
|
||||
*/
|
||||
|
||||
|
||||
#include "xml.h"
|
||||
#include "component.h"
|
||||
#include "components/controllable_component.h"
|
||||
#include "components/controllers/keyboard_controller.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct keyboard_controller *cmp = (struct keyboard_controller *)\
|
||||
component;
|
||||
|
||||
cmp->left_key = va_arg(args, int);
|
||||
cmp->right_key = va_arg(args, int);
|
||||
cmp->up_key = va_arg(args, int);
|
||||
cmp->down_key = va_arg(args, int);
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
struct keyboard_controller *cmp = (struct keyboard_controller *)\
|
||||
component;
|
||||
|
||||
cmp->left_key = xml_getintprop(n, "left");
|
||||
if (cmp->left_key == 0)
|
||||
cmp->left_key = xml_gettmpstring(n, "left", "")[0];
|
||||
cmp->right_key = xml_getintprop(n, "right");
|
||||
if (cmp->right_key == 0)
|
||||
cmp->right_key = xml_gettmpstring(n, "right", "")[0];
|
||||
cmp->up_key = xml_getintprop(n, "up");
|
||||
if (cmp->up_key == 0)
|
||||
cmp->up_key = xml_gettmpstring(n, "up", "")[0];
|
||||
cmp->down_key = xml_getintprop(n, "down");
|
||||
if (cmp->down_key == 0)
|
||||
cmp->down_key = xml_gettmpstring(n, "down", "")[0];
|
||||
(void)scene;
|
||||
(void)entity;
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct keyboard_controller keyboard_controller = {
|
||||
base: {
|
||||
name: "keyboard_controller",
|
||||
size: sizeof(struct keyboard_controller),
|
||||
dependencies: (char *[]){
|
||||
"transform_component",
|
||||
"controllable_component",
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** map_movement.c
|
||||
*/
|
||||
|
||||
|
||||
#include "components/map_movement.h"
|
||||
#include "xml.h"
|
||||
#include "component.h"
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct map_movement map_movement = {
|
||||
base: {
|
||||
name: "map_movement",
|
||||
size: sizeof(struct map_movement),
|
||||
dependencies: (char *[]) {
|
||||
"controllable_component",
|
||||
"transform_component",
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -8,6 +8,12 @@
|
||||
#include "engine.h"
|
||||
#include "setup.h"
|
||||
#include <SFML/System.h>
|
||||
#include "systems/map_movement_system.h"
|
||||
#include "systems/game_manager_system.h"
|
||||
#include "systems/controllers/keyboard_controller_system.h"
|
||||
#include "components/map_movement.h"
|
||||
#include "components/controllers/keyboard_controller.h"
|
||||
#include "components/controllable_component.h"
|
||||
#include "callbacks.h"
|
||||
#include "components/game_manager.h"
|
||||
#include "systems/game_manager_system.h"
|
||||
@@ -31,6 +37,11 @@ const struct callback callbacks[] = {
|
||||
|
||||
int register_customcmps(gc_engine *engine)
|
||||
{
|
||||
engine->add_component(engine, &controllable_component);
|
||||
engine->add_component(engine, &keyboard_controller);
|
||||
engine->add_component(engine, &map_movement);
|
||||
engine->add_system(engine, &map_movement_system);
|
||||
engine->add_system(engine, new_system(&keyboard_controller_system, engine));
|
||||
engine->add_component(engine, &game_manager);
|
||||
engine->add_system(engine, new_system(&game_manager_system, engine));
|
||||
engine->finish_physics(engine);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** movable_system
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
#include "system.h"
|
||||
#include "vector2.h"
|
||||
#include "components/movable_component.h"
|
||||
#include "components/controllable_component.h"
|
||||
#include "components/controllers/keyboard_controller.h"
|
||||
#include "components/renderer.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void keyboard_update_entity(gc_engine *engine, void *system, \
|
||||
gc_entity *entity, float dtime)
|
||||
{
|
||||
struct controllable_component *con = GETCMP(entity, controllable_component);
|
||||
struct keyboard_controller *key = GETCMP(entity, keyboard_controller);
|
||||
|
||||
con->movement_x = 0;
|
||||
con->movement_x += engine->is_keypressed(key->left_key);
|
||||
con->movement_x -= engine->is_keypressed(key->right_key);
|
||||
con->movement_y = 0;
|
||||
con->movement_y += engine->is_keypressed(key->down_key);
|
||||
con->movement_y -= engine->is_keypressed(key->up_key);
|
||||
(void)system;
|
||||
(void)dtime;
|
||||
}
|
||||
|
||||
|
||||
static void ctr(void *system, va_list args)
|
||||
{
|
||||
}
|
||||
|
||||
const gc_system keyboard_controller_system = {
|
||||
name: "keyboard_controller_system",
|
||||
component_name: "keyboard_controller",
|
||||
size: sizeof(gc_system),
|
||||
ctr: &ctr,
|
||||
dtr: NULL,
|
||||
check_dependencies: &system_check_dependencies,
|
||||
update_entity: &keyboard_update_entity,
|
||||
destroy: &system_destroy
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** map_movement_system.c
|
||||
*/
|
||||
|
||||
|
||||
#include <components/controllable_component.h>
|
||||
#include <components/transform_component.h>
|
||||
#include "map_utils.h"
|
||||
#include "system.h"
|
||||
|
||||
|
||||
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
|
||||
float dtime)
|
||||
{
|
||||
struct controllable_component *ctl = GETCMP(entity, controllable_component);
|
||||
struct transform_component *tra = GETCMP(entity, transform_component);
|
||||
struct vertext_component *map = GETSYS(engine, vertext_component);
|
||||
gc_vector2 move = gc_vector2_from_coords(ctl->movement_x, ctl->movement_y, 0);
|
||||
|
||||
if (ctl->move_callback <= 0) {
|
||||
tra->position.x += move.x;
|
||||
tra->position.y += move.y;
|
||||
ctl->move_callback = 10;
|
||||
}
|
||||
ctl->move_callback--;
|
||||
}
|
||||
|
||||
static void ctr(void *system, va_list list)
|
||||
{
|
||||
}
|
||||
|
||||
static void destroy(void *system)
|
||||
{
|
||||
}
|
||||
|
||||
const gc_system map_movement_system = {
|
||||
name: "map_movement_system",
|
||||
component_name: "map_movement",
|
||||
size: sizeof(gc_system),
|
||||
ctr: ctr,
|
||||
dtr: NULL,
|
||||
check_dependencies: &system_check_dependencies,
|
||||
update_entity: &update_entity,
|
||||
destroy: &destroy
|
||||
};
|
||||
Reference in New Issue
Block a user