void shmup_game_update(shmup_game *g, double t, double dt) { bullet *b; static int mx, my; glfwGetMousePos(&mx, &my); g->emitter.x = (double) mx; g->emitter.y = (double) g->window_height-my; if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)) shmup_game_fire(g, 40, 0, v2zero, v2zero, v2zero); if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT)) shmup_game_fire(g, 40, 1, v2zero, v2zero, v2zero); if (glfwGetKey('1')) g->render_type=1; if (glfwGetKey('2')) g->render_type=2; player_update(g, &g->player[0], dt); /* * be careful with this pointer, as this data may be moved by the * bpool_resize function! Make sure it points to the right place. */ b = g->bpool->bdata; /* do updates */ for (int i=0; i < g->bpool->n_active; ++i) { bullet_update(&b[i], dt); } /* do collisions */ for (int i=0; i < g->bpool->n_active; ++i) { if (!point_vs_aabb(b[i].pos, v2zero, v2(g->window_width, g->window_height))) bpool_deactivate(g->bpool, i--); } }
void shmup_game_update(shmup_game *g, double t, double dt) { static int tick = 0; static int mx, my; int i; ENetEvent event; ENetPacket *packet; bullet *b; tick++; while (enet_host_service(g->host, &event, 0) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: printf("A new client connected from %x:%u.\n", event.peer->address.host, event.peer->address.port); // sprintf(event.peer->data, "client %x.", event.peer->address.host); g->player[g->num_players].pos = v2(g->window_width/2, g->window_height/2); g->player[g->num_players].vel = v2zero; g->player[g->num_players].acc = v2zero; g->num_players++; break; case ENET_EVENT_TYPE_RECEIVE: g->player[1].keyflags = (short) *event.packet->data; // event.packet->dataLength, // event.packet->data, // event.peer->data, // event.channelID); enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: printf("%s disconected.\n", event.peer->data); /* Reset the peer's client information. */ event.peer->data = NULL; break; case ENET_EVENT_TYPE_NONE: break; } } glfwGetMousePos(&mx, &my); g->emitter.x = (double) mx; g->emitter.y = (double) g->window_height-my; if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)) shmup_game_fire(g, 40, 0, v2zero, v2zero, v2zero); if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT)) shmup_game_fire(g, 40, 1, v2zero, v2zero, v2zero); if (glfwGetKey('1')) g->render_type = 1; if (glfwGetKey('2')) g->render_type = 2; g->player->keyflags = KF_NONE; if (glfwGetKey('A')) g->player->keyflags |= KF_MOV_L; if (glfwGetKey('D')) g->player->keyflags |= KF_MOV_R; if (glfwGetKey('W')) g->player->keyflags |= KF_MOV_U; if (glfwGetKey('S')) g->player->keyflags |= KF_MOV_D; if (glfwGetKey(GLFW_KEY_SPACE)) g->player->keyflags |= KF_FIR_1; for (i=0; i < g->num_players; i++) { player_update(g, &g->player[i], dt); } b = g->bpool->bdata; /* * be careful with this pointer, as this data may be moved by the * bpool_resize function! Make sure it points to the right place. */ /* do updates */ for (i=0; i < g->bpool->n_active; i++) { bullet_update(&b[i], dt); } /* do collisions */ for (i=0; i < g->bpool->n_active; i++) { if (!point_vs_aabb(b[i].pos, v2zero, v2(g->window_width, g->window_height))) bpool_deactivate(g->bpool, i--); } if (g->network_type == CLIENT) { packet = enet_packet_create(&g->player->keyflags, sizeof(short), ENET_PACKET_FLAG_RELIABLE); enet_peer_send(g->peer, 0, packet); } else { packet = enet_packet_create(&g->player->keyflags, sizeof(short), ENET_PACKET_FLAG_RELIABLE); enet_host_broadcast(g->host, 0, packet); } }