#include "v4k.h" enum { MAX_NPCS = 5 }; struct player_t { uint64_t seen_until; float x,y,z,angle; uint32_t color; }; struct npc_t { float x,y,z; uint32_t color; }; struct world_t { struct player_t player[MAX_CLIENTS]; struct npc_t npc[MAX_NPCS]; } world = {0}; void bind_netbuffers(int64_t self_id) { uint32_t colors[] = { ORANGE,GREEN,RED,CYAN,PURPLE,YELLOW,GRAY,PINK,AQUA }; for (int64_t i=0; ix,100,self->z); camera_lookat(&cam, vec3(self->x,0,self->z)); // input - move player float iy = input(KEY_UP) - input(KEY_DOWN); float ix = input(KEY_RIGHT) - input(KEY_LEFT); if( iy || ix ) { self->x += iy*window_delta()*15; self->z += ix*window_delta()*15; } self->seen_until = date_epoch() + 4; // npc - update npc movement on server-side if (self_id == 0) { for (int i = 0; i < MAX_NPCS; ++i) { struct npc_t *n = &world.npc[i]; n->z = sinf(window_time())*4.f; } } // background - draw grid ddraw_grid(0); // foreground - draw all players for( int id = 0; id < MAX_CLIENTS; ++id ) { struct player_t *p = &world.player[id]; if (p->seen_until < date_epoch()) continue; /* skip inactive players */ ddraw_color( p->color ); ddraw_capsule(vec3(p->x,0,p->z), vec3(p->x,2,p->z), 1); ddraw_text(vec3(p->x,4,p->z), 0.01, stringf("player #%d", id)); } for( int id = 0; id < MAX_NPCS; ++id ) { struct npc_t *p = &world.npc[id]; ddraw_color( p->color ); ddraw_capsule(vec3(p->x,0,p->z), vec3(p->x,2,p->z), 1); ddraw_text(vec3(p->x,4,p->z), 0.01, stringf("npc #%d", id)); } // stats char title[64]; sprintf(title, "player #%lld", self_id); window_title(title); } }