+ w.setColor("wheat");
+ w.drawText(rtowX(w, positionChateau1), rtowY(w, 0) + 8, "Joueur 1",
+ Qt::AlignHCenter);
+ w.drawText(rtowX(w, positionChateau2), rtowY(w, 0) + 8, "Joueur 2",
+ Qt::AlignHCenter);
+ dessineVent(w, wnd);
+}
+
+/* Retour : numéro du perdant, 0 sinon
+ x et y contiennent les coordonnées de la collision
+*/
+int tir(DrawingWindow& w,
+ float x0, float y0, float v0, float alpha, float& x, float &y)
+{
+ float vx = v0 * cos(alpha);
+ float vy = v0 * sin(alpha);
+ x = x0;
+ y = y0;
+ int collision = 0;
+ do {
+ int wx = rtowX(w, x);
+ int wy = rtowY(w, y);
+ w.setColor("black");
+ w.fillCircle(wx, wy, 2);
+
+ float vxr = vx - wnd;
+ float kvr = -k * sqrt(vxr * vxr + vy * vy);
+ float ax = kvr * vxr;
+ float ay = kvr * vy - g;
+ x += vx * dt;
+ y += vy * dt;
+ vx += ax * dt;
+ vy += ay * dt;
+
+ w.msleep(10);
+ w.setColor("skyblue");
+ w.fillCircle(wx, wy, 2);
+// w.setColor("black");
+// w.drawPoint(wx, wy);
+
+ if (y <= 0) {
+ collision = 3;
+ } else if (y < hauteurChateau) {
+ if (positionChateau1 - largeurChateau <= x
+ && positionChateau1 + largeurChateau >= x)
+ collision = 1;
+ else if (positionChateau2 - largeurChateau <= x
+ && positionChateau2 + largeurChateau >= x)
+ collision = 2;
+ }
+ if (!collision) {
+ float h = hauteurMontagne(largeurMont, hauteurMont, x);
+ if (h > 0 && y < h)
+ collision = 3;
+ }
+ } while (!collision);
+ return collision == 3 ? 0 : collision;
+}
+
+int jeu1(DrawingWindow& w)
+{
+ initialise(w);
+ int joueur = 2;
+ float x, y;
+ int perdant;
+ do {
+ joueur = 3 - joueur;
+
+ std::cout << "-=| Joueur " << joueur << " |=-";
+
+ float alpha;
+ float v0;
+ if (joueur <= nbJoueurs) {
+ std::cout << "\nangle ? ";
+ std::cin >> alpha;
+ std::cout << "vitesse initiale ? ";
+ std::cin >> v0;
+ } else {
+ alpha = frand(10, 90);
+ v0 = frand(10, 100);
+ std::cout << " [ " << (int )alpha << "° ; " << (int )v0 << " ]\n";
+ }
+
+ alpha = deg2rad(alpha);
+ float x0;
+ if (joueur == 1) {
+ x0 = positionChateau1 + 0.8 * largeurChateau;
+ } else {
+ x0 = positionChateau2 - 0.8 * largeurChateau;
+ alpha = PI - alpha;
+ }
+ float y0 = hauteurChateau + 1;
+ perdant = tir(w, x0, y0, v0, alpha, x, y);
+ dessineExplosion(w, x, y);
+ dessineVent(w, wnd);
+ } while (!perdant);
+ dessineFlammes(w, x, y);
+ std::stringstream msg;
+ msg << "Joueur " << perdant;
+ if (perdant == joueur)
+ msg << " s'est suicidé !";
+ else
+ msg << " a perdu !";
+ w.setColor("darkred");
+ w.setBgColor("white");
+ w.drawTextBg(w.width / 2, w.height / 3, msg.str().c_str(),
+ Qt::AlignCenter);
+ std::cout << msg.str() << "\n";
+ return perdant;
+}