void boucleMap(int carte[][NB_BLOCS_HAUTEUR], SDL_Surface* ecran, SDL_Rect position) { hero_m = 1; SDLKey KEY[5]; void (*foncKEY[5])(int carte[][NB_BLOCS_HAUTEUR], SDL_Surface *ecran) = {monter, decendre, droitier,gaucher, inv}; KEY[0] = SDLK_z, KEY[1] = SDLK_s, KEY[2] = SDLK_d, KEY[3] = SDLK_q, KEY[4] = SDLK_i; int a; Input in; memset(&in,0,sizeof(in)); while((!in.key[SDLK_ESCAPE]) && hero_m) { UpdateEvents(&in); for(a = 0; a < 5; a++) { if (in.key[KEY[a]]) { foncKEY[a](carte, ecran); in.key[KEY[a]] = 0; } } if(hero_m) { effaceEcran(carte, ecran); posJoueur(ecran, position); } } }
void MainFrame::ShowChanged(wxCommandEvent& event) { if (ShowChoice->GetSelection() == SHOW_SPECIFIC) { PeriodPanel->Show(); ViewQuery->Criteria.AllEvents = false; } else { PeriodPanel->Hide(); if (ShowChoice->GetSelection() == SHOW_TODAYS || ShowChoice->GetSelection() == SHOW_UPCOMING) { CalendarCtrl->SetDate(wxDateTime::Today()); FromDatePicker->SetValue(wxDateTime::Today()); if (ShowChoice->GetSelection() == SHOW_TODAYS) ToDatePicker->SetValue(wxDateTime::Today()); else ToDatePicker->SetValue(wxDateTime::Today().Add(wxDateSpan(0, 0, 0, 7))); ViewQuery->Criteria.AllEvents = false; UpdateMonthEvents(); } else if (ShowChoice->GetSelection() == SHOW_ALL) { ViewQuery->Criteria.AllEvents = true; } } UpdateEvents(); }
bool CreditState::Update() { if(UpdateEvents()) { return false; } return true; }
void jeu_pause(SDL_Surface *ecran, SDL_Surface *afficher_maintenant, Input *in) { SDL_Surface *noir_transparente = NULL; SDL_Surface *image_pause; SDL_Rect p; SDL_SaveBMP(afficher_maintenant, "pause.bmp"); image_pause = SDL_LoadBMP("pause.bmp"); noir_transparente = SDL_CreateRGBSurface(SDL_HWSURFACE, ecran->w, ecran->h, 32, 0, 0, 0, 0); SDL_SetAlpha(noir_transparente, SDL_SRCALPHA, 80); p.x = 0; p.y = 0; while(!in->key[SDLK_ESCAPE]) { UpdateEvents(in); if( in->key[SDLK_p] ) // si appuie sur p alors quitte la pause { in->key[SDLK_ESCAPE] = 1; } SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0)); SDL_BlitSurface(image_pause, NULL, ecran, &p); SDL_BlitSurface(noir_transparente, NULL, ecran, &p); SDL_Flip(ecran); } SDL_FreeSurface(image_pause); SDL_FreeSurface(noir_transparente); }
std::vector<cl_float4> mila::meanshift::parallel::MeanShift::Run(const std::vector<cl_float4> &points, float bandwidth) { Initialize(); auto output = points; auto original_points_buffer = clpp::Buffer(context_, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, output.size() * sizeof(output.at(0)), output.data()); auto current_points_buffer = clpp::Buffer(context_, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, output.size() * sizeof(output.at(0)), output.data()); auto shifted_points_buffer = clpp::Buffer(context_, CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR, output.size() * sizeof(output.at(0)), output.data()); auto distances = std::vector<cl_float>(output.size(), 0.0f); auto distances_buffer = clpp::Buffer(context_, CL_MEM_WRITE_ONLY, output.size() * sizeof(distances.at(0))); auto global_work_size = std::vector<size_t>{output.size()}; auto difference_distance = 0.0f; auto iteration = size_t{0}; do { auto copy_buffer_event = queue_.enqueueCopyBuffer(shifted_points_buffer, current_points_buffer, 0, 0, output.size() * sizeof(output.at(0))); kernel_.setArgs(current_points_buffer, original_points_buffer, static_cast<int>(output.size()), bandwidth, shifted_points_buffer, distances_buffer); auto enqueue_nd_range_event = queue_.enqueueNDRangeKernel(kernel_, global_work_size, std::vector<clpp::Event>{copy_buffer_event}); auto read_buffer_event = queue_.enqueueReadBuffer(distances_buffer, 0, distances.size() * sizeof(distances.at(0)), distances.data(), {enqueue_nd_range_event}); queue_.finish(); difference_distance = *std::max_element(distances.begin(), distances.end()); UpdateEvents(copy_buffer_event, enqueue_nd_range_event, read_buffer_event); ++iteration; } while ((difference_distance > precision_) && (iteration < max_iterations_)); events_.read_buffer_with_output = queue_.enqueueReadBuffer(shifted_points_buffer, 0, output.size() * sizeof(output.at(0)), output.data()); queue_.finish(); return output; }
bool EventFsm::Update() { UpdateEvents(); Poll(); return true; }
int main() { Input in; initgrille(); // init SDL, chargement, tout ce que vous faites avant la boucle. SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(800,800,32,SDL_HWSURFACE); //newrect=SDL_CreateRGBSurface(SDL_HWSURFACE,300,200,32,0,0,0,0); SDL_WM_SetCaption("Othello",NULL); affiche memset(&in,0,sizeof(in)); while(!in.key[SDLK_ESCAPE] && !in.quit) { UpdateEvents(&in); if (in.mousebuttons[SDL_BUTTON_LEFT]) { in.mousebuttons[SDL_BUTTON_LEFT] = 0; // fait une seule fois. } if (in.key[SDLK_UP] && in.key[SDLK_LEFT]) { // simplification de la gestion des touches } } SDL_Quit(); return 0; }
void ButtonLog::transportChangedData() { UpdateEvents(); UpdateButtons(); if(log_action_mode!=RDAirPlayConf::Normal) { setActionMode(log_action_mode); } }
void MainFrame::FromDateChanged(wxDateEvent& event) { CalendarCtrl->SetDate(FromDatePicker->GetValue()); if (FromDatePicker->GetValue() > ToDatePicker->GetValue()) ToDatePicker->SetValue(FromDatePicker->GetValue()); UpdateMonthEvents(); UpdateEvents(); }
void ButtonLog::pausedData(int line) { for(int i=0;i<BUTTON_TOTAL_BUTTONS;i++) { if(log_line_box[i]->line()==line) { return; } } UpdateEvents(); }
// ----------------------------- // C'est ici que le jeu commence // ----------------------------- void jouer(SDL_Surface *ecran, Gestion_musique gMusique, enum Niveau niveau_v, Carte *pCarte,Input in) { Gestion_image gImage; // pour les surfaces du jeux SDL_Color couleurNoire = {0,0,0}; // la couleur du texte SDL_Rect positionObject;// pour la position de chaque object de la carte SDL_Rect positionTexte; // pour la position du texte SDL_Rect positionFondTexte; // pour la position du fond de texte // variable pour la police � utilis� TTF_Font *police; // ---------------------------- // Type de variable sp�ciale pour le jeu Monde gSerpent; // pour divers variable pour la gestion du jeu Temps gTemps; // pour la gestion de divers temps dans le jeu Position positionPomme; // pour la position de la pomme de en ce moment Position positionCerise; // pour la position de la cerise de en ce moment // ---------------------------- short continuer = 1; // si il vaut 0 alors on quitte la fonction jeu short totalPomme = 0; // pour le nombre total de pomme d�j� short pointsDeVie = 3; // pour les points de vie short effacePomme = 0; // si il vaut 1 alors e char zone_texte[100] = ""; // pour le zone texte initialisation_jouer(ecran, &gSerpent, &positionPomme, &positionCerise, &gTemps, &gImage, effacePomme, pCarte, &positionTexte, &positionFondTexte, &police, zone_texte, couleurNoire); //playMusiqueFond(gMusique); srand((time(NULL))); // pour la g�n�ration des valeur al�atoires /* tant que continuer est vrai */ while(!in.key[SDLK_ESCAPE]) { modification_texte( gSerpent, zone_texte, pointsDeVie, gTemps, &gImage, police, couleurNoire); activeCerise(&totalPomme, &gSerpent, &gTemps, pCarte, &positionCerise); if ( gSerpent.ceriseNumero > 2 ) // Si tous les pommes on �tait aper�u alors quitte le niveau { stopMusique(gMusique); // pour que la musique s'arr�te initialisation_resultats(ecran, gSerpent, gMusique, in); // affiche les r�sultats supp_surface_jouer(&gImage); // lib�re tous les surfaces destructionGestionMusique(&gMusique); // lib�re tous ce qui conserne la musique return; } position_pomme_cerise(&gSerpent, effacePomme, pCarte, &positionPomme, &positionCerise, &gTemps); UpdateEvents(&in); if( in.quit ) { in.key[SDLK_ESCAPE] = 1; } gestion_touche(&in, &gSerpent, &continuer, ecran); // pour la gestion des touches du clavier gestion_temps(pCarte, &gTemps, &positionCerise, gImage, ecran, gMusique, &pointsDeVie, &gSerpent, niveau_v, &effacePomme); // on affiche sur l'�cran affichage_ecran(pCarte, &gSerpent, &gImage, ecran, &positionObject, &positionTexte, &positionFondTexte); } supp_surface_jouer(&gImage); // lib�re tous les surface destructionGestionMusique(&gMusique); // lib�re tous ce qui conserne la musique }
void ButtonLog::playedData(int line) { for(int i=0;i<BUTTON_TOTAL_BUTTONS;i++) { if(log_line_box[i]->line()==line) { log_start_button[i]->setMode(StartButton::Play, log_log->logLine(line)->cartType()); UpdateButtons(); return; } } UpdateEvents(); }
void GameBase::DoEvents(){ Event evt; while(wnd->pollEvent(evt)){ switch(evt.type){ case Event::Closed: wnd->close(); break; } UpdatePoolEvents(evt); } UpdateEvents(); }
/*Ici les fantomes accélèrent de plus en plus * et le but est de tenir le plus longtemps * sans se faire dévorer*/ void survivor(int level, config *cfg) { if(level>=NB_LEVEL) return; int selection, counter=SDL_GetTicks(), tmp=counter, elapsed; SAVE_ENABLE=0; play_menu(level); Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_level(); init_blocks(); load_level(level); pac_restart(&pac); pac.nb_lives=1; init_ghosts(ftm, cfg); memset(&in,0,sizeof(in)); DELAY = 40; while(pac.nb_lives && POINTS) { elapsed = SDL_GetTicks()-tmp; if(elapsed > 10000) { //On accélere les fantomes speed_up(ftm, 1); tmp=SDL_GetTicks(); } UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } jouer(&pac, ftm, in, cfg, level, &msg_list); } counter = SDL_GetTicks() - counter; fprintf(stderr, "Wouaw tu as tenu %d ms!\n", counter); if(pacmanIsHuman(cfg)) draw_result("data/survivor.txt", counter); delete(&pac, ftm); }
MainFrame::MainFrame(wxWindow* parent): MainFrameBase(parent) { Quit = false; // it seems the default width of CalendarCtrl under GTK is a bit too small #if defined(__WXGTK__) wxSize NewSize = CalendarCtrl->GetSize() + wxSize(10, 0); NewSize.SetHeight(-1); CalendarCtrl->SetMinSize(NewSize); SidePanel->Fit(); #endif // making calendar header less ugly CalendarCtrl->SetHeaderColours(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); // events list preparation EventsImages = new wxImageList(16, 16); EventsImages->Add(wxBitmap(wxT("icons/event.png"), wxBITMAP_TYPE_PNG)); EventsImages->Add(wxBitmap(wxT("icons/recurrent.png"), wxBITMAP_TYPE_PNG)); EventsImages->Add(wxBitmap(wxT("icons/alarm.png"), wxBITMAP_TYPE_PNG)); EventsList->AssignImageList(EventsImages, wxIMAGE_LIST_SMALL); EventsList->InsertColumn(COLUMN_SUMMARY, _("Summary"), wxLIST_FORMAT_LEFT, 190); EventsList->InsertColumn(COLUMN_START, _("Start"), wxLIST_FORMAT_LEFT, 135); EventsList->InsertColumn(COLUMN_END, _("End"), wxLIST_FORMAT_LEFT, 135); EventsList->InsertColumn(COLUMN_CATEGORIES, _("Categories"), wxLIST_FORMAT_LEFT, 100); EventsList->InsertColumn(COLUMN_ALARM, _("A"), wxLIST_FORMAT_LEFT, 25); EventsList->InsertColumn(COLUMN_RECURRENCE, _("R"), wxLIST_FORMAT_LEFT, 45); PeriodPanel->Hide(); ToolBar->EnableTool(wxID_DELETE, false); ToolBar->EnableTool(wxID_PROPERTIES, false); SortOptions.Descending = false; SortOptions.Column = COLUMN_START; Calendar = new ICalendar("calendar.ics"); ViewQuery = new ICalendar::Query(Calendar); AlarmsQuery = new ICalendar::Query(Calendar); UpdateMonthEvents(); UpdateEvents(); Sound = new wxSound(); Connect(wxEVT_TIMER, wxTimerEventHandler(MainFrame::CheckAlarms)); AlarmsTimer = new wxTimer(this); AlarmsTimer->Start(60000); Icon = new MainFrame::TaskBarIcon(this); Icon->NormalIcon(); }
/*Permet de jouer un seul niveau * choisi dans la liste des niveaux * disponibles*/ void one_level(int level, config *cfg) { if(level>=NB_LEVEL) return; int selection; SAVE_ENABLE=0; play_menu(level); Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_level(); init_blocks(); load_level(level); pac_restart(&pac); init_ghosts(ftm, cfg); memset(&in,0,sizeof(in)); DELAY = 40-level; while(POINTS) //Tant que l'on a pas mangé toutes les pac-gommes { UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } if (in.key[SDLK_w]) POINTS=0; //cheat code for winning!! else if (in.key[SDLK_l] || !(pac.nb_lives)) //cheat code for loosing!! { lost_menu(); delete(&pac, ftm); if(pacmanIsHuman(cfg)) draw_result("data/results.txt", pac.score); return; } jouer(&pac, ftm, in, cfg, level, &msg_list); } win_menu(); if(pacmanIsHuman(cfg)) draw_result("data/results.txt", pac.score); delete(&pac, ftm); }
/*Rajouter le centrage des éléments * Vérifier que tout entre dans l'ecran * sinon réduire la police ou faire * des colonnes*/ int draw_menu(Menu menu) { int i; Input in; memset(&in,0,sizeof(in)); while(!menu.available[menu.selection]) menu.selection=(menu.selection+1)%(menu.nb_options); for(i=0; i<menu.nb_options; i++) if(!menu.available[i]) menu.couleur[i]=gris; while(!in.quit) { menu.couleur[menu.selection]=blanc; UpdateEvents(&in); if(in.key[SDLK_RETURN]) { in.key[SDLK_RETURN]=0; return menu.selection; } else if(in.key[SDLK_DOWN]) { in.key[SDLK_DOWN]=0; menu.selection=(menu.selection+1)%(menu.nb_options); while(!menu.available[menu.selection]) menu.selection=(menu.selection+1)%(menu.nb_options); } else if(in.key[SDLK_UP]) { in.key[SDLK_UP]=0; if(!(menu.selection)) menu.selection=menu.nb_options-1; else menu.selection=(menu.selection-1)%(menu.nb_options); while(!menu.available[menu.selection]) { if(!(menu.selection)) menu.selection=menu.nb_options-1; else menu.selection=(menu.selection-1)%(menu.nb_options); } } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); menu.couleur[menu.selection]=jaune; menu.p1.x=100; menu.p1.y=25; aff_pol(menu.title, 50, menu.p1, jaune); menu.p1.x=300; menu.p1.y=100; menu.pos.x=menu.p1.x-60; menu.pos.y=menu.p1.y+(menu.selection*menu.space)-5; SDL_BlitSurface(menu.img, NULL, screen, &(menu.pos)); for(i=0; i<menu.nb_options; i++) { aff_pol(menu.options[i], menu.font_size, menu.p1, menu.couleur[i]); menu.p1.y=menu.p1.y+menu.space; } SDL_Flip(screen); } return menu.nb_options-1; }
bool StartMenuState::Update() { UpdateEvents(); // Draw(); if (creditsTab){ //float opacity = 255; //mp_creditsRoll->setColor(sf::Color(255, 255, 255, opacity)); float creditsChangeSprite = turnOnCredits->getElapsedTime().asSeconds(); sf::Color opacity = mp_creditsRoll->getColor(); if (creditsChangeSprite > 1.0f) { if (checkFade == false){ fade -= Settings::ms_deltatime * 127.0f; } else { fade += Settings::ms_deltatime * 127.0f; } opacity.a = static_cast<sf::Uint8>(fade); mp_creditsRoll->setColor(opacity); if (fade <= 1){ checkFade = true; } if (fade >= 254){ checkFade = false; turnOnCredits->restart(); creditsChangeSprite = 0; fadeTimer = 3.0f; } } if (creditsChangeSprite > fadeTimer){ creditsNumber++; fadeTimer += 5.0f; if (creditsNumber == Credits.size()){ creditsNumber = 0; } mp_creditsRoll->setTexture(*Credits.at(creditsNumber)); } } else { creditsNumber = 0; mp_creditsRoll->setColor(sf::Color(255, 255, 255, 255)); mp_creditsRoll->setTexture(*Credits.at(creditsNumber)); turnOnCredits->restart(); } return !m_done; }
void analyse_touche(SDL_Surface *ecran, Monde valeur_score, Gestion_musique gMusique, Surface_Resultat resultats, TTF_Font *police, TTF_Font *police_pomme_cerise, SDL_Rect position, Input in) { while(!in.key[SDLK_ESCAPE]) { UpdateEvents(&in); // pour les évènements if( in.key[SDLK_a] ) // pour q \\ comme SDL ne prends que en charge le QWERTY { in.key[SDLK_ESCAPE] = 1; } affiche_resultat(ecran, position, resultats); } liberation_variables(resultats, police, police_pomme_cerise); stopMusique(gMusique); // pour arrêter la musique }
void MainFrame::CalendarCtrlChanged(wxCalendarEvent& event) { FromDatePicker->SetValue(CalendarCtrl->GetDate()); ToDatePicker->SetValue(CalendarCtrl->GetDate()); if (CalendarCtrl->GetDate().IsSameDate(wxDateTime::Today())) { PeriodPanel->Hide(); ShowChoice->SetSelection(SHOW_TODAYS); } else { PeriodPanel->Show(); ShowChoice->SetSelection(SHOW_SPECIFIC); } ViewQuery->Criteria.AllEvents = false; UpdateMonthEvents(); UpdateEvents(); }
void MainFrame::DeleteClicked(wxCommandEvent& event) { if (EventsList->GetSelectedItemCount() > 0 && wxMessageBox( wxString::Format(_("Are you sure you want to delete %d item(s)?"), EventsList->GetSelectedItemCount()), _("Confirmation"), wxYES_NO ) == wxYES) { long Item = -1; while ((Item = EventsList->GetNextItem(Item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1) { Calendar->DeleteEvent(((Event *)EventsList->GetItemData(Item))->BaseEvent); } UpdateMonthEvents(); UpdateEvents(); } }
void declaration_KEYBouA(SDL_Surface *ecran, void (*foncKEYBouA[3])(), SDLKey KEYBouA[3]) { int b; Input in; memset(&in,0,sizeof(in)); while(!in.key[SDLK_ESCAPE]) { posBouA(ecran); UpdateEvents(&in); for(b = 0; b < 3 ; b++) { if (in.key[KEYBouA[b]]) { foncKEYBouA[b](ecran); in.key[KEYBouA[b]] = 0; } } } }
void new_file_menu(char *new_file) { POINT p1; Input in; memset(&in,0,sizeof(in)); new_file[0]='\0'; while(!in.quit) { UpdateEvents(&in); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); if(in.quit) exit(EXIT_FAILURE); if(in.key[SDLK_RETURN]) return; p1.x=100; p1.y=50; aff_pol("TYPE NEW LEVEL NAME", 50, p1, jaune); print_key(new_file, &in, 32); //permet de taper le nom du niveau p1.x=50; p1.y=200; aff_pol(new_file, 30, p1, jaune); SDL_Flip(screen); } }
void MainFrame::ToDateChanged(wxDateEvent& event) { if (ToDatePicker->GetValue() < FromDatePicker->GetValue()) FromDatePicker->SetValue(ToDatePicker->GetValue()); UpdateEvents(); }
bool GameState::Update() { //Updates the timers m_timerGuards += Settings::ms_deltatime; m_timerPlayer += Settings::ms_deltatime; m_bumpTimer += Settings::ms_deltatime; //Updates keypresses. returns true if the game is exiting if(UpdateEvents()) { return false; } //Updates the player int noise = mp_player->Update(cl, fm, mp_fov); if(noise != -1 && m_bumpTimer > 0.91f) { sf::Sound* bump = nullptr; if(!SoundEntity::IsMuted()) { bump = Settings::ms_soundManager.GetSound("../data/sound/FURNITURE.ogg")->CreateSound(mp_player->GetPosition()); if(bump != nullptr) { bump->play(); } } m_soundRippleManager.CreateSoundRipple(mp_player->GetPosition(), noise, true, m_spriteManager.Load("Ripple.txt"), bump); m_bumpTimer = 0.0f; } //Update the listener Settings::ms_soundManager.Update(mp_player->GetPosition()); if(mp_player->IsRunning() && m_timerPlayer > 0.5f) { m_timerPlayer = 0.0f; sf::Sound* footstep = nullptr; if(mp_player->IsRightFoot()) { if(!SoundEntity::IsMuted()) { footstep = Settings::ms_soundManager.GetSound("../data/sound/RUN_1.ogg")->CreateSound(mp_player->GetPosition()); } } else { if(!SoundEntity::IsMuted()) { footstep = Settings::ms_soundManager.GetSound("../data/sound/RUN_2.ogg")->CreateSound(mp_player->GetPosition()); } } m_soundRippleManager.CreateSoundRipple(mp_player->GetPosition(), 4, true, m_spriteManager.Load("Ripple.txt"), footstep); } for(unsigned int i = 0; i < m_guards.size(); i++) { //checks to see if a guard is within hearing range of a playercreated sound sf::Vector2f pos(m_soundRippleManager.GuardNotice(m_guards.at(i)->GetPosition())); if(pos.x > 1.0f && pos.y > 1.0f) { m_guards.at(i)->AddWaypointToFront(pos); } //updates the guard m_guards.at(i)->Update(mp_player->GetPosition(), cl, fm); //checks to see if a foot step is to be created. Move or change so it is in sync with the walk animation if(m_guards.at(i)->IsWalking() && m_timerGuards > 0.5f) { AnimatedSprite* footPrint = m_spriteManager.Load("GuardFootStep.txt"); sf::Sound* sound = nullptr; if(m_guards.at(i)->GetFoot() == 0) { footPrint->ChangeAnimation("Footstep_left.png"); if(!SoundEntity::IsMuted()) { sound = Settings::ms_soundManager.GetSound("../data/sound/STEP_1.ogg")->CreateSound((m_guards.at(i)->GetPosition())); } } else { footPrint->ChangeAnimation("Footstep_right.png"); if(!SoundEntity::IsMuted()) { sound = Settings::ms_soundManager.GetSound("../data/sound/STEP_2.ogg")->CreateSound((m_guards.at(i)->GetPosition())); } } mp_guardFootSteps->AddRipple(m_guards.at(i)->GetPosition(), m_guards.at(i)->GetSprite()->getSprite()->getRotation(), footPrint, sound); } //updates the guards flashlight position and direction Vec2f vecG(m_guards.at(i)->GetPosition().x, -m_guards.at(i)->GetPosition().y + mp_view->getSize().y); float angle = (static_cast<int>(m_guards.at(i)->GetSprite()->getSprite()->getRotation() - 90) % 360) * (3.141592 / 180); lm->GetLight(m_guards.at(i))->m_directionAngle = -angle; lm->GetLight(m_guards.at(i))->SetCenter(vecG); lm->GetLight(m_guards.at(i))->CalculateAABB(); } //resets the timer if(m_timerGuards > 0.5f) { m_timerGuards = 0.0f; } //Check if door is open if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::E) || Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::Space)) { sf::CircleShape* door = cl->Circle_DoorUse(*mp_player->GetSprite()); if(door != nullptr) { if(!dm->OpenDoor(door)) { for(int i = 0; i < mp_gui->GetItemCount(); i++) { sf::Color color = mp_gui->GetItem(i)->getColor(); if(dm->OpenDoor(door, color)) { mp_gui->RemoveItem(i); if(!SoundEntity::IsMuted()) { mp_unlock->play(); mp_unlock->setPosition(door->getPosition().x, 0, door->getPosition().y); } break; } } } else { if(dm->GetDoor(door)->IsOpen()) { if(!SoundEntity::IsMuted()) { sf::Sound* mp_closeDoor = Settings::ms_soundManager.GetSound("../data/sound/DOOR_CLOSE.ogg")->CreateSound(door->getPosition()); m_soundRippleManager.CreateSoundRipple(mp_player->GetPosition(), 1, true, m_spriteManager.Load("Ripple.txt"), mp_closeDoor); } } else { if(!SoundEntity::IsMuted()) { sf::Sound* mp_openDoor = Settings::ms_soundManager.GetSound("../data/sound/DOOR_OPEN.ogg")->CreateSound(door->getPosition()); m_soundRippleManager.CreateSoundRipple(mp_player->GetPosition(), 1, true, m_spriteManager.Load("Ripple.txt"), mp_openDoor); } } } } } //check if key is close enough to pick up sf::CircleShape* circle_key = cl->Circle_KeyPickup(*mp_player->GetSprite()); if(circle_key != nullptr) { Key* key = km->PickUpKey(circle_key); sf::Color color = key->GetPickUpRadius()->getFillColor(); color.a = 255; key->setColor(color); mp_gui->AddItem(key); if (!SoundEntity::IsMuted()) { mp_keySound->play(); mp_keySound->setPosition(key->getPosition().x, 0, key->getPosition().y); } } //updates the footsteps and the soundripples mp_guardFootSteps->Update(); m_soundRippleManager.UpdateSounds(); //updates the light around the player Vec2f vec(mp_player->GetPosition().x, -mp_view->getCenter().y + mp_view->getSize().y); lm->GetLight(mp_player)->SetCenter(vec); //checks if the player has won or lost. if(Settings::ms_gameOver && m_gameOverTimer > 3.2f) { m_nextState = "GameOverState"; Settings::ms_gameOver = false; return false; } else if(mp_player->GetPosition().x > Settings::ms_exit.x - 100 && mp_player->GetPosition().x < Settings::ms_exit.x + 100 && mp_player->GetPosition().y > Settings::ms_exit.y - 100 && mp_player->GetPosition().y < Settings::ms_exit.y + 100) { m_levelToLoad++; m_levelToLoad = m_levelToLoad % 5; if(m_levelToLoad == 0) { m_nextState = "VictoryState"; return false; } else { Exit(); Enter(); } } else if(Settings::ms_gameOver) { if(m_gameOverTimer > 0.5f && !m_deathSoundPlayed) { int random = rand()%10; if(random == 0) { mp_jokeDeath->play(); } else { mp_death->play(); } m_deathSoundPlayed = true; } m_gameOverTimer += Settings::ms_deltatime; } if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F1) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LControl) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LShift)) { m_levelToLoad = 1; Exit(); Enter(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F2) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LControl) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LShift)) { m_levelToLoad = 2; Exit(); Enter(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F3) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LControl) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LShift)) { m_levelToLoad = 3; Exit(); Enter(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F4) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LControl) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LShift)) { m_levelToLoad = 4; Exit(); Enter(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F5) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LControl) && Settings::ms_inputManager.IsDownKeyboard(sf::Keyboard::LShift)) { m_levelToLoad = 0; Exit(); Enter(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F11)) { Settings::SetFullscreen(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::F12)) { Settings::SetWindowed(); } else if(Settings::ms_inputManager.IsDownOnceKeyboard(sf::Keyboard::Escape)) { m_nextState = "StartMenuState"; return false; } return true; }
void CModAPI_Component_Items::OnRender() { if(Client()->State() < IClient::STATE_ONLINE) return; int Num = Client()->SnapNumItems(IClient::SNAP_CURRENT); for(int i = 0; i < Num; i++) { IClient::CSnapItem Item; const void *pData = Client()->SnapGetItem(IClient::SNAP_CURRENT, i, &Item); switch(Item.m_Type) { case NETOBJTYPE_MODAPI_SPRITE: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPISprite((const CNetObj_ModAPI_Sprite *)pPrev, (const CNetObj_ModAPI_Sprite *)pData); } break; case NETOBJTYPE_MODAPI_ANIMATEDSPRITE: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPIAnimatedSprite((const CNetObj_ModAPI_AnimatedSprite *)pPrev, (const CNetObj_ModAPI_AnimatedSprite *)pData); } break; case NETOBJTYPE_MODAPI_SPRITECHARACTER: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPISpriteCharacter((const CNetObj_ModAPI_SpriteCharacter *)pPrev, (const CNetObj_ModAPI_SpriteCharacter *)pData); } break; case NETOBJTYPE_MODAPI_ANIMATEDSPRITECHARACTER: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPIAnimatedSpriteCharacter((const CNetObj_ModAPI_AnimatedSpriteCharacter *)pPrev, (const CNetObj_ModAPI_AnimatedSpriteCharacter *)pData); } break; case NETOBJTYPE_MODAPI_LINE: { RenderModAPILine((const CNetObj_ModAPI_Line *)pData); } break; case NETOBJTYPE_MODAPI_TEXT: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPIText((const CNetObj_ModAPI_Text *)pPrev, (const CNetObj_ModAPI_Text *)pData); } break; case NETOBJTYPE_MODAPI_ANIMATEDTEXT: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPIAnimatedText((const CNetObj_ModAPI_AnimatedText *)pPrev, (const CNetObj_ModAPI_AnimatedText *)pData); } break; case NETOBJTYPE_MODAPI_TEXTCHARACTER: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPITextCharacter((const CNetObj_ModAPI_TextCharacter *)pPrev, (const CNetObj_ModAPI_TextCharacter *)pData); } break; case NETOBJTYPE_MODAPI_ANIMATEDTEXTCHARACTER: { const void *pPrev = Client()->SnapFindItem(IClient::SNAP_PREV, Item.m_Type, Item.m_ID); if(pPrev) RenderModAPIAnimatedTextCharacter((const CNetObj_ModAPI_AnimatedTextCharacter *)pPrev, (const CNetObj_ModAPI_AnimatedTextCharacter *)pData); } break; } } int64 CurrentTime = time_get(); int64 DeltaTime = CurrentTime - m_LastTime; m_LastTime = CurrentTime; if(Client()->State() == IClient::STATE_DEMOPLAYBACK) { const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo(); if(!pInfo->m_Paused) UpdateEvents((float)((DeltaTime)/(double)time_freq())*pInfo->m_Speed); } else { if(m_pClient->m_Snap.m_pGameData && !(m_pClient->m_Snap.m_pGameData->m_GameStateFlags&GAMESTATEFLAG_PAUSED)) UpdateEvents((float)((DeltaTime)/(double)time_freq())); } }
void placing_boats(Input *in, Context *C, navire *navires) { int i; SDL_Rect R; /*Ici on crée un tableau de coordonnées sur la grille à ne pas dépasser*/ int coord_limit[4] = {0}; /*Les longeurs des navires sont de :*/ int len_sprites[NB_BOATS] = {67, 101, 101, 135, 169}; int nextTime, actualTime; int nav_places = 0; /*Boucle qui va permettre de placer un navire un par un...*/ for (i = 0; i < NB_BOATS; i++) { /*Une position initiale de notre navire a placer...*/ C->cNavires[i].x = OFFSET_L; C->cNavires[i].y = OFFSET_T; /*Limites sur la grille à ne pas dépasser (dépend de la longueur du navire et de sa rotation)*/ coord_limit[0] = OFFSET_L; coord_limit[1] = OFFSET_R-len_sprites[i]; coord_limit[2] = OFFSET_T; coord_limit[3] = OFFSET_B; nextTime = SDL_GetTicks() + 100; R.x = C->cNavires[i].x; R.y = C->cNavires[i].y; SDL_BlitSurface(C->images_h[i], NULL, C->screen, &R); /*Boucle*/ while (!in->quit) { SDL_Delay(20); actualTime = SDL_GetTicks(); if(actualTime - nextTime >= 0) { UpdateEvents(in); if(in->key[SDLK_q] || in->key[SDLK_r]) return; if(Evolution(in, &C->cNavires[i].x, &C->cNavires[i].y, coord_limit, &navires[i], len_sprites[i])) { if(!in->quit) { if(!navires[i].r) { navires[i].x[0] = (C->cNavires[i].x-OFFSET_L)/CELL_W+1; navires[i].x[1] = (C->cNavires[i].x-OFFSET_L)/CELL_W+((C->images_h[i]->w)/CELL_W); navires[i].y[0] = ((C->cNavires[i].y-450)/CELL_W)+1; navires[i].y[1] = ((C->cNavires[i].y-450)/CELL_W)+1; } else { navires[i].x[0] = (C->cNavires[i].x-OFFSET_L)/CELL_W+1; navires[i].x[1] = (C->cNavires[i].x-OFFSET_L)/CELL_W+1; navires[i].y[0] = ((C->cNavires[i].y-450)/CELL_W)+1; navires[i].y[1] = ((C->cNavires[i].y-450)/CELL_W)+((C->images_v[i]->h)/CELL_W); } } /*On regarde si il n'y a pas de chevauchement*/ if(overlap_detection(nav_places, navires)) { nav_places++; break; } } UpdateScreen(C, navires); while(in->key[SDLK_SPACE]) UpdateEvents(in); if(!in->key[SDLK_LEFT] && !in->key[SDLK_RIGHT] && !in->key[SDLK_DOWN] && !in->key[SDLK_UP] && !in->key[SDLK_RETURN]) nextTime = SDL_GetTicks(); else nextTime = SDL_GetTicks() + 160; } } } }
void configure(SDL_Surface *screen) { Color_t *left_eye_color_ptr, *right_eye_color_ptr; int *selectors[6]; font = TTF_OpenFont("resources/opensans.ttf", 20); Input in; memset(&in, 0, sizeof(in)); config = load_config(); left_eye_color_ptr = &config.left_eye_color; right_eye_color_ptr = &config.right_eye_color; erase_surface(screen); currentPosition = 0; selectors[0] = &(*left_eye_color_ptr).r; selectors[1] = &(*left_eye_color_ptr).g; selectors[2] = &(*left_eye_color_ptr).b; selectors[3] = &(*right_eye_color_ptr).r; selectors[4] = &(*right_eye_color_ptr).g; selectors[5] = &(*right_eye_color_ptr).b; while(!in.key[SDLK_ESCAPE]) { UpdateEvents(&in); if (in.key[SDLK_LEFT]) { if (currentPosition > 0) { currentPosition--; } in.key[SDLK_LEFT] = 0; } if (in.key[SDLK_RIGHT]) { if (currentPosition < 6) { currentPosition++; } in.key[SDLK_RIGHT] = 0; } if (in.key[SDLK_UP]) { if (*selectors[currentPosition] == 255) *selectors[currentPosition] = 0; else (*selectors[currentPosition])++; in.key[SDLK_UP] = 0; } if (in.key[SDLK_DOWN]) { if (*selectors[currentPosition] == 0) *selectors[currentPosition] = 255; else (*selectors[currentPosition])--; in.key[SDLK_DOWN] = 0; } erase_surface(screen); draw_color_selector(screen); SDL_Flip(screen); } save_config(config); }
/*Permet de jouer tout les niveaux * à la suite*/ void campagne(config *cfg, int cmp_level) { int selection=0, level; SAVE_ENABLE=1; Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_blocks(); memset(&in,0,sizeof(in)); while(cmp_level < CAMPAGNE_LEVEL) { level=0; while(strcmp(LEVEL_FILE[level], CAMPAGNE[cmp_level]) && level < NB_LEVEL) { level++; } DELAY = 40-cmp_level; play_menu(cmp_level); init_level(); load_level(level); pac_restart(&pac); init_ghosts(ftm, cfg); while(POINTS) //Tant que l'on a pas mangé toutes les pac-gommes { UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==1) save_game(cmp_level); else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } if (in.key[SDLK_w]) { in.key[SDLK_w]=0; POINTS=0; //cheat code for winning!! } else if (in.key[SDLK_l] || !(pac.nb_lives)) //cheat code for loosing!! { lost_menu(); draw_result("data/results.txt", pac.score); delete(&pac, ftm); return; } jouer(&pac, ftm, in, cfg, cmp_level, &msg_list); } cmp_level++; win_menu(); } draw_result("data/results.txt", pac.score); delete(&pac, ftm); }
void MainFrame::QueryChanged(wxCommandEvent& event) { UpdateEvents(); }