add heading dir to input

efd/v1
Dominik Madarász 2023-02-02 17:22:05 +01:00
parent fc9997d4db
commit 8c288dc193
7 changed files with 23 additions and 5 deletions

View File

@ -3,13 +3,13 @@
#include "models/assets.h"
#define ecs_get_mut_ex(world, entity, T) \
(ECS_CAST(T*, world_component_cached(world, entity, ecs_id(T))))
(ECS_CAST(T*, ecs_get_mut(world, entity, T)))
#define ecs_get_if(world, entity, T) \
(world_entity_valid(entity) ? ecs_get(world, entity, T) : NULL)
#define ecs_get_mut_if_ex(world, entity, component) \
(ecs_get_if(world, entity, component) ? ecs_get_mut_ex(world, entity, component) : NULL)
(ecs_get_if(world, entity, component) ? ecs_get_mut(world, entity, component) : NULL)
#ifndef ecs_get_mut_if
#define ecs_get_mut_if(world, entity, component)\
@ -69,6 +69,8 @@ typedef struct {
float my;
float bx;
float by;
float hx;
float hy;
uint8_t use;
uint8_t sprint;
uint8_t ctrl;

View File

@ -19,12 +19,14 @@ uint64_t player_spawn(char *name) {
ecs_set_name(world_ecs(), e, name);
ecs_set(world_ecs(), e, ClientInfo, {0});
ecs_set(world_ecs(), e, Input, {0});
ecs_set(world_ecs(), e, Inventory, {0});
ecs_set(world_ecs(), e, Health, {.hp = PLAYER_MAX_HP, .max_hp = PLAYER_MAX_HP});
ecs_set(world_ecs(), e, HealthRegen, {.amt = 15.0f});
ecs_set(world_ecs(), e, Velocity, { 0 });
ecs_set(world_ecs(), e, PhysicsBody, { .kind = PHYS_AABB, .mass = INFINITE_MASS });
Input *i = ecs_get_mut(world_ecs(), e, Input);
*i = (Input){ 0 };
i->hx = 1.0f;
librg_entity_owner_set(world_tracker(), e, (int64_t)e);

View File

@ -63,6 +63,8 @@ int32_t pkt_send_keystate_handler(pkt_header *header) {
i->y = zpl_clamp(table.y, -1.0f, 1.0f);
i->mx = table.mx;
i->my = table.my;
i->hx = (i->x != 0.0f) ? i->x : i->hx;
i->hy = (i->y != 0.0f) ? i->y : i->hy;
i->use |= table.use;
i->sprint = table.sprint;
i->ctrl = table.ctrl;

View File

@ -15,7 +15,9 @@ pkt_desc pkt_entity_view_desc[] = {
{ PKT_UINT(entity_view, kind) },
{ PKT_UINT(entity_view, flag) },
{ PKT_HALF(entity_view, x) },
{ PKT_HALF(entity_view, y) },
{ PKT_HALF(entity_view, y) },
{ PKT_HALF(entity_view, hx) },
{ PKT_HALF(entity_view, hy) },
{ PKT_HALF(entity_view, angle) },
{ PKT_KEEP_IF(entity_view, blocks_used, 0, 2) }, // NOTE(zaklaus): skip velocity for chunks

View File

@ -53,6 +53,8 @@ typedef struct entity_view {
float vy;
float tx;
float ty;
float hx;
float hy;
float angle;
float hp;

View File

@ -87,6 +87,14 @@ entity_view* world_build_entity_view(int64_t e) {
view.frame = spr->frame;
}
{
const Input* in = ecs_get(world_ecs(), e, Input);
if (in) {
view.hx = in->hx;
view.hy = in->hy;
}
}
view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false;
Inventory* inv = 0;

View File

@ -103,7 +103,7 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr
DrawNametag("Player", key, data, x, y-16);
//DrawTextureRec(GetSpriteTexture2D(assets_find(ASSET_PLAYER)), ASSET_SRC_RECT(), (Vector2){data->x-(WORLD_BLOCK_SIZE/2), data->y-(WORLD_BLOCK_SIZE/2)}, ColorAlpha(WHITE, data->tran_time));
//DrawCircleEco(x, y, size, ColorAlpha(YELLOW, data->tran_time));
DrawSpriteEco(test_player_anim.spritesheet, TickSpriteAnimation(&test_player_anim), x, y, 0.0f, 2.0f, WHITE);
DrawSpriteEco(test_player_anim.spritesheet, TickSpriteAnimation(&test_player_anim), x, y, 0.0f, 2.0f, WHITE);
//if (data->has_items && !data->inside_vehicle) {
// float ix = data->x;