- while (1)
- dessineExplosion(w, frand(rXMin, rXMax), frand(rYMin, rYMax));
-
+ const float g = 9.81;
+ const float k = 0.005;
+ const float dt = 0.1;
+ const float wnd = frand(-30, 30);
+ const float x0 = positionChateau1 + 8;
+ const float y0 = 8;
+
+ dessineVent(w, wnd);
+
+ while (1) {
+ const float v0 = frand(10, 100);
+ const float alpha = deg2rad(frand(10, 90));
+
+ float x = x0;
+ float y = y0;
+ float vx = v0 * cos(alpha);
+ float vy = v0 * sin(alpha);
+ w.setColor("black");
+ bool collision = false;
+ do {
+ int wx = rtowX(w, x);
+ int wy = rtowY(w, y);
+ 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("white");
+ w.fillCircle(wx, wy, 2);
+ w.setColor("black");
+ w.drawPoint(wx, wy);
+
+ if ((y <= 0) ||
+ (y < hauteurChateau
+ && ((positionChateau1 - largeurChateau <= x
+ && positionChateau1 + largeurChateau >= x) ||
+ (positionChateau2 - largeurChateau <= x
+ && positionChateau2 + largeurChateau >= x)))) {
+ collision = true;
+ } else {
+ float h = hauteurMontagne(largeurMont, hauteurMont, x);
+ if (h > 0 && y < h)
+ collision = true;
+ }
+ } while (!collision);
+ dessineExplosion(w, x, y);
+ }