DEADSOFTWARE

Добавлено ограничение максимального ускорения
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 4 Apr 2017 16:07:20 +0000 (19:07 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 4 Apr 2017 16:07:20 +0000 (19:07 +0300)
game.c

diff --git a/game.c b/game.c
index 4b1c345c43d2443572eb281bdb13533ce4197c47..36dccb41669cf628070979921560f8fdf93ec3d2 100644 (file)
--- a/game.c
+++ b/game.c
@@ -10,6 +10,9 @@
 #define ROTATE     (0.03 / TICK)
 #define BULL_SPEED (0.4  / TICK)
 
+#define MAX_SPEED  (0.3 / TICK)
+#define MAX_ROTATE (0.3 / TICK)
+
 Player g_player[MAX_PLAYERS];
 Bullet g_bullet[MAX_BULLETS];
 
@@ -53,10 +56,17 @@ static int freebullet() {
 static void moveplayer(int id, float speed) {
        g_player[id].vx += speed * cos(g_player[id].r * 2 * M_PI);
        g_player[id].vy += speed * sin(g_player[id].r * 2 * M_PI);
+
+       if(fabs(g_player[id].vx) > MAX_SPEED)
+               g_player[id].vx = copysignf(MAX_SPEED, g_player[id].vx);
+       if(fabs(g_player[id].vy) > MAX_SPEED)
+               g_player[id].vy = copysignf(MAX_SPEED, g_player[id].vy);
 }
 
 static void roteplayer(int id, float speed) {
        g_player[id].vr += speed;
+       if(fabs(g_player[id].vr) > MAX_ROTATE)
+               g_player[id].vr = copysignf(MAX_ROTATE, g_player[id].vr);
 }
 
 static void fireplayer(int id) {