void Bullet::go(int id, double sync, Net &net, Server &server) // call after clear { move(sync); if (y < 0 || y > out->getHeight() || dead) { // transmit here cos this covers dead and out of screen Unit unit; unit.bullet.flag = UNIT_BULLET; unit.bullet.id = id; unit.bullet.active = 0; unit.bullet.x = 0; unit.bullet.y = 0; unit.bullet.z = 0; unit.bullet.dirY = 0; unit.bullet.speedY = 0; unit.bullet.owner = 0; net.addUnitAll(unit, server, -1); dead = false; active = false; }//else{ //draw(); //} }
void Badcontrol::spawn(Timer &timer, Net &net, Server &server) { timeval elapsed = timer.elapsed(lastSpawn); if (elapsed.tv_sec > spawnDelay.tv_sec || (elapsed.tv_sec == spawnDelay.tv_sec && elapsed.tv_usec > spawnDelay.tv_usec)) { lastSpawn = timer.getCurrent(); spawnDelay.tv_sec = std::rand() % 10 + 1; spawnDelay.tv_usec = std::rand() % 100 * 10000; Unit unit; for (int i = 0; i < badlen; i++) { if (!bad[i].getActive()) { makeBad(i, spawnOffsetX + formationX, spawnOffsetY + formationY, spawnOffsetX, spawnOffsetY, BAD_SHIP, timer.getCurrent()); unit.position.flag = UNIT_POSITION; unit.position.id = i + ID_BAD_MIN; unit.position.x = bad[i].getX(); unit.position.y = bad[i].getY(); unit.position.z = 0; net.addUnitAll(unit, server, -1); unit.bad.flag = UNIT_BAD; unit.bad.id = i; unit.bad.type = bad[i].getType(); unit.bad.status = 1; net.addUnitAll(unit, server, -1); if (std::rand() % 2 == 0) bad[i].setPowerup(true); else bad[i].setPowerup(false); if (std::rand() % 2 == 0) bad[i].setPowerupType(POWERUP_SPEED); else bad[i].setPowerupType(POWERUP_BULLET); break; } } } }
void Badcontrol::go(float playerX, float playerY, double sync, Bulletcontrol &bulletcontrol, Powerupcontrol &powerupcontrol, Timer &timer, bool &gameover, Net &net, Server &server) { // s = ut + 0.5 * att // a = 0 formationX += speedX * sync; // check if any baddie has hit the edge of the screen, using their place in formation // If they have, change formation direction for (int i = 0; i < badlen; i++) { if (bad[i].getActive() && !bad[i].getDying()) { if ((formationX + bad[i].getOffsetX() + bad[i].getWidth() / 2.0 > out->getWidth() && speedX > 0.0) || (formationX + bad[i].getOffsetX() - bad[i].getWidth() / 2.0 < 0 && speedX < 0.0)) { speedX = -speedX; if (moveDown) { formationY++; speedX = (speedX < 0) ? speedX - speedInc : speedX + speedInc; for (int i = 0; i < badlen; i++) { if (bad[i].getActive() && !bad[i].getDying()) { if (formationY + bad[i].getOffsetY() + bad[i].getHeight() / 2.0 > out->getHeight()) { gameover = true; } } } } break; } } } if (spawning) spawn(timer, net, server); int dead = 0; for (int i = 0; i < badlen; i++) { if (bad[i].getActive()) bad[i].go(i, formationX, formationY, playerX, playerY, sync, bulletcontrol, powerupcontrol, timer, net, server); else dead++; } if (dead == badlen) { makeAttack(attackWave, timer.getCurrent()); Unit unit; unit.attack.flag = UNIT_ATTACK; unit.attack.wave = attackWave; net.addUnitAll(unit, server, -1); attackWave++; if (attackWave > attacklen) attackWave = 0; } }
void Picturecontrol::input(int keys, Net& net, Server &server) // called by server, transmit picnum to clients { if (clientnum > -1 && clientnum < MAX_CLIENTS && picnum > -1 && picnum < piclen[clientnum]) { //&& pic[clientnum][picnum].getAngleY() > -20 && pic[clientnum][picnum].getAngleY() < 20) { int oldpicnum = picnum; if (keys & KEYS_NEXT) picnum++; if (keys & KEYS_BACK) picnum--; if (picnum < 0) { picnum = 0; // default (no pics found) bool found = false; // go to end of last client that has something for (int c = clientnum - 1; c >= 0; c--) { if (piclen[c] > 0) { picnum = piclen[c] - 1; clientnum = c; found = true; break; } } if (!found) { // count back from end, up until and including current client for (int c = MAX_CLIENTS - 1; c >= clientnum; c--) { if (piclen[c] > 0) { picnum = piclen[c] - 1; clientnum = c; break; } } } } if (picnum > piclen[clientnum] - 1) { bool found = false; for (int c = clientnum + 1; c < MAX_CLIENTS; c++) { if (piclen[c] > 0) { clientnum = c; found = true; break; } } if (!found) { // go through from start for (int c = 0; c < clientnum + 1; c++) { if (piclen[c] > 0) { clientnum = c; break; } } } picnum = 0; } if (oldpicnum != picnum) { int direction = (keys & KEYS_NEXT) ? 1 : 0; setPicnum(clientnum, picnum, direction); // set up positions // transmit picnum Unit unit; unit.picselect.flag = UNIT_PICSELECT; unit.picselect.clientnum = clientnum; unit.picselect.picnum = picnum; unit.picselect.direction = direction; net.addUnitAll(unit, server, -1); *out << VERBOSE_LOUD << "Picselect clientnum: " << unit.picselect.clientnum << ", picnum: " << unit.picselect.picnum << ", direction: " << unit.picselect.direction << '\n'; } } }