1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
else if (event.packet->data[0] == 'B') {
char message[100];
int messageCount = 0;
int ID;
for(unsigned int i = 0; i < event.packet->dataLength; ++i) {
message[i] = event.packet->data[i];
}
string coords = message;
istringstream ss(coords);
string token;
while(getline(ss, token, ',')) {
ID = atoi(token.c_str());
}
if (players[ID].weapon == MACHINE_GUN) {
Bullet newBullet;
newBullet.dir = players[ID].dir + (rand() % 6 - 3) * .01;
newBullet.x = players[ID].x + (players[ID].gunOffX * cos(players[ID].dir)) - (players[ID].gunOffY * sin(players[ID].dir));
newBullet.y = players[ID].y + (players[ID].gunOffY * cos(players[ID].dir)) + (players[ID].gunOffX * sin(players[ID].dir));
newBullet.speed = 10;
newBullet.life = 70;
newBullet.radius = 3;
newBullet.active = true;
newBullet.damage = .35;
newBullet.type = 0;
newBullet.playerID = ID;
newBullet.explosive = 0;
newBullet.knockback = 1;
newBullet.collidedPlayer = 1000;
newBullet.x += (newBullet.speed * 3) * cos(newBullet.dir);
newBullet.y += (newBullet.speed * 3) * sin(newBullet.dir);
bullets.push_back(newBullet);
char packet[256];
sprintf_s(packet, sizeof(packet), "B,%f,%f,%f,%f,%i,%i,%i,%i,%i", newBullet.x, newBullet.y, newBullet.dir, newBullet.speed, ID, newBullet.radius, newBullet.life, newBullet.type, newBullet.explosive);
ENetPacket *p = enet_packet_create((char*)packet, strlen(packet)+1, NULL);
//printf("Sent a packet to client containing %s\n", packet);
enet_host_broadcast(server, 0, p);
}
else if (players[ID].weapon == SHOTGUN) {
for (int i = 0; i < 5; i++) {
Bullet newBullet;
newBullet.dir = players[ID].dir + (rand() % 600 - 299) * .001;
newBullet.x = players[ID].x + (players[ID].gunOffX * cos(players[ID].dir)) - (players[ID].gunOffY * sin(players[ID].dir));
newBullet.y = players[ID].y + (players[ID].gunOffY * cos(players[ID].dir)) + (players[ID].gunOffX * sin(players[ID].dir));
newBullet.speed = 10 + (rand() % 10) * .1;
newBullet.life = 30;
newBullet.radius = 3;
newBullet.active = true;
newBullet.damage = 1;
newBullet.type = 0;
newBullet.playerID = ID;
newBullet.explosive = 0;
newBullet.knockback = 1;
newBullet.collidedPlayer = 1000;
newBullet.x += (newBullet.speed * 3) * cos(newBullet.dir);
newBullet.y += (newBullet.speed * 3) * sin(newBullet.dir);
bullets.push_back(newBullet);
char packet[256];
sprintf_s(packet, sizeof(packet), "B,%f,%f,%f,%f,%i,%i,%i,%i,%i", newBullet.x, newBullet.y, newBullet.dir, newBullet.speed, ID, newBullet.radius, newBullet.life, newBullet.type, newBullet.explosive);
ENetPacket *p = enet_packet_create((char*)packet, strlen(packet)+1, NULL);
enet_host_broadcast(server, 0, p);
}
}
else if (players[ID].weapon == FLAMETHROWER) {
for (int i = 0; i < 10 + (rand() % 5 - 5); i++) {
Bullet newBullet;
newBullet.dir = players[ID].dir + (rand() % 1000 - 490) * .001;
newBullet.x = players[ID].x + (players[ID].gunOffX * cos(players[ID].dir)) - (players[ID].gunOffY * sin(players[ID].dir));
newBullet.y = players[ID].y + (players[ID].gunOffY * cos(players[ID].dir)) + (players[ID].gunOffX * sin(players[ID].dir));
newBullet.speed = 10 + (rand() % 100 - 50) * .1;
newBullet.life = 5 + (rand() % 10 - 5);
newBullet.radius = 5;
newBullet.active = true;
newBullet.damage = .25;
newBullet.type = 2;
newBullet.playerID = ID;
newBullet.explosive = 0;
newBullet.knockback = 1;
newBullet.collidedPlayer = 1000;
newBullet.x += (newBullet.speed * 3) * cos(newBullet.dir);
newBullet.y += (newBullet.speed * 3) * sin(newBullet.dir);
bullets.push_back(newBullet);
char packet[256];
sprintf_s(packet, sizeof(packet), "B,%f,%f,%f,%f,%i,%i,%i,%i,%i", newBullet.x, newBullet.y, newBullet.dir, newBullet.speed, ID, newBullet.radius, newBullet.life, newBullet.type, newBullet.explosive);
ENetPacket *p = enet_packet_create((char*)packet, strlen(packet)+1, NULL);
enet_host_broadcast(server, 0, p);
}
}
else if (players[ID].weapon == BAZOOKA) {
Bullet newBullet;
newBullet.dir = players[ID].dir;
newBullet.x = players[ID].x + (players[ID].gunOffX * cos(players[ID].dir)) - (players[ID].gunOffY * sin(players[ID].dir));
newBullet.y = players[ID].y + (players[ID].gunOffY * cos(players[ID].dir)) + (players[ID].gunOffX * sin(players[ID].dir));
newBullet.speed = 15;
newBullet.life = 25;
newBullet.radius = 10;
newBullet.active = true;
newBullet.damage = 1.5;
newBullet.type = 5;
newBullet.playerID = ID;
newBullet.explosive = 0;
newBullet.knockback = 1;
newBullet.collidedPlayer = 1000;
newBullet.x += (newBullet.speed * 2) * cos(newBullet.dir);
newBullet.y += (newBullet.speed * 2) * sin(newBullet.dir);
bullets.push_back(newBullet);
char packet[256];
sprintf_s(packet, sizeof(packet), "B,%f,%f,%f,%f,%i,%i,%i,%i,%i", newBullet.x, newBullet.y, newBullet.dir, newBullet.speed, ID, newBullet.radius, newBullet.life, newBullet.type, newBullet.explosive);
ENetPacket *p = enet_packet_create((char*)packet, strlen(packet)+1, NULL);
enet_host_broadcast(server, 0, p);
}
if (players[ID].weapon == CHAIN_GUN) {
for (float i = -.125; i <= .125; i += .125) {
Bullet newBullet;
newBullet.dir = players[ID].dir + i;
newBullet.x = players[ID].x + (players[ID].gunOffX * cos(players[ID].dir)) - (players[ID].gunOffY * sin(players[ID].dir));
newBullet.y = players[ID].y + (players[ID].gunOffY * cos(players[ID].dir)) + (players[ID].gunOffX * sin(players[ID].dir));
newBullet.speed = 10;
newBullet.life = 50;
newBullet.radius = 4;
newBullet.active = true;
newBullet.damage = .35;
newBullet.type = 0;
newBullet.playerID = ID;
newBullet.explosive = 0;
newBullet.knockback = 1;
newBullet.collidedPlayer = 1000;
newBullet.x += (newBullet.speed) * 2 * cos(newBullet.dir);
newBullet.y += (newBullet.speed) * 2 * sin(newBullet.dir);
bullets.push_back(newBullet);
char packet[256];
sprintf_s(packet, sizeof(packet), "B,%f,%f,%f,%f,%i,%i,%i,%i,%i", newBullet.x, newBullet.y, newBullet.dir, newBullet.speed, ID, newBullet.radius, newBullet.life, newBullet.type, newBullet.explosive);
ENetPacket *p = enet_packet_create((char*)packet, strlen(packet)+1, NULL);
//printf("Sent a packet to client containing %s\n", packet);
enet_host_broadcast(server, 0, p);
}
}
}
|