some gameplay fixes
This commit is contained in:
parent
90f4b64af8
commit
e08d376864
75
src/game.cpp
75
src/game.cpp
@ -71,11 +71,21 @@ void game_reset_point(point_t *point) {
|
||||
point->z = 0.0;
|
||||
}
|
||||
|
||||
void game_reset_bomb(bomb_t *bomb) {
|
||||
bomb->status = 0;
|
||||
bomb->x = 0.0;
|
||||
bomb->y = 0.0;
|
||||
bomb->z = 0.0;
|
||||
}
|
||||
|
||||
void game_setup(game_t *game, int master, void(*explosion_callback)(double x,
|
||||
double y, double z)) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_TEAM_COUNT; i++)
|
||||
game_setup_team(&game->team[i], i);
|
||||
for (i = 0; i < GAME_BOMB_COUNT; i++)
|
||||
game_reset_bomb(&game->bomb[i]);
|
||||
|
||||
if (master) {
|
||||
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++)
|
||||
@ -145,12 +155,12 @@ void game_update_players(game_t *game, double dt) {
|
||||
player_t *player = &game->player[i];
|
||||
if (player->status == 0)
|
||||
return;
|
||||
if (player->vx > 500.0)
|
||||
player->vx = 500.0;
|
||||
if (player->vy > 500.0)
|
||||
player->vy = 500.0;
|
||||
if (player->vz > 500.0)
|
||||
player->vz = 500.0;
|
||||
if (player->vx > 1000.0)
|
||||
player->vx = 1000.0;
|
||||
if (player->vy > 1000.0)
|
||||
player->vy = 1000.0;
|
||||
if (player->vz > 1000.0)
|
||||
player->vz = 1000.0;
|
||||
player->x += player->vx * dt;
|
||||
player->y += player->vy * dt;
|
||||
player->z += player->vz * dt;
|
||||
@ -161,6 +171,30 @@ void game_update_players(game_t *game, double dt) {
|
||||
player->team->points += player->points;
|
||||
player->points = 0;
|
||||
}
|
||||
|
||||
if (player->x < (-1000 + 10)) {
|
||||
player->x = (-1000 + 10);
|
||||
player->vx *= -1;
|
||||
} else if (player->x > (5000 - 10)) {
|
||||
player->x = (5000 - 10);
|
||||
player->vx *= -1;
|
||||
}
|
||||
|
||||
if (player->y < (-3000 + 10)) {
|
||||
player->y = (-3000 + 10);
|
||||
player->vy *= -1;
|
||||
} else if (player->y > (3000 - 10)) {
|
||||
player->y = (3000 - 10);
|
||||
player->vy *= -1;
|
||||
}
|
||||
|
||||
if (player->z < (-3000 + 10)) {
|
||||
player->z = (-3000 + 10);
|
||||
player->vz *= -1;
|
||||
} else if (player->z > (3000 - 10)) {
|
||||
player->z = (3000 - 10);
|
||||
player->vz *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +206,7 @@ void _explode_bomb(game_t *game, bomb_t *bomb) {
|
||||
continue;
|
||||
double distance2 = pow(player->x - bomb->x, 2) + pow(player->y
|
||||
- bomb->y, 2) + pow(player->z - bomb->z, 2);
|
||||
if (distance2 < 10000.0) {
|
||||
if (distance2 < pow(150 , 2)) {
|
||||
game->explosion_callback(player->x, player->y, player->z);
|
||||
player->x = player->team->x + 100;
|
||||
player->y = player->team->y;
|
||||
@ -201,11 +235,32 @@ void game_update_bombs(game_t *game, double dt) {
|
||||
bomb->y += bomb->vy * dt;
|
||||
bomb->z += bomb->vz * dt;
|
||||
bomb->ttl -= dt;
|
||||
|
||||
if (bomb->x < (-1000 + 10)) {
|
||||
bomb->x = (-1000 + 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->x > (5000 - 10)) {
|
||||
bomb->x = (5000 - 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->y < (-3000 + 10)) {
|
||||
bomb->y = (-3000 + 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->y > (3000 - 10)) {
|
||||
bomb->y = (3000 - 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->z < (-3000 + 10)) {
|
||||
bomb->z = (-3000 + 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->z > (3000 - 10)) {
|
||||
bomb->z = (3000 - 10);
|
||||
bomb->ttl = -0.1;
|
||||
}
|
||||
|
||||
if (bomb->ttl < 0) {
|
||||
if (bomb->status == 1) {
|
||||
game->explosion_callback(bomb->x, bomb->y, bomb->z);
|
||||
bomb->status = 2;
|
||||
} else if (bomb->ttl < 0.8) {
|
||||
} else if (bomb->ttl < -0.2) {
|
||||
_explode_bomb(game, bomb);
|
||||
bomb->status = 0;
|
||||
}
|
||||
@ -240,9 +295,9 @@ void game_update_points(game_t *game, double dt) {
|
||||
}
|
||||
|
||||
void game_update(game_t *game, double dt) {
|
||||
const double delta = 1. / 60.;
|
||||
const double delta = 1. / 120.;
|
||||
game->updateTime += dt;
|
||||
while (game->updateTime > delta * 0.8) {
|
||||
while (game->updateTime > delta) {
|
||||
game_update_players(game, delta);
|
||||
game_update_bombs(game, delta);
|
||||
game_update_points(game, delta);
|
||||
|
101
src/main.cpp
101
src/main.cpp
@ -299,9 +299,9 @@ void dispatch_message(enet_uint8 *data, size_t length, game_t *game) {
|
||||
case MESSAGE_PLAYER_UPDATE: {
|
||||
player_update_message_t *um = (player_update_message_t *) data;
|
||||
player_t *player = game_player(game, um->player_id);
|
||||
player->x = um->x;
|
||||
player->y = um->y;
|
||||
player->z = um->z;
|
||||
player->x = um->x + um->vx * 0.0001;
|
||||
player->y = um->y + um->vy * 0.0001;
|
||||
player->z = um->z + um->vz * 0.0001;
|
||||
player->vx = um->vx;
|
||||
player->vy = um->vy;
|
||||
player->vz = um->vz;
|
||||
@ -330,9 +330,9 @@ void dispatch_message(enet_uint8 *data, size_t length, game_t *game) {
|
||||
bomb_t *bomb = game_spawn_bomb(game);
|
||||
if (bomb == NULL)
|
||||
return;
|
||||
bomb->x = m->x;
|
||||
bomb->y = m->y;
|
||||
bomb->z = m->z;
|
||||
bomb->x = m->x + m->vx * 0.0001;
|
||||
bomb->y = m->y + m->vy * 0.0001;
|
||||
bomb->z = m->z + m->vz * 0.0001;
|
||||
bomb->vx = m->vx;
|
||||
bomb->vy = m->vy;
|
||||
bomb->vz = m->vz;
|
||||
@ -544,14 +544,14 @@ void draw_box() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
if (wallTex == 0) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glfwLoadTexture2D("data/wall.tga", 0);
|
||||
}
|
||||
|
||||
GLfloat red[] = { 0.1f, 0.2f, 0.3f, 1.0f };
|
||||
GLfloat red[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
|
||||
// Enable/Disable features
|
||||
@ -564,41 +564,41 @@ void draw_box() {
|
||||
glPushMatrix();
|
||||
glTranslated(2000.0, 0.0, 0.0);
|
||||
//glScaled(5000.0f, 5000.0f, 5000.0f);
|
||||
float s = 2500.0;
|
||||
float s = 3000.0f, t = 5.0f;
|
||||
// Just in case we set all vertices to white.
|
||||
glColor4f(1, 1, 1, 1);
|
||||
|
||||
// Render the front quad
|
||||
// glBindTexture(GL_TEXTURE_2D, _skybox[0]);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
glVertex3f(s, -s, -s);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
glVertex3f(s, s, -s);
|
||||
glTexCoord2f(1, 1);
|
||||
glTexCoord2f(0, t);
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
glVertex3f(-s, s, -s);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glTexCoord2f(0, 0);
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
glVertex3f(-s, -s, -s);
|
||||
|
||||
glTexCoord2f(t, 0);
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
glVertex3f(s, -s, -s);
|
||||
|
||||
glTexCoord2f(t, t);
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
glVertex3f(s, s, -s);
|
||||
glEnd();
|
||||
|
||||
// Render the left quad
|
||||
// glBindTexture(GL_TEXTURE_2D, _skybox[1]);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(s, -s, s);
|
||||
glTexCoord2f(0, 1);
|
||||
|
||||
glTexCoord2f(0, t);
|
||||
glVertex3f(s, s, s);
|
||||
glTexCoord2f(1, 1);
|
||||
|
||||
glTexCoord2f(t, t);
|
||||
glVertex3f(s, s, -s);
|
||||
glTexCoord2f(1, 0);
|
||||
|
||||
glTexCoord2f(t, 0);
|
||||
glVertex3f(s, -s, -s);
|
||||
glEnd();
|
||||
|
||||
@ -607,11 +607,11 @@ void draw_box() {
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-s, -s, s);
|
||||
glTexCoord2f(0, 1);
|
||||
glTexCoord2f(0, t);
|
||||
glVertex3f(-s, s, s);
|
||||
glTexCoord2f(1, 1);
|
||||
glTexCoord2f(t, t);
|
||||
glVertex3f(s, s, s);
|
||||
glTexCoord2f(1, 0);
|
||||
glTexCoord2f(t, 0);
|
||||
glVertex3f(s, -s, s);
|
||||
|
||||
glEnd();
|
||||
@ -621,24 +621,24 @@ void draw_box() {
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-s, -s, -s);
|
||||
glTexCoord2f(0, 1);
|
||||
glTexCoord2f(0, t);
|
||||
glVertex3f(-s, s, -s);
|
||||
glTexCoord2f(1, 1);
|
||||
glTexCoord2f(t, t);
|
||||
glVertex3f(-s, s, s);
|
||||
glTexCoord2f(1, 0);
|
||||
glTexCoord2f(t, 0);
|
||||
glVertex3f(-s, -s, s);
|
||||
glEnd();
|
||||
|
||||
// Render the top quad
|
||||
//glBindTexture(GL_TEXTURE_2D, _skybox[4]);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 1);
|
||||
glTexCoord2f(0, t);
|
||||
glVertex3f(-s, s, -s);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glTexCoord2f(t, t);
|
||||
glVertex3f(s, s, -s);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glTexCoord2f(t, 0);
|
||||
glVertex3f(s, s, s);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
@ -651,11 +651,11 @@ void draw_box() {
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-s, -s, -s);
|
||||
glTexCoord2f(0, 1);
|
||||
glTexCoord2f(0, t);
|
||||
glVertex3f(-s, -s, s);
|
||||
glTexCoord2f(1, 1);
|
||||
glTexCoord2f(t, t);
|
||||
glVertex3f(s, -s, s);
|
||||
glTexCoord2f(1, 0);
|
||||
glTexCoord2f(t, 0);
|
||||
glVertex3f(s, -s, -s);
|
||||
glEnd();
|
||||
|
||||
@ -768,7 +768,7 @@ void Application::initialize(int argc, char ** argv) {
|
||||
accelerate_schudule.setInterval(0.05);
|
||||
|
||||
player_update_schudule.setExact(true);
|
||||
player_update_schudule.setInterval(0.1);
|
||||
player_update_schudule.setInterval(0.05);
|
||||
|
||||
loadConsoleFont();
|
||||
}
|
||||
@ -791,23 +791,13 @@ void Application::update() {
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
|
||||
if (local_player) {
|
||||
camX = local_player->x;
|
||||
camY = local_player->y;
|
||||
camZ = local_player->z;
|
||||
} else {
|
||||
camX = 1000.0;
|
||||
camY = 1000.0;
|
||||
camZ = 1000.0;
|
||||
}
|
||||
game_update(&game, dt);
|
||||
|
||||
service_network(&game);
|
||||
if (server && player_update_schudule.next(time)) {
|
||||
send_player_updates(&game);
|
||||
}
|
||||
|
||||
game_update(&game, dt);
|
||||
|
||||
double rx = cos(phi) * cos(theta);
|
||||
double ry = sin(theta);
|
||||
double rz = sin(phi) * cos(theta);
|
||||
@ -837,13 +827,24 @@ void Application::update() {
|
||||
drop_bomb(&game, rx, ry, rz, 5.0);
|
||||
}
|
||||
}
|
||||
service_network(&game);
|
||||
//service_network(&game);
|
||||
|
||||
if (local_player) {
|
||||
camX = local_player->x;
|
||||
camY = local_player->y;
|
||||
camZ = local_player->z;
|
||||
} else {
|
||||
camX = 1000.0;
|
||||
camY = 1000.0;
|
||||
camZ = 1000.0;
|
||||
}
|
||||
|
||||
prepareFrame(rx, ry, rz);
|
||||
setup_light();
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
for (size_t i = 0; i < GAME_TEAM_COUNT; i++)
|
||||
draw_team(&game.team[i]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user