#include <cstdlib>
#include <sstream>
-/* Note : les coordonnées réelles vont de -100 à +100 en abscisse, et
- * de -10 à +140 en ordonnée
+/* Note : les coordonnées réelles vont de -100 à +100 en abscisse, et
+ * de -10 à +140 en ordonnée
*/
const float PI = 4.0 * atan(1.0);
const float largeurMin = 40;
const float largeurMax = 150;
+const float ventMax = 30;
+
const float largeurChateau = 8.5;
const float hauteurChateau = 7;
float hauteurMont;
float wnd;
-/* Retourne un nombre pseudo-aléatoire compris entre 0 et le paramètre
- * 'max' (exclus)
+/* Retourne un nombre pseudo-aléatoire compris entre le paramètre
+ * 'min' (inclus) et le paramètre 'max' (exclus)
*/
float frand(float min, float max)
{
return deg * PI / 180.0;
}
-// conversion coordonnées réelles -> coordonnées fenêtre
+// conversion coordonnées réelles -> coordonnées fenêtre
int rtowX(const DrawingWindow& w, float rx)
{
return (int )roundf((w.width - 1) * (rx - rXMin) / (rXMax - rXMin));
return (int )roundf((w.height - 1) * (rYMax - ry) / (rYMax - rYMin));
}
-// conversion coordonnées fenêtre -> coordonnées réelles
+// conversion coordonnées fenêtre -> coordonnées réelles
float wtorX(const DrawingWindow& w, int wx)
{
return (rXMax - rXMin) * wx / (w.width - 1) + rXMin;
float wtorY(const DrawingWindow& w, int wy)
{
- return -(rYMax - rYMin) * wy / (w.height - 1) - rYMax;
+ return -(rYMax - rYMin) * wy / (w.height - 1) + rYMax;
}
float hauteurMontagne(float largeur, float hauteur, float x)
{
largeurMont = frand(largeurMin, largeurMax);
hauteurMont = frand(hauteurMin, hauteurMax);
- wnd = frand(-30, 30);
+ wnd = frand(-ventMax, ventMax);
w.setBgColor("skyblue");
w.clearGraph();
dessineTerrain(w, largeurMont, hauteurMont);
Qt::AlignHCenter);
std::stringstream s;
s << score1 << " / " << score2;
- w.drawText(rtowX(w, 0), rtowY(w, 0) + 8, s.str().c_str(),
+ w.drawText(rtowX(w, 0), rtowY(w, 0) + 8, s.str(),
Qt::AlignHCenter);
}
-/* Retour : numéro du perdant, 0 sinon
- x et y contiennent les coordonnées de la collision
+/* 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)
} else {
alpha = frand(10, 90);
v0 = frand(10, 100);
- std::cout << " [ " << (int )alpha << "° ; " << (int )v0 << " ]"
+ std::cout << " [ " << (int )alpha << "° ; " << (int )v0 << " ]"
<< std::endl;
}
std::stringstream msg;
msg << " Joueur " << perdant;
if (perdant == joueur)
- msg << " s'est suicidé ! ";
+ 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(),
+ w.drawTextBg(w.width / 2, w.height / 3, msg.str(),
Qt::AlignCenter);
w.sync();
std::cout << msg.str() << std::endl;