X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=netwar.c;h=a3236f122f95dd8ff4a6d58c3dcee5668fd856ac;hb=0aebaa861295894d8bfd51ee7d02da0d4b63e477;hp=2419456d87d0dea2265c5f9e47422286359258ab;hpb=c4b04d12861ae0eac6315b1c2170013422136f80;p=netwar.git diff --git a/netwar.c b/netwar.c index 2419456..a3236f1 100644 --- a/netwar.c +++ b/netwar.c @@ -20,7 +20,7 @@ static const float ship[] = { static char * host = "localhost"; static char * nick = "Anonymous"; -static uint16_t port = DEFAULT_PORT; +static uint16_t port = PROTOCOL_PORT; static SDL_Window * window; static SDL_Renderer * renderer; @@ -110,22 +110,32 @@ static void paintwindow() { SDL_RenderDrawLines(renderer, pixship, count); } + for(int i = 0; i < MAX_BULLETS; i++) { + if(g_bullet[i].owner == cl_playerid) + SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0x00); + else + SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0x00); + + int x = g_bullet[i].x * WIDTH / 2; + int y = g_bullet[i].y * HEIGHT / 2; + + if(g_bullet[i].live) + SDL_RenderDrawPoint(renderer, cx + x, cy + y); + } + SDL_RenderPresent(renderer); } static void keyboardhandle() { SDL_PumpEvents(); const Uint8 * key = SDL_GetKeyboardState(NULL); - if(key[SDL_SCANCODE_UP]) - cl_move(DOES_UP); - if(key[SDL_SCANCODE_DOWN]) - cl_move(DOES_DOWN); - if(key[SDL_SCANCODE_LEFT]) - cl_move(DOES_LEFT); - if(key[SDL_SCANCODE_RIGHT]) - cl_move(DOES_RIGHT); - if(key[SDL_SCANCODE_LCTRL]) - cl_move(DOES_FIRE); + cl_move((DoesBits) { + .up = key[SDL_SCANCODE_UP], + .down = key[SDL_SCANCODE_DOWN], + .left = key[SDL_SCANCODE_LEFT], + .right = key[SDL_SCANCODE_RIGHT], + .fire = key[SDL_SCANCODE_LCTRL], + }); } int main(int argc, char ** argv) { @@ -135,23 +145,15 @@ int main(int argc, char ** argv) { cl_connect(host, port); - Uint32 lastTime = SDL_GetTicks(); - Uint32 currTime = SDL_GetTicks(); - - while(cl_isrun()) { + while(cl_playerid >= 0) { SDL_Event event; while(SDL_PollEvent(&event)) if(event.type == SDL_QUIT) goto cleanup; - if(currTime - lastTime >= TICK_DELAY) { - keyboardhandle(); - g_update(); - lastTime = SDL_GetTicks(); - } - currTime = SDL_GetTicks(); + keyboardhandle(); - cl_recv(); + cl_handle(); paintwindow();