eco2d/code/game/src/player.c

36 lines
855 B
C
Raw Normal View History

2021-05-05 07:55:45 +00:00
#include "player.h"
2021-05-08 09:05:15 +00:00
#include "entity.h"
2021-07-27 15:57:50 +00:00
#include "entity_view.h"
2021-05-05 07:55:45 +00:00
#include "flecs/flecs.h"
#include "flecs/flecs_meta.h"
#include "librg.h"
2021-05-12 15:50:30 +00:00
#include "world/world.h"
2021-05-05 07:55:45 +00:00
2021-07-27 12:43:26 +00:00
#include "modules/components.h"
#include "modules/systems.h"
2021-05-06 18:24:01 +00:00
#include "zpl.h"
2021-05-05 07:55:45 +00:00
2021-07-27 16:34:31 +00:00
#define PLAYER_MAX_HP 100.0f
2021-05-08 09:05:15 +00:00
uint64_t player_spawn(char *name) {
2021-07-28 09:49:09 +00:00
ecs_entity_t e = entity_spawn(EKIND_PLAYER);
2021-05-06 18:24:01 +00:00
if (!name) {
name = zpl_bprintf("player_%d", e);
}
2021-05-08 09:05:15 +00:00
ecs_set_name(world_ecs(), e, name);
2021-08-09 15:18:34 +00:00
ecs_set(world_ecs(), e, ClientInfo, {0});
ecs_set(world_ecs(), e, Input, {0});
ecs_set(world_ecs(), e, Health, {.hp = PLAYER_MAX_HP, .max_hp = PLAYER_MAX_HP});
ecs_add(world_ecs(), e, Player);
2021-07-19 08:28:23 +00:00
2021-05-05 07:55:45 +00:00
librg_entity_owner_set(world_tracker(), e, (int64_t)e);
2021-07-19 08:28:23 +00:00
2021-05-05 07:55:45 +00:00
return (uint64_t)e;
}
void player_despawn(uint64_t ent_id) {
2021-07-26 15:53:18 +00:00
entity_despawn(ent_id);
2021-05-05 13:14:02 +00:00
}