X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=netwar.c;h=88ff5c7ba766b2e9f27bc044d45291ad23706da7;hb=0ce00cd1d7ade8d9f72a4b7f67154e82ed9079b6;hp=2419456d87d0dea2265c5f9e47422286359258ab;hpb=c4b04d12861ae0eac6315b1c2170013422136f80;p=netwar.git diff --git a/netwar.c b/netwar.c index 2419456..88ff5c7 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,35 @@ 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], + }); +} + +static void fire() { + cl_move((DoesBits) { .fire = true }); } int main(int argc, char ** argv) { @@ -135,23 +148,17 @@ 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; + else if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_LCTRL) + fire(); - if(currTime - lastTime >= TICK_DELAY) { - keyboardhandle(); - g_update(); - lastTime = SDL_GetTicks(); - } - currTime = SDL_GetTicks(); + keyboardhandle(); - cl_recv(); + cl_handle(); paintwindow();