diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-11-04 11:59:49 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-11-04 11:59:49 +0100 |
| commit | 7cebd14ef316460d6929053ba27c3ad9f1f468bb (patch) | |
| tree | 49b87a1b5cdfe85cf2a14b1eb4bfed48d617afcd | |
| parent | 2b9b3e78d9d448e4dfb4eaaa87b5f290ebee9cff (diff) | |
improve camera
| -rw-r--r-- | build/zombies.exe | bin | 1995181 -> 1996781 bytes | |||
| -rw-r--r-- | src/game.c | 32 | ||||
| -rw-r--r-- | src/players.c | 7 |
3 files changed, 32 insertions, 7 deletions
diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex 646a03c..b47c519 100644 --- a/build/zombies.exe +++ b/build/zombies.exe @@ -333,7 +333,31 @@ void update_client(platform_window* window) { logic_update_time = platform_get_time(TIME_FULL, TIME_NS) - logic_update_time; update_zombies_client(window); - update_players_client(); +} + +static void move_camera(platform_window* window) { + float speedx = window->width / 1000.0f; + float diffx = (_next_camera_pos.x - _global_camera.x); + if (abs(diffx) <= speedx) diffx = 0.0f; + speedx += (abs(diffx)/200.0f*speedx); + + float speedy = window->height / 600.0f; + float diffy = (_next_camera_pos.y - _global_camera.y); + if (abs(diffy) <= speedy) diffy = 0.0f; + speedy += (abs(diffy)/200.0f*speedy); + + float length = sqrt(diffx * diffx + diffy * diffy); + if (length == 0) length = 1.0f; + + float dirx = diffx/length; + float diry = diffy/length; + + _global_camera.x += dirx*speedx; + _global_camera.y += diry*speedy; + + //_global_camera.x = _next_camera_pos.x; + //_global_camera.y = _next_camera_pos.y; + log_infox("%.1f %.1f", speedx, speedy); } void update_game(platform_window* window) { @@ -365,7 +389,8 @@ void update_game(platform_window* window) { #ifdef MODE_DEBUG if (!is_editing_map) - #endif + #endif + draw_players(window); draw_spawners(window); @@ -375,7 +400,6 @@ void update_game(platform_window* window) { draw_editor(window); #endif - _global_camera.x = (int)_next_camera_pos.x; - _global_camera.y = (int)_next_camera_pos.y; + move_camera(window); } }
\ No newline at end of file diff --git a/src/players.c b/src/players.c index bd80d5b..a01a962 100644 --- a/src/players.c +++ b/src/players.c @@ -310,6 +310,7 @@ void draw_players(platform_window* window) { players[i].height = height; box box = get_render_box_of_square(window, (vec3f){players[i].playerx, players[i].playery, height}, (vec3f){size,size,1.0f}); + /* render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgb(200,150,120)); render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,150,120)); @@ -327,8 +328,8 @@ void draw_players(platform_window* window) { int size = get_tile_width(window) / 2; map_info info = get_map_info(window); - float player_render_x = players[i].playerx*info.tile_width + (players[i].playery*info.px_incline); - float player_render_y = players[i].playery*info.tile_height - (height*info.px_raised_per_h); + float player_render_x = box.tl_u.x;//players[i].playerx*info.tile_width + (players[i].playery*info.px_incline); + float player_render_y = box.tl_u.y;//players[i].playery*info.tile_height - (height*info.px_raised_per_h); players[i].gun_height = height+0.5; //float gun_render_x = players[i].gunx*info.tile_width + (players[i].guny*info.px_incline); @@ -341,7 +342,7 @@ void draw_players(platform_window* window) { renderer->render_image(img_disconnected, box.tl_u.x + (icon_h/3), box.tr_u.y - icon_h, icon_h, icon_h); } - if (players[i].id == player_id) { + if (players[i].id == player_id) { _next_camera_pos.x = -(window->width / 2) + player_render_x; _next_camera_pos.y = -(window->height / 2) + player_render_y; } |
