summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-11-07 20:24:19 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-11-07 20:24:19 +0100
commit92489617eec44b913515404143baf5b094a16473 (patch)
treee6d3d0424491052eb6f495ab3a64b725376ee76a
parentcf3cfecbcac3835c84dce3711884b7ce0a81b6b8 (diff)
points
-rw-r--r--build/zombies.exebin2016824 -> 2020526 bytes
-rw-r--r--include/bullets.h2
-rw-r--r--include/players.h17
-rw-r--r--main.c2
-rw-r--r--src/bullets.c1
-rw-r--r--src/game.c1
-rw-r--r--src/overlay.c34
-rw-r--r--src/players.c38
8 files changed, 94 insertions, 1 deletions
diff --git a/build/zombies.exe b/build/zombies.exe
index ea4ab02..60b35e3 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/include/bullets.h b/include/bullets.h
index 26e4c5f..28ad175 100644
--- a/include/bullets.h
+++ b/include/bullets.h
@@ -8,6 +8,8 @@
#include "map.h"
#include "guns.h"
+#define POINTS_PER_HIT 10
+
typedef struct t_bullet {
u32 player_id;
bool active;
diff --git a/include/players.h b/include/players.h
index a6b1745..a41b246 100644
--- a/include/players.h
+++ b/include/players.h
@@ -12,6 +12,7 @@
#include "../include/players.h"
#define MAX_PLAYERS 10
+#define MAX_POINT_ANIMATIONS 10
typedef enum t_player_interact_state {
INTERACT_IDLE,
@@ -29,6 +30,16 @@ typedef enum t_player_direction {
DIRECTION_BOTTOMRIGHT,
} player_direction;
+typedef struct t_point_animation
+{
+ bool active;
+ u32 points;
+ float diry;
+ vec2f position;
+ float sec_alive;
+ float opacity;
+} point_animation;
+
typedef struct t_player {
u32 id;
bool active;
@@ -52,12 +63,16 @@ typedef struct t_player {
u64 ping;
sprite sprite;
network_state connection_state;
+ u32 points;
struct {
int grenades;
int molotovs;
} throwables;
+ point_animation point_animations[MAX_POINT_ANIMATIONS];
} player;
+
+
#include "protocol.h"
u32 player_id = -1; // Session id on current server.
@@ -79,5 +94,7 @@ bool player_has_old_session(u32 id);
void rejoin_player(u32 id, network_client client);
char* get_player_name_by_player_index(int index);
color get_color_tint_by_player_index(int index);
+void add_points_to_player(player* p, u32 points);
+void update_points_animation_server();
#endif \ No newline at end of file
diff --git a/main.c b/main.c
index f1f1842..17b6c09 100644
--- a/main.c
+++ b/main.c
@@ -87,7 +87,7 @@ void handle_args(int argc, char **argv) {
}
int main(int argc, char **argv)
-{
+{
platform_init(argc, argv, CONFIG_DIRECTORY);
settings_set_number("USE_GPU", 1);
diff --git a/src/bullets.c b/src/bullets.c
index db23938..6cb4b66 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -246,6 +246,7 @@ void update_bullets_server(platform_window* window) {
bullets[i].damage = b.damage;
b = bullets[i];
+ add_points_to_player(p, POINTS_PER_HIT);
add_zombie_audio_event_to_queue(EVENT_IMPACT, ZOMBIE_TYPE_NORMAL, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
}
}
diff --git a/src/game.c b/src/game.c
index 2ebbcf0..41064e4 100644
--- a/src/game.c
+++ b/src/game.c
@@ -220,6 +220,7 @@ void update_server(platform_window* window) {
update_throwables_server();
update_zombie_chunks_server();
update_round_server();
+ update_points_animation_server();
broadcast_players = platform_get_time(TIME_FULL, TIME_NS);
update_players_server();
diff --git a/src/overlay.c b/src/overlay.c
index e1762cd..6aad6d4 100644
--- a/src/overlay.c
+++ b/src/overlay.c
@@ -121,9 +121,43 @@ void draw_debug_stats(platform_window* window) {
renderer->render_text(fnt_20, _global_camera.x, _global_camera.y + fnt_20->px_h*1, update_text, rgb(0,0,0));
}
+void draw_points(platform_window* window) {
+ int x = (int)_global_camera.x + window->width - EDGE_PADDING;
+ int y = (int)_global_camera.y + window->height - EDGE_PADDING;
+ char points_txt[20];
+
+ for (int i = 0; i < MAX_PLAYERS; i++) {
+ if (!players[i].active) continue;
+
+ sprintf(points_txt, "%d", players[i].points);
+
+ y -= fnt_20->px_h;
+ int x1 = renderer->calculate_text_width(fnt_24, points_txt);
+ renderer->render_text(fnt_24, x - x1+1, y+1, points_txt, rgba(0,0,0,120));
+ renderer->render_text(fnt_24, x - x1, y, points_txt, get_color_tint_by_player_index(i));
+
+ for (int t = 0; t < MAX_POINT_ANIMATIONS; t++) {
+ if (!players[i].point_animations[t].active) continue;
+ point_animation animation = players[i].point_animations[t];
+ sprintf(points_txt, "%d", animation.points);
+ int textw = renderer->calculate_text_width(fnt_20, points_txt);
+ int py = y - animation.position.y;
+ int px = x1 - animation.position.x;
+ px += textw+2;
+ color c = get_color_tint_by_player_index(i);
+ c.a = 255*animation.opacity;
+ renderer->render_text(fnt_20, x - px+1, py+1, points_txt, rgba(0,0,0,120*animation.opacity));
+ renderer->render_text(fnt_20, x - px, py, points_txt, c);
+ }
+
+ y -= 8;
+ }
+}
+
void draw_overlay(platform_window* window) {
OVERLAY_RENDER_DEPTH();
draw_gun_info(window);
+ draw_points(window);
draw_leaderboard(window);
draw_debug_stats(window);
} \ No newline at end of file
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;