static inline void idct_1d(int *Y) { int z1[8], z2[8], z3[8]; int t; /* Stage 1: */ but(Y[0], Y[4], z1[1], z1[0]); /* rot(sqrt(2), 6, Y[2], Y[6], &z1[2], &z1[3]); */ t=CMUL2(CK1,ADD(Y[2],Y[6])); z1[2]=SUB(t,CMUL2(ADDK1,Y[6])); z1[3]=ADD(t,CMUL2(SUBK1,Y[2])); but(Y[1], Y[7], z1[4], z1[7]); /* z1[5] = CMUL(sqrt(2), Y[3]); z1[6] = CMUL(sqrt(2), Y[5]); */ z1[5] = CMUL2(SQRT2, Y[3]); z1[6] = CMUL2(SQRT2, Y[5]); /* Stage 2: */ but(z1[0], z1[3], z2[3], z2[0]); but(z1[1], z1[2], z2[2], z2[1]); but(z1[4], z1[6], z2[6], z2[4]); but(z1[7], z1[5], z2[5], z2[7]); /* Stage 3: */ z3[0] = z2[0]; z3[1] = z2[1]; z3[2] = z2[2]; z3[3] = z2[3]; /* rot(1, 3, z2[4], z2[7], &z3[4], &z3[7]); */ t=CMUL2(CK2,ADD(z2[4],z2[7])); z3[4]=SUB(t,CMUL2(ADDK2,z2[7])); z3[7]=ADD(t,CMUL2(SUBK2,z2[4])); /* rot(1, 1, z2[5], z2[6], &z3[5], &z3[6]); */ t=CMUL2(CK3,ADD(z2[5],z2[6])); z3[5]=SUB(t,CMUL2(ADDK3,z2[6])); z3[6]=ADD(t,CMUL2(SUBK3,z2[5])); /* Final stage 4: */ but(z3[0], z3[7], Y[7], Y[0]); but(z3[1], z3[6], Y[6], Y[1]); but(z3[2], z3[5], Y[5], Y[2]); but(z3[3], z3[4], Y[4], Y[3]); }
/* Inverse 1-D Discrete Cosine Transform. Result Y is scaled up by factor sqrt(8). Original Loeffler algorithm. */ static void idct_1d(int *Y) { int z1[8], z2[8], z3[8]; /* Stage 1: */ but(Y[0], Y[4], z1[1], z1[0]); /* rot(sqrt(2), 6, Y[2], Y[6], &z1[2], &z1[3]); */ z1[2] = SUB(CMUL(8867, Y[2]), CMUL(21407, Y[6])); z1[3] = ADD(CMUL(21407, Y[2]), CMUL(8867, Y[6])); but(Y[1], Y[7], z1[4], z1[7]); /* z1[5] = CMUL(sqrt(2), Y[3]); z1[6] = CMUL(sqrt(2), Y[5]); */ z1[5] = CMUL(23170, Y[3]); z1[6] = CMUL(23170, Y[5]); /* Stage 2: */ but(z1[0], z1[3], z2[3], z2[0]); but(z1[1], z1[2], z2[2], z2[1]); but(z1[4], z1[6], z2[6], z2[4]); but(z1[7], z1[5], z2[5], z2[7]); /* Stage 3: */ z3[0] = z2[0]; z3[1] = z2[1]; z3[2] = z2[2]; z3[3] = z2[3]; /* rot(1, 3, z2[4], z2[7], &z3[4], &z3[7]); */ z3[4] = SUB(CMUL(13623, z2[4]), CMUL(9102, z2[7])); z3[7] = ADD(CMUL(9102, z2[4]), CMUL(13623, z2[7])); /* rot(1, 1, z2[5], z2[6], &z3[5], &z3[6]); */ z3[5] = SUB(CMUL(16069, z2[5]), CMUL(3196, z2[6])); z3[6] = ADD(CMUL(3196, z2[5]), CMUL(16069, z2[6])); /* Final stage 4: */ but(z3[0], z3[7], Y[7], Y[0]); but(z3[1], z3[6], Y[6], Y[1]); but(z3[2], z3[5], Y[5], Y[2]); but(z3[3], z3[4], Y[4], Y[3]); }
/** * @brief Résout un puzzle * @param[in,out] p le puzzle à résoudre * @param[in] t le damier initial * @param[in,out] os flux de sortie */ void jouer(Puzzle& p, const Tab2D& t, std::ostream& os) { Etat etatInitial; Etat etatCourant; Tab2D damierFinal; Etat etatDerive; double tempsDebutRecherche = getTime(); but(damierFinal, t.nbL, t.nbC); initialiser(etatInitial.damier, t.nbL, t.nbC); etatInitial.mouvement = FIXE; etatInitial.precedent = 0; etatInitial.g = 0; //Copie du damier inititial dans etatInitial for (unsigned int l = 0; l < t.nbL; ++l) { for (unsigned int c = 0; c < t.nbC; ++c) { etatInitial.damier.tab[l][c] = t.tab[l][c]; } } etatInitial.h = manhattan(etatInitial.damier, damierFinal); initialiser(etatDerive.damier, t.nbL, t.nbC); inserer(p.lEAE, 0, etatInitial); //étatInitial dans LEAE bool solutionTrouvee = false; bool mvtPossible; unsigned int pos; while (p.lEAE.nb != 0) { pos = minimal(p.lEAE); etatCourant = lire(p.lEAE, pos); //on prend le 1er état à explorer //insérer étatCourant dans LEE inserer(p.lEE, longueur(p.lEE), etatCourant); supprimer(p.lEAE, pos); //supprimer étatCourant de LEAE if (etatCourant.h == 0) { // le damier de étatCourant est le damier but solutionTrouvee = true; break; //sortir de la boucle while } /*pour_tout (mouvement possible associé à étatCourant) mouvement possible relatif à damier de étatCourant (etatCourant.damier) ordre d'exploration (obligatoire) NORD, EST, SUD, OUEST */ //initialiser un étatDérivé // d'après le mouvement for(int m = OUEST; m >= NORD; --m) { mvtPossible = deriver(etatCourant, (Mouvement) m, etatDerive); if (mvtPossible && !rechercher(etatDerive, p.lEAE)\ && !rechercher(etatDerive, p.lEE)) { etatDerive.precedent = longueur(p.lEE) - 1; etatDerive.h = manhattan(etatDerive.damier, damierFinal); etatDerive.g = etatCourant.g + 1; //insérer étatDérivé dans LEAE inserer(p.lEAE, longueur(p.lEAE), etatDerive); } } } double tempsFinRecherche = getTime(); cout << "Durée de recherche : " << tempsFinRecherche - tempsDebutRecherche <<" seconde(s)."<< endl; if (solutionTrouvee) { Pile sol; Etat etatSol; initialiser(sol, 3, 2); initialiser(etatSol.damier, t.nbL, t.nbC); //Stockage de la solution etatSol = lire(p.lEE, longueur(p.lEE)-1); empiler(sol, etatSol); while (etatSol.precedent != 0) { etatSol = lire(p.lEE, etatSol.precedent); empiler(sol, etatSol); } empiler(sol, etatInitial); //Affichage de la solution os << "Damier : " << t.nbL << " lignes " << t.nbC << " colonnes" << endl; os << "Solution en " << sol.sommet << " mouvements" << endl; while (!estVide(sol)) { afficher(sommet(sol), os); os << endl; depiler(sol); } detruire(sol); detruire(etatSol.damier); } else { os << "Solution non trouvée" << endl; } detruire(etatInitial.damier); detruire(etatCourant.damier); detruire(etatDerive.damier); detruire(damierFinal); }
Ultra1::StateNumber Ultra1::HelpState::Run( ) { Sim::Image bg( UBD_PREFIX "/images/mountains.jpg" ); Sim::Image but( UBD_PREFIX "/images/button.png", 255, 0, 0 ); Sim::Button menu( 0, 480, 450, 50, 3, 0, 0, 0, 40, 7, true ); menu.SetBackGround( but.image ); menu.SetForeGround( "Main Menu", app->text_writer.GetFont( GALAPOGO_36 ), 0, 0, 0 ); Sim::Button quit( 0, 540, 450, 50, 3, 0, 0, 0, 40, 7, true ); quit.SetBackGround( but.image ); quit.SetForeGround( "Quit", app->text_writer.GetFont( GALAPOGO_36 ), 0, 0, 0 ); Sim::Image bear_i( UBD_PREFIX "/images/bear.png", 0, 0, 255 ); Sim::Sprite bear( 10, 130, 20, 40, 1 ); bear.AddAnimation( 0, 0, 3, true, bear_i.image, 200, true ); Sim::Image armor_i( UBD_PREFIX "/images/armor.png", 0, 0, 255 ); Sim::Sprite armor( 10, 190, 20, 20, 1 ); armor.AddAnimation( 0, 0, 2, true, armor_i.image, 125, false ); Sim::Image force_i( UBD_PREFIX "/images/force.png", 0, 0, 255 ); Sim::Sprite force( 10, 230, 20, 20, 1 ); force.AddAnimation( 0, 0, 2, true, force_i.image, 125, false ); Sim::Image life_i( UBD_PREFIX "/images/extralife.png", 0, 0, 255 ); Sim::Sprite life( 10, 270, 20, 20, 1 ); life.AddAnimation( 0, 0, 2, true, life_i.image, 125, false ); Sim::Image coin_i( UBD_PREFIX "/images/coin.png", 0, 0, 255 ); Sim::Sprite coin( 10, 310, 20, 20, 1 ); coin.AddAnimation( 0, 0, 3, true, coin_i.image, 125, false ); SDL_Event event; while( true ) { while( SDL_PollEvent(&event) ) { if( event.type == SDL_QUIT ) { app->FadeTo( 100 ); return QUIT_STATE; } else if( event.type == SDL_KEYDOWN ) { if( event.key.keysym.sym == SDLK_ESCAPE ) { app->FadeTo( 100 ); return MENU_STATE; } } else if( event.type == SDL_MOUSEBUTTONDOWN ) { menu.HandleMouseDown( event.button.x, event.button.y ); quit.HandleMouseDown( event.button.x, event.button.y ); } else if( event.type == SDL_MOUSEBUTTONUP ) { if( menu.HandleMouseUp( event.button.x, event.button.y ) ) { app->PlaySound( BUTTON_NOISE ); app->FadeTo( 100 ); return MENU_STATE; } if( quit.HandleMouseUp( event.button.x, event.button.y ) ) { app->PlaySound( BUTTON_NOISE ); app->FadeTo( 100 ); return QUIT_STATE; } } } bear.Update( ); armor.Update( ); force.Update( ); life.Update( ); coin.Update( ); app->Clear( 0, 0, 0 ); SDL_BlitSurface( bg.image, NULL, app->screen, NULL ); app->text_writer.WriteText( app->screen, GALAPOGO_72, "Help", 10, 0, 0, 0, 0 ); // Write basic info at top... app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "In this game, you must guide Ultra Bear to the South Pole by working through every level on the map.", 10, 65, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "To beat a level, you must move Ultra Bear to the right while avoiding all of the enemies. You can kill", 10, 82, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "enemies by bouncing on their heads. Here are a few things that you will encounter:", 10, 99, 0,0,0 ); // Info beside UB and crew... app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Ultra Bear. This is the bear you must guide south. He is very Ultra.", 50, 139, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Armor. This pickup will protect Ultra Bear from one blow by an enemy.", 50, 190, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Force. This magic force field will eliminate all enemies Ultra Bear touches. It will wear off though.", 50, 230, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Extra Life. This pickup will credit Ultra Bear with one extra life.", 50, 270, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "Coin. This pickup deposits one coin in Ultra Bear's account. Once he has 100, he can trade them in for an extra life.", 50, 310, 0, 0, 0 ); app->text_writer.WriteText( app->screen, PLAIN_FONT_14, "The controls can be configured by clicking Options from the Main Menu", 10, 380, 0, 0, 0 ); menu.Draw( app->screen ); quit.Draw( app->screen ); bear.Draw( app->screen ); armor.Draw( app->screen ); force.Draw( app->screen ); life.Draw( app->screen ); coin.Draw( app->screen ); app->Flip( ); } }
void MyQGraphicsScene::chargerGraphiques(int **carte) { //--- CHARGEMENT DU TERRAIN --- QPixmap cheminHorizontal("data/Chemin/cheminHorizontal.jpg"); QPixmap cheminVertical("data/Chemin/cheminVertical.jpg"); QPixmap coinBD("data/Chemin/coinBD.jpg"); QPixmap coinBG("data/Chemin/coinBG.jpg"); QPixmap coinHD("data/Chemin/coinHD.jpg"); QPixmap coinHG("data/Chemin/coinHG.jpg"); QPixmap herbe("data/herbe.jpg"); QPixmap but("data/but.png"); QPixmap boue("data/Chemin/boue.jpg"); this->setBackgroundBrush(herbe); QGraphicsPixmapItem *I; for(int i=0;i<16;++i){ for(int j=0;j<16;++j){ if(carte[i][j] != 0) { if(carte[i][j] == 1) // vers le NORD { I = this->addPixmap(cheminVertical); I->setData(0,"NORD"); } else if(carte[i][j] == 2) // vers le SUD { I = this->addPixmap(cheminVertical); I->setData(0,"SUD"); } else if(carte[i][j] == 4) // vers l'EST { I = this->addPixmap(cheminHorizontal); I->setData(0,"EST"); } else if(carte[i][j] == 8) // vers l'OUEST { I = this->addPixmap(cheminHorizontal); I->setData(0,"OUEST"); } else if(carte[i][j] == 5) // vers le Nord EST { if(carte[i][j+1] != 1 && carte[i+1][j] != 17) I = this->addPixmap(coinBD); else I = this->addPixmap(coinHG); I->setData(0,"NORD_EST"); } else if(carte[i][j] == 6) // vers le Sud EST { if(carte[i][j-1] != 2 && carte[i-1][j] != 18) I = this->addPixmap(coinHD); else I = this->addPixmap(coinBG); I->setData(0,"SUD_EST"); } else if(carte[i][j] == 9) // vers le Nord OUEST { if(carte[i][j+1] != 1 && carte[i+1][j] != 17) I = this->addPixmap(coinBG); else I = this->addPixmap(coinHD); I->setData(0,"NORD_OUEST"); } else if(carte[i][j] == 10) // vers le Sud OUEST { if(carte[i][j-1] != 2 && carte[i-1][j] != 18) I = this->addPixmap(coinHG); else I = this->addPixmap(coinBD); I->setData(0,"SUD_OUEST"); } // TRAITER LES DIFFERENTS DEPARTS else if(carte[i][j] < 32 && carte[i][j] >= 17) // case de DEPART { if(carte[i][j] == 17) // vers le NORD { I = this->addPixmap(QPixmap("data/Chemin/Depart/cheminVerticalDepartSud.jpg")); I->setData(0,"DEPART_NORD"); } else if(carte[i][j] == 18) // vers le SUD { I = this->addPixmap(QPixmap("data/Chemin/Depart/cheminVerticalDepartNord.jpg")); I->setData(0,"DEPART_SUD"); } else if(carte[i][j] == 19) // vers l'EST { I = this->addPixmap(QPixmap("data/Chemin/Depart/cheminHorizontalDepartOuest.jpg")); I->setData(0,"DEPART_EST"); } else if(carte[i][j] == 24) // vers l'OUEST { I = this->addPixmap(QPixmap("data/Chemin/Depart/cheminHorizontalDepartEst.jpg")); I->setData(0,"DEPART_OUEST"); } else if(carte[i][j] == 21) // vers le Nord EST { if(j == 0) I = this->addPixmap(QPixmap("data/Chemin/Depart/coinBGDepartNordEst.jpg")); else I = this->addPixmap(QPixmap("data/Chemin/Depart/coinHGDepartNordEst.jpg")); I->setData(0,"DEPART_NORD_EST"); } else if(carte[i][j] == 22) // vers le Sud EST { if(i == 0) I = this->addPixmap(QPixmap("data/Chemin/Depart/coinBGDepartSudEst.jpg")); else I = this->addPixmap(QPixmap("data/Chemin/Depart/coinHDDepartSudEst.jpg")); I->setData(0,"DEPART_SUD_EST"); } else if(carte[i][j] == 25) // vers le Nord OUEST { if(j == 15) I = this->addPixmap(QPixmap("data/Chemin/Depart/coinBGDepartNordOuest.jpg")); else I = this->addPixmap(QPixmap("data/Chemin/Depart/coinHDDepartNordOuest.jpg")); I->setData(0,"DEPART_NORD_OUEST"); } else if(carte[i][j] == 26) // vers le Sud OUEST { if(i == 0) I = this->addPixmap(QPixmap("data/Chemin/Depart/coinHDDepartSudOuest.jpg")); else I = this->addPixmap(QPixmap("data/Chemin/Depart/coinHGDepartSudEst.jpg")); I->setData(0,"DEPART_SUD_OUEST"); } } else if(carte[i][j] == 32) // le but { I = this->addPixmap(but); float scale1 = (float)32/but.size().width(); float scale2 = (float)32/but.size().height(); if(scale2 > scale1) scale1 = scale2; I->setScale(scale1); I->setData(0,"BUT"); } else if(carte[i][j] == 64) // la boue { I = this->addPixmap(boue); I->setData(0,"BOUE"); } I->setPos(i*32,j*32); } else // de l'herbe { // on ajoute un item afin de respecter le quadrillage 16x16 this->addRect(i*32,j*32,1*32,1*32,QPen(Qt::NoPen),Qt::transparent)->setData(0,"HERBE"); } } } }