GCC Code Coverage Report


Directory: ./
File: sources/System/system_move_controllable.c
Date: 2023-09-29 04:53:15
Exec Total Coverage
Lines: 0 21 0.0%
Branches: 0 12 0.0%

Line Branch Exec Source
1 /*
2 * Filename: system_move_controllable.c
3 * Path: sources/System
4 * Created Date: Saturday, September 16th 2023, 4:09:34 am
5 * Author: osvegn
6 *
7 * Copyright (c) 2023 our_rpg
8 */
9
10 #include "systems.h"
11 #include "raylib.h"
12 #include "vector.h"
13 #include "world.h"
14 #include "world_entity.h"
15 #include "components.h"
16
17 int system_move_controllable_constructor(system_t *system)
18 {
19 system->type = S_MOVE_CONTROLLABLE;
20 system->run = &system_move_controllable;
21 system->active = true;
22 return 0;
23 }
24
25 static int system_move_controllable(void *world)
26 {
27 vector_t entities = {0};
28 int rvalue = world_join_entities(world, &entities, 3, C_CONTROLLABLE, C_VELOCITY, C_SPEED);
29 ecs_vector2i_t movement = {0};
30 ecs_vector2i_t offset = {0};
31 entity_t *e = 0;
32 component_t *c_speed = 0;
33 component_t *c_velocity = 0;
34
35 if (rvalue <= 0)
36 return 0;
37 if (IsKeyDown(KEY_A))
38 offset.x = -1;
39 if (IsKeyDown(KEY_D))
40 offset.x = 1;
41 if (IsKeyDown(KEY_W))
42 offset.y = -1;
43 if (IsKeyDown(KEY_S))
44 offset.y = 1;
45 for (unsigned int i = 0; i < entities.size(&entities); i++) {
46 e = *(entity_t **)entities.at(&entities, i);
47 c_speed = entity_get_component(e, C_SPEED);
48 c_velocity = entity_get_component(e, C_VELOCITY);
49 movement.x = offset.x * *(int *){c_speed->data};
50 movement.y = offset.y * *(int *){c_speed->data};
51 component_velocity_set(c_velocity, &movement);
52 }
53 return 0;
54 }
55