X-Git-Url: https://deadsoftware.ru/gitweb?p=netwar.git;a=blobdiff_plain;f=netwar.c;h=44e8725cc6ff9c117784d59b64472fd207d491a2;hp=a3236f122f95dd8ff4a6d58c3dcee5668fd856ac;hb=f23bc975650813d88a819d403e1b9e1795086242;hpb=0afebb148532e32e6b47194e08e908beec45087e diff --git a/netwar.c b/netwar.c index a3236f1..44e8725 100644 --- a/netwar.c +++ b/netwar.c @@ -12,10 +12,19 @@ #define HEIGHT 480 static const float ship[] = { - +1.0, +0.0, -1.0, -1.0, - -1.0, -1.0, +0.0, +0.0, - +0.0, +0.0, -1.0, +1.0, - -1.0, +1.0, +1.0, +0.0, + +1.0, +0.0, + -1.0, -1.0, + +0.0, +0.0, + -1.0, +1.0, + +1.0, +0.0, +}; + +static const float star[] = { + +1.0, +0.0, + +0.0, -1.0, + -1.0, +0.0, + +0.0, +1.0, + +1.0, +0.0, }; static char * host = "localhost"; @@ -78,13 +87,35 @@ static void closewindow() { SDL_DestroyWindow(window); } +static void paintmodel(const float * model, int modelsz, float mx, float my, float r, float size, int cx, int cy) { + int scale = (WIDTH + HEIGHT) / 2 * size; + + int count = modelsz / sizeof(model[0]) / 2; + int x = mx * WIDTH / 2; + int y = my * HEIGHT / 2; + + SDL_Point pix[count]; + for(int j = 0; j < count * 2; j += 2) { + float c = cos(r * 2 * M_PI); + float s = sin(r * 2 * M_PI); + float rx = model[j + 0] * scale; + float ry = model[j + 1] * scale; + pix[j / 2].x = cx + x + (c * rx - s * ry); + pix[j / 2].y = cy + y + (s * rx + c * ry); + } + + SDL_RenderDrawLines(renderer, pix, count); +} + static void paintwindow() { SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); SDL_RenderClear(renderer); int cx = WIDTH / 2; int cy = HEIGHT / 2; - int shipsz = (WIDTH + HEIGHT) / 2 * PLAYER_SIZE; + + SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0xFF, 0x00); + paintmodel(star, sizeof(star), 0, 0, 0, STAR_SIZE, cx, cy); for(int i = 0; i < MAX_PLAYERS; i++) { if(i == cl_playerid) @@ -92,22 +123,8 @@ static void paintwindow() { else SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0x00); - int count = sizeof(ship) / sizeof(ship[0]) / 2; - int x = g_player[i].x * WIDTH / 2; - int y = g_player[i].y * HEIGHT / 2; - - SDL_Point pixship[count]; - for(int j = 0; j < count * 2; j += 2) { - float c = cos(g_player[i].r * 2 * M_PI); - float s = sin(g_player[i].r * 2 * M_PI); - float rx = ship[j + 0] * shipsz; - float ry = ship[j + 1] * shipsz; - pixship[j / 2].x = cx + x + (c * rx - s * ry); - pixship[j / 2].y = cy + y + (s * rx + c * ry); - } - if(g_player[i].live) - SDL_RenderDrawLines(renderer, pixship, count); + paintmodel(ship, sizeof(ship), g_player[i].x, g_player[i].y, g_player[i].r, PLAYER_SIZE, cx, cy); } for(int i = 0; i < MAX_BULLETS; i++) {