From 92489617eec44b913515404143baf5b094a16473 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Tue, 7 Nov 2023 20:24:19 +0100 Subject: points --- src/players.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/players.c') diff --git a/src/players.c b/src/players.c index 5f4b19e..cd2e479 100644 --- a/src/players.c +++ b/src/players.c @@ -63,6 +63,7 @@ void spawn_player(u32 id, network_client client) { players[i].connection_state = CONNECTED; players[i].throwables.grenades = 3; players[i].throwables.molotovs = 1; + players[i].points = 800; gun g = get_gun_by_type(players[i].guntype); players[i].total_ammo = g.max_ammunition; @@ -71,6 +72,43 @@ void spawn_player(u32 id, network_client client) { } } +void update_points_animation_server() { + float speed = 15.0f; + float alive_time = 1.0f; + for (int i = 0; i < MAX_PLAYERS; i++) { + for (int x = 0; x < MAX_POINT_ANIMATIONS; x++) { + if (!players[i].point_animations[x].active) continue; + + players[i].point_animations[x].sec_alive += SERVER_TICK_RATE; + players[i].point_animations[x].position.x -= speed * SERVER_TICK_RATE; + players[i].point_animations[x].position.y -= players[i].point_animations[x].diry * speed * SERVER_TICK_RATE; + players[i].point_animations[x].opacity = 1.0f - (players[i].point_animations[x].sec_alive/alive_time); + + if (players[i].point_animations[x].sec_alive >= alive_time) { + players[i].point_animations[x].active = false; + } + } + } +} + +void add_points_to_player(player* p, u32 points) { + p->points += points; + float rand_dirs[MAX_POINT_ANIMATIONS] = {0.0f, -1.0f, 1.0f, 0.3f, -0.1f, 0.5f, 0.2f, -0.8f, 0.3f, -0.6f}; + + for (int i = 0; i < MAX_POINT_ANIMATIONS; i++) { + if (p->point_animations[i].active) continue; + + p->point_animations[i].active = true; + p->point_animations[i].points = points; + p->point_animations[i].diry = rand_dirs[i]; + p->point_animations[i].sec_alive = 0.0f; + p->point_animations[i].position.x = 0.0f; + p->point_animations[i].position.y = 0.0f; + p->point_animations[i].opacity = 1.0f; + return; + } +} + void move_user(platform_window* window, u32 id, protocol_move_type move, float delta) { float speed_straight = 5.5f; -- cgit v1.2.3-70-g09d2