summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ce00cd)
raw | patch | inline | side by side (parent: 0ce00cd)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 3 Apr 2017 07:57:04 +0000 (10:57 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 3 Apr 2017 07:57:04 +0000 (10:57 +0300) |
client.c | patch | blob | history | |
game.c | patch | blob | history | |
game.h | patch | blob | history | |
netwar.c | patch | blob | history | |
protocol.h | patch | blob | history | |
server.c | patch | blob | history |
diff --git a/client.c b/client.c
index 6c00cd29460d141be8b819193194005c95a7ec36..390a04e4be7719e9c206a4da5ce63ca40e87d293 100644 (file)
--- a/client.c
+++ b/client.c
b2f(m.sv.splr.r),
b2f(m.sv.splr.vx),
b2f(m.sv.splr.vy),
- b2f(m.sv.splr.vr)
+ b2f(m.sv.splr.vr),
+ m.sv.splr.shoot
);
}
SDL_Log("Invalid first message %i", m.type);
exit(1);
}
+
+ g_init(false);
}
index 9b7f2391ddc78d4aa3fdb7ef0777ba46c9001e61..cacaf6213412aca5862a489bb33f50c5cc9a2aa9 100644 (file)
--- a/game.c
+++ b/game.c
#include "game.h"
-#define SPEED 0.00006
-#define ROTATE 0.00004
-#define BULL_SPEED 0.008
+#define SPEED 0.00006
+#define ROTATE 0.00004
+#define BULL_SPEED 0.00800
Player g_player[MAX_PLAYERS];
Bullet g_bullet[MAX_BULLETS];
-void g_player_set(unsigned int id, bool live, float x, float y, float r, float vx, float vy, float vr) {
+static bool svmode;
+
+void g_player_set(unsigned int id, bool live, float x, float y, float r, float vx, float vy, float vr, int shoot) {
assert(id < MAX_PLAYERS);
g_player[id] = (Player) {
.updated = true,
if(j < 0)
return;
- float vx = BULL_SPEED * cos(g_player[id].r * 2 * M_PI);
- float vy = BULL_SPEED * sin(g_player[id].r * 2 * M_PI);
- g_bullet_set(j, id, true, g_player[id].x, g_player[id].y, vx, vy, 0);
+ if(g_player[id].shoot < PLAYER_SHOOT)
+ return;
+
+ g_player[id].shoot = 0;
+
+ if(svmode) {
+ float vx = BULL_SPEED * cos(g_player[id].r * 2 * M_PI);
+ float vy = BULL_SPEED * sin(g_player[id].r * 2 * M_PI);
+ g_bullet_set(j, id, true, g_player[id].x, g_player[id].y, vx, vy, 0);
+ }
}
static void checkspacebound(float * a) {
g_player[i].r += g_player[i].vr;
checkspacebound(&g_player[i].x);
checkspacebound(&g_player[i].y);
+
+ ++g_player[i].shoot;
+ if(g_player[i].shoot > PLAYER_SHOOT)
+ g_player[i].shoot = PLAYER_SHOOT;
}
}
}
}
}
+
+void g_init(bool server_mode) {
+ svmode = server_mode;
+ // TODO memset & co
+}
index 44bad6348d2dfe74d980270ad03bd066bba26473..a2d44b4ba1c82167c55681235148d7efb884c098 100644 (file)
--- a/game.h
+++ b/game.h
#include "protocol.h"
-#define MAX_PLAYERS 32
-#define MAX_BULLETS (MAX_PLAYERS * 8)
-#define TICK_DELAY (1000 / 40)
-#define BULLET_TIME (TICK_DELAY * 6)
-#define PLAYER_SIZE 0.01785
+#define MAX_PLAYERS 32
+#define MAX_BULLETS (MAX_PLAYERS * 8)
+#define TICK_DELAY (1000 / 20) // 20 World updates per second
+#define BULLET_TIME (TICK_DELAY * 6) // Bullet live time 6.0s
+#define PLAYER_SIZE 0.01785 // Palyer radius
+#define PLAYER_SHOOT (TICK_DELAY * 0.3) // Can shoot every 0.15s
typedef struct Player {
/* public */
bool live;
float x, y, r;
float vx, vy, vr;
+ int shoot;
/* internal */
bool updated;
extern Player g_player[MAX_PLAYERS];
extern Bullet g_bullet[MAX_BULLETS];
-void g_player_set(unsigned int id, bool live, float x, float y, float r, float vx, float vy, float vr);
+void g_player_set(unsigned int id, bool live, float x, float y, float r, float vx, float vy, float vr, int shoot);
void g_bullet_set(unsigned int id, unsigned int owner, bool live, float x, float y, float vx, float vy, int tick);
void g_player_does(unsigned int id, DoesBits code);
void g_update();
+void g_init(bool server_mode);
diff --git a/netwar.c b/netwar.c
index 88ff5c7ba766b2e9f27bc044d45291ad23706da7..a3236f122f95dd8ff4a6d58c3dcee5668fd856ac 100644 (file)
--- a/netwar.c
+++ b/netwar.c
.down = key[SDL_SCANCODE_DOWN],
.left = key[SDL_SCANCODE_LEFT],
.right = key[SDL_SCANCODE_RIGHT],
+ .fire = key[SDL_SCANCODE_LCTRL],
});
}
-static void fire() {
- cl_move((DoesBits) { .fire = true });
-}
-
int main(int argc, char ** argv) {
sysinit();
useargs(argv);
while(SDL_PollEvent(&event))
if(event.type == SDL_QUIT)
goto cleanup;
- else if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_LCTRL)
- fire();
keyboardhandle();
diff --git a/protocol.h b/protocol.h
index 68ec54a55aaa9a7c44b2a1af22c74c6c66a71652..a96d6932a6728f0eb5d6cb7b6cc95e45abafa63e 100644 (file)
--- a/protocol.h
+++ b/protocol.h
#include <string.h>
#define PROTOCOL_PORT 29386
-#define PROTOCOL_VERSION 2
+#define PROTOCOL_VERSION 3
#define PROTOCOL_F8FRAC (1 << 7)
#define PACKED __attribute__((__packed__))
uint8_t live;
uint8_t x, y, r;
uint8_t vx, vy, vr;
+ uint8_t shoot;
} SvSplr;
typedef struct PACKED SvSbul {
return (ProtocolMessage) (SvMessage) m;
}
-static inline ProtocolMessage sv_splr(int clid, bool live, float x, float y, float r, float vx, float vy, float vr) {
+static inline ProtocolMessage sv_splr(int clid, bool live, float x, float y, float r, float vx, float vy, float vr, int shoot) {
return (ProtocolMessage) (SvMessage) (SvSplr) {
- .type = SV_SPLR,
- .clid = clid,
- .live = live,
- .x = f2b(x),
- .y = f2b(y),
- .r = f2b(r),
+ .type = SV_SPLR,
+ .clid = clid,
+ .live = live,
+ .x = f2b(x),
+ .y = f2b(y),
+ .r = f2b(r),
.vx = f2b(vx),
.vy = f2b(vy),
.vr = f2b(vr),
+ .shoot = shoot,
};
}
diff --git a/server.c b/server.c
index 5e4823451f706e01bb394d6312de50135bf40436..e28b30203679bdde9c28ac957b2a8f487e9570cc 100644 (file)
--- a/server.c
+++ b/server.c
for(int i = 0; i < clientlimit; i++)
if(full || g_player[i].updated)
- SendMessage(sock, client[id].address, sv_splr(i, g_player[i].live, g_player[i].x, g_player[i].y, g_player[i].r, g_player[i].vx, g_player[i].vy, g_player[i].vr));
+ SendMessage(sock, client[id].address, sv_splr(i, g_player[i].live, g_player[i].x, g_player[i].y, g_player[i].r, g_player[i].vx, g_player[i].vy, g_player[i].vr, g_player[i].shoot));
for(int i = 0; i < MAX_BULLETS; i++)
if(full || g_bullet[i].updated)
static void sv_spawn_player(int id) {
assert(id >= 0);
- g_player_set(id, true, randfm(), randfm(), randfm(), 0, 0, 0);
+ g_player_set(id, true, randfm(), randfm(), randfm(), 0, 0, 0, PLAYER_SHOOT);
}
static void sv_kill_player(int id, bool send, const char * msg) {
SendMessage(sock, client[id].address, sv_kill(msg));
client[id].connected = false;
- g_player_set(id, false, 0, 0, 0, 0, 0, 0);
+ g_player_set(id, false, 0, 0, 0, 0, 0, 0, 0);
SDL_Log("Player %s (%i) disconnected: %s", client[id].name, id, msg);
}
}
void sv_start(uint16_t port) {
+ g_init(true);
sock = OpenPort(port);
lastTime = SDL_GetTicks();
currTime = SDL_GetTicks();