void ObjetVolant::init() { //Initialise les variables setZValue(1); setPilotage(manuel); setDessinerTrajectoire(false); creerImageParDefaut(); setLooping(0); setVitesseAngulaireObjet(180.0 / 1000.0); setAccelerationObjet(100.0 / 1000000.0); setVitesseMinObjet(100.0 / 1000.0); setVitesseMaxObjet(300.0 / 1000.0); setPosition(QPointF(0, 0)); setVitesseAngulaire(0); setAngle(vitesseAngulaire() * 0); setAcceleration(0); setVitesse(vitesseMinObjet()); //Animation du looping animationLooping = new QPropertyAnimation(this, "looping"); animationLooping->setDuration(500); animationLoopingRoot = new QSequentialAnimationGroup(this); animationLoopingRoot->addPause(1500); //Attend un moment avant de se retourner animationLoopingRoot->addAnimation(animationLooping); //Animation de la position animationPosition = new QPropertyAnimation(this, "position"); animationPosition->setDuration(25); //Animation de l'angle setTransformOriginPoint(boundingRect().center()); //Met le centre de rotation au centre de l'Item animationAngle = new QPropertyAnimation(this, "angle"); animationAngle->setDuration(25); //Animation de la vitesse animationVitesse = new QPropertyAnimation(this, "vitesse"); animationVitesse->setDuration(25); //Animation principale des déplacements animationRoot = new QParallelAnimationGroup(this); animationRoot->addAnimation(animationAngle); animationRoot->addAnimation(animationVitesse); animationRoot->addAnimation(animationPosition); connect(animationRoot, SIGNAL(finished()), this, SLOT(seDeplacer())); temps.start(); seDeplacer(); }
void Lapin::sauter() { Position newPos, oldPos = getPosition() ; int nbDep = getVitesse() ; while (nbDep > 0) { // On génère une position adjacente newPos = seDeplacer() ; while (!getMonde()->positionLibre(newPos)) newPos = seDeplacer() ; // On met à jour la position dans le monde setPosition(newPos) ; unsigned int indice = getMonde()->getMap().find(oldPos)->second ; getMonde()->getMap().erase(oldPos) ; getMonde()->getMap().insert(pair<Position, unsigned>(newPos, indice)) ; } }
void ObjetVolant::seDeplacer() { int ms; double distance; double angleRadian; QPointF newPosition; double newAngle; double newVitesse; //Calcule l'angle, la vitesse et la position ms = temps.elapsed(); distance = vitesse() * ms; angleRadian = rad(angle()); newAngle = angle() + vitesseAngulaire() * ms; newVitesse = vitesse() + acceleration() * ms; newPosition = position() + QPointF(cos(angleRadian) * distance, sin(angleRadian) * distance); //Déplace l'objet volant seDeplacer(newPosition, newAngle, newVitesse); }