Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Filename: system_follow_player.c |
3 |
|
|
* Path: sources/System |
4 |
|
|
* Created Date: Thursday, September 28th 2023, 3:01:43 pm |
5 |
|
|
* Author: osvegn |
6 |
|
|
* |
7 |
|
|
* Copyright (c) 2023 our_rpg |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include "systems.h" |
11 |
|
|
#include "components.h" |
12 |
|
|
#include "vector.h" |
13 |
|
|
#include "world_resource.h" |
14 |
|
|
#include "resources.h" |
15 |
|
|
#include <raylib.h> |
16 |
|
|
|
17 |
|
✗ |
int system_follow_player_constructor(system_t *system) |
18 |
|
|
{ |
19 |
|
✗ |
system->type = S_FOLLOW_PLAYER; |
20 |
|
✗ |
system->run = &system_follow_player; |
21 |
|
✗ |
system->active = true; |
22 |
|
✗ |
return 0; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
✗ |
int system_follow_player(void *world) |
26 |
|
|
{ |
27 |
|
✗ |
vector_t entities = {0}; |
28 |
|
✗ |
int rvalue = world_join_entities(world, &entities, 1, C_CONTROLLABLE); |
29 |
|
✗ |
resource_t *camera = world_get_resource_by_type(world, R_CAMERA); |
30 |
|
✗ |
Camera2D *cam = camera->data; |
31 |
|
✗ |
entity_t *e = *(entity_t **)entities.at(&entities, 0); |
32 |
|
✗ |
ecs_vector2f_t *pos = entity_get_component(e, C_POSITION)->data; |
33 |
|
✗ |
ecs_vector2i_t *size = entity_get_component(e, C_SIZE)->data; |
34 |
|
|
|
35 |
|
✗ |
cam->target.x = pos->x + size->x / 2; |
36 |
|
✗ |
cam->target.y = pos->y + size->y / 2; |
37 |
|
✗ |
resource_camera_set(camera, cam); |
38 |
|
✗ |
return 0; |
39 |
|
|
} |
40 |
|
|
|