diff --git a/src/audio.cc b/src/audio.cc index 5b812af..7663d33 100644 --- a/src/audio.cc +++ b/src/audio.cc @@ -33,7 +33,7 @@ /*** Variable globales ***/ /*************************/ extern sNewPreference Pref; -extern int Horloge; +extern int currentTime; /*** Constructeur et Destructeur ***/ /***********************************/ @@ -162,10 +162,10 @@ void Audio::Play(eSon So) } if (So == sClic) { - if (Horloge - MemoHorloge <= 120) { + if (currentTime - MemorizedTime <= 120) { return; } - MemoHorloge = Horloge; + MemorizedTime = currentTime; } Mix_PlayChannel(-1, Son[So], 0); diff --git a/src/audio.h b/src/audio.h index 4823562..40f1bb1 100644 --- a/src/audio.h +++ b/src/audio.h @@ -66,7 +66,7 @@ class Audio /*** Variables ***/ int N { 0 }; // Nombre d'échantillon audio int NMus { 0 }; // Numéro de la music en cours - int MemoHorloge { 0 }; // Mémorise l'horloge pour les clics + int MemorizedTime { 0 }; // Mémorise l'horloge pour les clics Mix_Chunk **Son { nullptr }; // Pointe sur les sons }; diff --git a/src/editor.cc b/src/editor.cc index b6ed9c2..eaf7cd8 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -43,8 +43,8 @@ extern SDL_Renderer *sdlRenderer; extern Sprite *Sprites; extern sNewPreference Pref; -extern int Horloge; -extern int HorlogeAvant; +extern int currentTime; +extern int previousTime; extern Level level; @@ -62,10 +62,10 @@ eMenu Editor::SDLMain(int NumNiv) NumN = NumNiv; - Affiche(); // Charge le tableau + Draw(); // Charge le tableau SDL_RenderPresent(sdlRenderer); - Horloge = SDL_GetTicks(); // Prend l'horloge + currentTime = SDL_GetTicks(); // Prend l'horloge Option = rail; @@ -82,7 +82,7 @@ eMenu Editor::SDLMain(int NumNiv) switch (event.type) { case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_ENTER) { - Affiche(); + Draw(); } break; case SDL_KEYDOWN: @@ -173,10 +173,10 @@ eMenu Editor::SDLMain(int NumNiv) case pluscourt: level.T[NumN].T[cy * LT + cx] = C_Reduit; break; - case vitesse: + case speed: level.T[NumN].T[cy * LT + cx] = C_Speed; break; - case vie: + case life: level.T[NumN].T[cy * LT + cx] = C_Live; break; case (e_Sprite)(locomotive + D_Top): @@ -193,12 +193,12 @@ eMenu Editor::SDLMain(int NumNiv) } // Gère les Horloges et la pose - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Fait l'affichage - Affiche(); + Draw(); SDL_RenderPresent(sdlRenderer); } while (true); @@ -208,7 +208,7 @@ eMenu Editor::SDLMain(int NumNiv) /*** Charge un tableau ***/ /*************************/ -void Editor::Affiche() const +void Editor::Draw() const { int i, x, y, m, cx, cy; unsigned char *T; @@ -217,7 +217,7 @@ void Editor::Affiche() const T = level.T[NumN].T; // Fabrique le fond du jeu - Sprites[fond].Affiche(400, 300, 0); + Sprites[fond].Draw(400, 300, 0); // Affiche le circuit for (i = 0; i < LT * HT; i++) { @@ -241,35 +241,35 @@ void Editor::Affiche() const m += 1; } - Sprites[rail].Affiche(x, y, NumRail[m]); + Sprites[rail].Draw(x, y, NumRail[m]); } } // Affiche les décorations for (i = 0; i < level.T[NumN].NDeco; i++) { - Sprites[deco].Affiche(level.T[NumN].Deco[i].x, level.T[NumN].Deco[i].y, level.T[NumN].Deco[i].NumSpr); + Sprites[deco].Draw(level.T[NumN].Deco[i].x, level.T[NumN].Deco[i].y, level.T[NumN].Deco[i].NumSpr); } // Affiche numero du niveau - AfficheChiffre(740, 130, NumN + 1); + DrawNumber(740, 130, NumN + 1); // Affiche les options for (i = 0; i < LT * HT; i++) { switch (T[i]) { case C_Wagon: // Si un loco - Sprites[wagon].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + Sprites[wagon].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; case C_Allonge: // Si plus long - Sprites[pluslong].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + Sprites[pluslong].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; case C_Reduit: // Si plus court - Sprites[pluscourt].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + Sprites[pluscourt].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; case C_Speed: // Si plus vite - Sprites[vitesse].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + Sprites[speed].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; case C_Live: // Si une vie - Sprites[vie].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + Sprites[life].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; } } @@ -277,16 +277,16 @@ void Editor::Affiche() const // Affiche le départ de la locomotive switch (level.T[NumN].DepDir) { case D_Top: - Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 0); + Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 0); break; case D_Bottom: - Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 40); + Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 40); break; case D_Left: - Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 80); + Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 80); break; case D_Right: - Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 120); + Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 120); break; } @@ -296,24 +296,24 @@ void Editor::Affiche() const case wagon: case pluslong: case pluscourt: - case vitesse: - case vie: - Sprites[Option].Affiche(740, 200, 0); + case speed: + case life: + Sprites[Option].Draw(740, 200, 0); break; case (e_Sprite)(locomotive + D_Top): - Sprites[locomotive].Affiche(740, 200, 0); + Sprites[locomotive].Draw(740, 200, 0); break; case (e_Sprite)(locomotive + D_Bottom): - Sprites[locomotive].Affiche(740, 200, 40); + Sprites[locomotive].Draw(740, 200, 40); break; case (e_Sprite)(locomotive + D_Left): - Sprites[locomotive].Affiche(740, 200, 80); + Sprites[locomotive].Draw(740, 200, 80); break; case (e_Sprite)(locomotive + D_Right): - Sprites[locomotive].Affiche(740, 200, 120); + Sprites[locomotive].Draw(740, 200, 120); break; case deco: - Sprites[deco].Affiche(740, 200, NumDeco); + Sprites[deco].Draw(740, 200, NumDeco); break; default: break; @@ -321,10 +321,10 @@ void Editor::Affiche() const // Affiche le curseur if (Option != deco) { - Sprites[curseur].Affiche(m_mouse.Px, m_mouse.Py, 0); + Sprites[cursor].Draw(m_mouse.Px, m_mouse.Py, 0); } else { - Sprites[deco].Affiche(m_mouse.Px, m_mouse.Py, NumDeco); + Sprites[deco].Draw(m_mouse.Px, m_mouse.Py, NumDeco); } } @@ -409,10 +409,10 @@ void Editor::PrendTouche(int Tou) } // test le niveau - Pref.Niveau = NumN; + Pref.Level = NumN; m_game.SDLMain(); m_mouse.Init(nullptr); - Affiche(); + Draw(); break; case 'a': Option = rail; @@ -427,10 +427,10 @@ void Editor::PrendTouche(int Tou) Option = pluscourt; break; case 't': - Option = vitesse; + Option = speed; break; case 'y': - Option = vie; + Option = life; break; } } diff --git a/src/editor.h b/src/editor.h index 7b260bf..f305e3c 100644 --- a/src/editor.h +++ b/src/editor.h @@ -43,7 +43,7 @@ class Editor /*** Fonctions ***/ /*****************/ eMenu SDLMain(int NumNiveau); // Boucle principale - void Affiche() const; // Charge un tableau + void Draw() const; // Charge un tableau void PrendTouche(int Touche); // Prend les touches enfoncées private: diff --git a/src/game.cc b/src/game.cc index 273a27b..e06d959 100644 --- a/src/game.cc +++ b/src/game.cc @@ -44,8 +44,8 @@ extern SDL_Renderer *sdlRenderer; extern Sprite *Sprites; extern sNewPreference Pref; -extern int Horloge; -extern int HorlogeAvant; +extern int currentTime; +extern int previousTime; extern Screen Ec; @@ -71,7 +71,7 @@ Game::Game(Audio &sounds, Gamepad &gamepad) : eMenu Game::SDLMain() { eMenu mRet; - int NumN = Pref.Niveau; + int NumN = Pref.Level; Help = true; Load(NumN); // Charge le tableau @@ -79,12 +79,12 @@ eMenu Game::SDLMain() Ec.CleanSpriteAndScreen(fjeu); Pause = true; - Horloge = SDL_GetTicks(); // Prend l'horloge + currentTime = SDL_GetTicks(); // Prend l'horloge DureeJeu = 0; Key = 0; // Met le options de départ du joueur - Pref.NVie = N_VIES_DEP; + Pref.Lives = N_LIVES_COUNT; Pref.Score = 0; // Prend les evenements @@ -219,13 +219,13 @@ eMenu Game::SDLMain() } // Gère les Horloges et la pose - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); - if (Pause == true || Lo.Mort > Horloge) { - HorlogeAvant = Horloge; + if (Pause == true || Lo.Mort > currentTime) { + previousTime = currentTime; } - DureeJeu += Horloge - HorlogeAvant; + DureeJeu += currentTime - previousTime; // Fait l'affichage DrawLevel(NumN); @@ -238,12 +238,12 @@ eMenu Game::SDLMain() // Fait avancer la loco if (Lo.Mort == -1 && Pause == false) { - Lo.Avance(Horloge - HorlogeAvant, DureeJeu, Touche, T); + Lo.Avance(currentTime - previousTime, DureeJeu, Touche, T); } // Test la fin d'une partie - if (Lo.Mort > -1 && Lo.Mort < Horloge) { // Si est Mort test si doit continuer ou quitter - if (Pref.NVie < 0) { + if (Lo.Mort > -1 && Lo.Mort < currentTime) { // Si est Mort test si doit continuer ou quitter + if (Pref.Lives < 0) { return mScoreEdit; // Si mort fini } if (Lo.Gagne) { @@ -254,11 +254,11 @@ eMenu Game::SDLMain() #endif NumN++; if (level.N == NumN) { - Pref.Score += Pref.NVie * 100; + Pref.Score += Pref.Lives * 100; return mScoreEdit; } - if (Pref.NiveauMax[Pref.Difficulte] < NumN) { - Pref.NiveauMax[Pref.Difficulte] = NumN; + if (Pref.LevelMax[Pref.Difficulty] < NumN) { + Pref.LevelMax[Pref.Difficulty] = NumN; } } m_sounds.NextMusic(); @@ -279,7 +279,7 @@ bool Game::Load(int NivN) { int i; - Pref.Niveau = NivN; + Pref.Level = NivN; // Recopie le tableau for (i = 0; i < LT * HT; i++) { @@ -287,7 +287,7 @@ bool Game::Load(int NivN) } // Laisse ou efface la vie suivant le niveau - switch (Pref.Difficulte) { + switch (Pref.Difficulty) { case Easy: i = 5; break; @@ -311,15 +311,15 @@ bool Game::Load(int NivN) MasqueK = 0; // Met la vitesse suivant difficulté - switch (Pref.Difficulte) { + switch (Pref.Difficulty) { case Easy: - Pref.Vitesse = Pref.VitesseMoy = VITESSE_MIN; + Pref.Speed = Pref.SpeedAverage = SPEED_MIN; break; case Hard: - Pref.Vitesse = Pref.VitesseMoy = VITESSE_MAX; + Pref.Speed = Pref.SpeedAverage = SPEED_MAX; break; default: - Pref.Vitesse = Pref.VitesseMoy = VITESSE_MOY; + Pref.Speed = Pref.SpeedAverage = SPEED_AVERAGE; } return DrawLevel(NivN); @@ -332,7 +332,7 @@ bool Game::DrawLevel(int NivN) int i, x, y, m, cx, cy; // Fabrique le fond du jeu - Sprites[fond].Affiche(400, 300, 0, Sprites[fjeu].Image[0]); + Sprites[fond].Draw(400, 300, 0, Sprites[fjeu].Image[0]); // Affiche le circuit for (i = 0; i < LT * HT; i++) { @@ -356,25 +356,25 @@ bool Game::DrawLevel(int NivN) m += 1; } - Sprites[rail].Affiche(x, y, NumRail[m], Sprites[fjeu].Image[0]); + Sprites[rail].Draw(x, y, NumRail[m], Sprites[fjeu].Image[0]); } } // Affiche les décorations #ifndef DCHILDREN for (i = 0; i < level.T[NivN].NDeco; i++) { - Sprites[deco].Affiche(level.T[NivN].Deco[i].x, level.T[NivN].Deco[i].y, level.T[NivN].Deco[i].NumSpr, + Sprites[deco].Draw(level.T[NivN].Deco[i].x, level.T[NivN].Deco[i].y, level.T[NivN].Deco[i].NumSpr, Sprites[fjeu].Image[0]); } #endif // Affiche les textes suivant la langue - AfficheText(740, 110, T_level, Sprites[fjeu].Image[0]); - AfficheText(740, 180, T_score, Sprites[fjeu].Image[0]); - AfficheText(740, 260, T_options, Sprites[fjeu].Image[0]); - AfficheText(740, 340, T_lives, Sprites[fjeu].Image[0]); + DrawText(740, 110, T_level, Sprites[fjeu].Image[0]); + DrawText(740, 180, T_score, Sprites[fjeu].Image[0]); + DrawText(740, 260, T_options, Sprites[fjeu].Image[0]); + DrawText(740, 340, T_lives, Sprites[fjeu].Image[0]); - AfficheChiffre(740, 140, Pref.Niveau + 1, Sprites[fjeu].Image[0]); + DrawNumber(740, 140, Pref.Level + 1, Sprites[fjeu].Image[0]); return true; } @@ -552,10 +552,10 @@ void Game::AfficheEcran() Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; case C_Speed: // Si plus vite - Ec.PrintSprite(vitesse, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + Ec.PrintSprite(speed, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; case C_Live: // Si une vie - Ec.PrintSprite(vie, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + Ec.PrintSprite(life, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; } } @@ -566,14 +566,14 @@ void Game::AfficheEcran() } // Affiche tableau de bord - Ec.PrintOptions(Pref.NVie, Pref.Score); - if (Pref.EcartWagon < ECARTWAGON_MOY) { + Ec.PrintOptions(Pref.Lives, Pref.Score); + if (Pref.WagonGap < WAGON_GAP_MIN) { Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000) % 50, 715, 295); } - if (Pref.EcartWagon > ECARTWAGON_MOY) { + if (Pref.WagonGap > WAGON_GAP_AVERAGE) { Ec.PrintSprite(pluslong, (DureeJeu * 40 / 1000) % 50, 715, 295); } - if (Pref.VitesseMoy > Pref.Vitesse) { - Ec.PrintSprite(vitesse, (DureeJeu * 40 / 1000 + 7) % 50, 765, 295); + if (Pref.SpeedAverage > Pref.Speed) { + Ec.PrintSprite(speed, (DureeJeu * 40 / 1000 + 7) % 50, 765, 295); } } diff --git a/src/loco.cc b/src/loco.cc index 1889a76..db30b66 100644 --- a/src/loco.cc +++ b/src/loco.cc @@ -36,7 +36,7 @@ /*** Variables globales ***/ /**************************/ extern sNewPreference Pref; -extern int Horloge; +extern int currentTime; extern int MasqueK; int AddDir[] = { -1, 1, -LT, LT }; @@ -58,10 +58,10 @@ void Loco::Init(int Pos, int Direction) PLoco = 0; // Pointe sur la première case PInter = -1; - Vitesse = Reduit = Alonge = 0; // Pas d'alongement + Speed = Reduce = Extend = 0; // Pas d'alongement Mort = -1; Gagne = false; - Pref.EcartWagon = ECARTWAGON_MOY; + Pref.WagonGap = WAGON_GAP_AVERAGE; // Initialise les variables for (i = 0; i < 256; i++) { @@ -103,7 +103,7 @@ void Loco::Init(int Pos, int Direction) // Initialise la loco et son wagon à charbon NWagon = 2; Wagon[0] = locomotive; - Wagon[1] = charbon; + Wagon[1] = coal_wagon; PosWagon[0].SprStart = PosWagon[1].SprStart = N_SPR_START; PosWagon[0].dx = PosWagon[0].dy = -10; PosWagon[0].fx = PosWagon[0].fy = -10; @@ -128,7 +128,7 @@ void Loco::Display(Screen &Ec) for (i = 0; i < NWagon; i++) { // Cherche les points du wagons switch (Wagon[i]) { - case charbon: + case coal_wagon: p1 = ltrain + 11; p2 = ltrain + 36 - 11; ltrain += 36.0; @@ -224,12 +224,12 @@ void Loco::Display(Screen &Ec) if (PosWagon[i].SprStart < N_SPR_START) { PosWagon[i].SprStart += MemoDuree * N_SPR_START / 750.0; if (PosWagon[i].SprStart < N_SPR_START) { - Ec.PrintSprite(nouveau_wagon, (int)(PosWagon[i].SprStart), x1, y1); + Ec.PrintSprite(new_wagon, (int)(PosWagon[i].SprStart), x1, y1); } } // Met l'ecart entre les wagons - ltrain += Pref.EcartWagon; + ltrain += Pref.WagonGap; } } @@ -259,7 +259,7 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) } } if (Gagne) { - Mort = Horloge + DUREE_PAUSE; + Mort = currentTime + PAUSE_DURATION; m_audio.Play(sEnd); } break; @@ -267,33 +267,33 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) m_audio.Play(sEtire); Tableau[T[PLoco].P] = 1; // efface l'option Pref.Score += 20; - if (Reduit > DureeJeu) { - Reduit = DureeJeu - 1; + if (Reduce > DureeJeu) { + Reduce = DureeJeu - 1; } else { - Alonge = DureeJeu + DUREE_ALONGE; + Extend = DureeJeu + EXTENSION_DURATION; } break; case C_Reduit: // Si réduit la loco m_audio.Play(sReduit); Tableau[T[PLoco].P] = 1; // efface l'option - if (Alonge > DureeJeu) { - Alonge = DureeJeu - 1; + if (Extend > DureeJeu) { + Extend = DureeJeu - 1; } else { - Reduit = DureeJeu + DUREE_REDUIT; + Reduce = DureeJeu + REDUCTION_DURATION; } break; case C_Speed: // Si Vitesse m_audio.Play(sSpeed); Tableau[T[PLoco].P] = 1; // efface l'option Pref.Score += 30; - Vitesse = DureeJeu + DUREE_VITESSE; + Speed = DureeJeu + SPEED_DURATION; break; case C_Live: // Si Vie m_audio.Play(sLive); Tableau[T[PLoco].P] = 1; // efface l'option - Pref.NVie++; + Pref.Lives++; break; } @@ -307,10 +307,10 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) Ec2 = vx * vx + vy * vy; // Si colition le signale - if (Mort < Horloge && (Ec1 < RAYON_TOUCHE || Ec2 <= RAYON_TOUCHE)) { + if (Mort < currentTime && (Ec1 < RAYON_TOUCHE || Ec2 <= RAYON_TOUCHE)) { m_audio.Play(sCrash); - Pref.NVie--; - Mort = Horloge + DUREE_PAUSE; + Pref.Lives--; + Mort = currentTime + PAUSE_DURATION; } } } @@ -321,62 +321,62 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) void Loco::Avance(int Duree, long DureeJeu, int *Touche, int *Tableau) { int i; - float Dist = Pref.VitesseMoy * (float)(Duree) / 1000.0; + float Dist = Pref.SpeedAverage * (float)(Duree) / 1000.0; MemoDuree = (float)(Duree); TestCase(Dist, DureeJeu, Tableau); // Test si doit Réduire le wagon - if (Reduit > DureeJeu) { - if (Pref.EcartWagon > ECARTWAGON_MIN) { // Si doit réduire - Pref.EcartWagon -= (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon - 1)) / 1000.0; - if (Pref.EcartWagon < ECARTWAGON_MIN) { - Pref.EcartWagon = ECARTWAGON_MIN; + if (Reduce > DureeJeu) { + if (Pref.WagonGap > WAGON_GAP_MIN) { // Si doit réduire + Pref.WagonGap -= (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon - 1)) / 1000.0; + if (Pref.WagonGap < WAGON_GAP_MIN) { + Pref.WagonGap = WAGON_GAP_MIN; } } } else { // Si temps est passé - if (Pref.EcartWagon < ECARTWAGON_MOY) { // Si doit ralonger le wagon - Pref.EcartWagon += (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon)) / 1000.0; - if (Pref.EcartWagon > ECARTWAGON_MOY) { - Pref.EcartWagon = ECARTWAGON_MOY; + if (Pref.WagonGap < WAGON_GAP_AVERAGE) { // Si doit ralonger le wagon + Pref.WagonGap += (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon)) / 1000.0; + if (Pref.WagonGap > WAGON_GAP_AVERAGE) { + Pref.WagonGap = WAGON_GAP_AVERAGE; } } } // Test si doit Ralonger le wagon - if (Alonge > DureeJeu) { - if (Pref.EcartWagon < ECARTWAGON_MAX) { // Si doit Ralonger - Pref.EcartWagon += (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon)) / 1000.0; - if (Pref.EcartWagon > ECARTWAGON_MAX) { - Pref.EcartWagon = ECARTWAGON_MAX; + if (Extend > DureeJeu) { + if (Pref.WagonGap < WAGON_GAP_MAX) { // Si doit Ralonger + Pref.WagonGap += (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon)) / 1000.0; + if (Pref.WagonGap > WAGON_GAP_MAX) { + Pref.WagonGap = WAGON_GAP_MAX; } } } else { // Si temps est passé - if (Pref.EcartWagon > ECARTWAGON_MOY) { // Si doit ralonger le wagon - Pref.EcartWagon -= (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon - 1)) / 1000.0; - if (Pref.EcartWagon < ECARTWAGON_MOY) { - Pref.EcartWagon = ECARTWAGON_MOY; + if (Pref.WagonGap > WAGON_GAP_AVERAGE) { // Si doit ralonger le wagon + Pref.WagonGap -= (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon - 1)) / 1000.0; + if (Pref.WagonGap < WAGON_GAP_AVERAGE) { + Pref.WagonGap = WAGON_GAP_AVERAGE; } } } // Test si doit modifier la vitesse de la loco - if (Vitesse > DureeJeu) { - if (Pref.VitesseMoy < Pref.Vitesse * 2) { // Si doit accelerer - Pref.VitesseMoy += (float)(Duree) / 40.0; - if (Pref.VitesseMoy > Pref.Vitesse * 2) { - Pref.VitesseMoy = Pref.Vitesse * 2; + if (Speed > DureeJeu) { + if (Pref.SpeedAverage < Pref.Speed * 2) { // Si doit accelerer + Pref.SpeedAverage += (float)(Duree) / 40.0; + if (Pref.SpeedAverage > Pref.Speed * 2) { + Pref.SpeedAverage = Pref.Speed * 2; } } } else { - if (Pref.VitesseMoy > Pref.Vitesse) { // Si doit ralentir - Pref.VitesseMoy -= (float)(Duree) / 40.0; - if (Pref.VitesseMoy < Pref.Vitesse) { - Pref.VitesseMoy = Pref.Vitesse; + if (Pref.SpeedAverage > Pref.Speed) { // Si doit ralentir + Pref.SpeedAverage -= (float)(Duree) / 40.0; + if (Pref.SpeedAverage < Pref.Speed) { + Pref.SpeedAverage = Pref.Speed; } } } @@ -669,10 +669,10 @@ void Loco::FindPoint(float Dist, int &x, int &y) /*********************************/ void Loco::AddLoco() { - Wagon[NWagon] = (e_Sprite)(rand() % (wagon - buches) + buches); + Wagon[NWagon] = (e_Sprite)(rand() % (wagon - logs_wagon) + logs_wagon); if (Wagon[NWagon] == Wagon[NWagon - 1]) { // Evite 2 fois le meme wagon if (Wagon[NWagon] + 1 == wagon) { - Wagon[NWagon] = buches; + Wagon[NWagon] = logs_wagon; } else { Wagon[NWagon] = (e_Sprite)(Wagon[NWagon] + 1); diff --git a/src/loco.h b/src/loco.h index 6160615..302a78e 100644 --- a/src/loco.h +++ b/src/loco.h @@ -74,7 +74,7 @@ class Loco private: /*** Variables ***/ - long Reduit, Alonge, Vitesse; // Memorise l'horloge de fin si doit réduire ou alonger le train + long Reduce, Extend, Speed; // Memorise l'horloge de fin si doit réduire ou alonger le train int PLoco; // Position de la tête de la loco dans le tableau float D; // Distance parcourue par la loco struct s_TLoco T[256]; // Mémorise le parcour de la loco maxi = 256 cases diff --git a/src/main.cc b/src/main.cc index 1100443..054bc14 100644 --- a/src/main.cc +++ b/src/main.cc @@ -46,35 +46,35 @@ #include "editor.h" #include "utils.h" -/*** Variables globales ***/ +/*** Global variables ***/ /************************/ -SDL_Window *sdlWindow; // Pointe sur l'écran video -SDL_Renderer *sdlRenderer; // Pointe sur l'écran video +SDL_Window *sdlWindow; // Screen video pointer +SDL_Renderer *sdlRenderer; // Screen video pointer char Titre[] = "Li-ri V" VERSION; -Sprite *Sprites = nullptr; // Pointe sur les sprites -int NSprites = 0; // Nombre de sprites en mémoire -Screen Ec; // Pointe sur les 2 buffets vidéo -sNewPreference Pref; // Tableau des préférences. -Level level; // Gère les niveaux +Sprite *Sprites = nullptr; // Sprites pointer +int NSprites = 0; // Number of sprites in memory +Screen Ec; // 2 Video buffer pointer +sNewPreference Pref; // Preference table. +Level level; -int Horloge = 0; // Horloges du jeu -int HorlogeAvant = 0; +int currentTime = 0; // Game clock +int previousTime = 0; #if defined(__unix__) || defined(__HAIKU__) -char DefPath[256]; // Chemin par defaut dans arg +char DefPath[256]; // Default path #endif -/*** Initialise les preferences ***/ -/**********************************/ +/*** Initialize preferences ***/ +/******************************/ void InitPref() { #if defined(__unix__) || defined(__HAIKU__) DefPath[0] = 0; #endif - for (int i = 0; i < 8; i++) { // Vide les scores + for (int i = 0; i < 8; i++) { // Empty the scores Pref.Sco[i].Score = 0; Pref.Sco[i].Name[0] = 0; } @@ -82,14 +82,14 @@ void InitPref() Utils::LoadPref(); } -/*** Preogramme principale ***/ -/*****************************/ +/*** Main program ***/ +/********************/ int main(int narg, char *argv[]) { int i; eMenu RetM, RetMenu = mMenu; - // Initialise les préferences + // Initialize preferences InitPref(); #if defined(__unix__) || defined(__HAIKU__) if (narg > 1) { @@ -103,10 +103,10 @@ int main(int narg, char *argv[]) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s", SDL_GetError()); exit(-1); } - // Ferme le programme correctement quand quit + // Close the program properly when quitting atexit(SDL_Quit); - // Demande la resolution Video + // Set resolution int vOption = SDL_WINDOW_RESIZABLE; if (Pref.FullScreen) { vOption |= SDL_WINDOW_FULLSCREEN_DESKTOP; @@ -117,7 +117,7 @@ int main(int narg, char *argv[]) SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_RenderSetLogicalSize(sdlRenderer, 800, 600); - SDL_ShowCursor(0); // Masque le curseur + SDL_ShowCursor(0); // Hide cursor Audio audio; audio.Init(); @@ -141,13 +141,13 @@ int main(int narg, char *argv[]) Menu MainMenu { game, audio, mouse, gamepad }; game.setMenu(&MainMenu); - HorlogeAvant = Horloge = SDL_GetTicks(); + previousTime = currentTime = SDL_GetTicks(); srand(SDL_GetTicks()); // ask locale if first run - if (Pref.Langue == -1) { + if (Pref.Language == -1) { RetMenu = MainMenu.SDLMain_Language(); - LoadLangue(); + LoadLanguage(); } // menu switch @@ -156,7 +156,7 @@ int main(int narg, char *argv[]) case mMenu: RetM = MainMenu.SDLMain(); break; - case mLangue: + case mLanguage: RetM = MainMenu.SDLMain_Language(); break; case mOption: @@ -171,7 +171,7 @@ int main(int narg, char *argv[]) case mMenuSpeed: RetM = MainMenu.SDLMain_Speed(); break; - case mMenuNiveau: + case mMenuLevel: RetM = MainMenu.SDLMain_Level(); break; case mGame: @@ -197,7 +197,7 @@ int main(int narg, char *argv[]) } delete[] Sprites; - Utils::SauvePref(); + Utils::SavePref(); SDL_DestroyRenderer(sdlRenderer); SDL_DestroyWindow(sdlWindow); diff --git a/src/menu.cc b/src/menu.cc index 6432693..167a249 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -51,8 +51,8 @@ /*** Variables globales ***/ /**************************/ -extern int Horloge; -extern int HorlogeAvant; +extern int currentTime; +extern int previousTime; extern SDL_Window *sdlWindow; extern SDL_Renderer *sdlRenderer; extern Sprite *Sprites; @@ -68,16 +68,16 @@ void Sleeping() { int delay; - if ((Horloge - HorlogeAvant) < (1000 / 60)) { - delay = 1000 / 60 - (Horloge - HorlogeAvant); + if ((currentTime - previousTime) < (1000 / 60)) { + delay = 1000 / 60 - (currentTime - previousTime); SDL_Delay(delay); - Horloge = SDL_GetTicks(); + currentTime = SDL_GetTicks(); } } /*** Ajoute une entrée dans le tableau des boutons ***/ /*****************************************************/ -void AddBouton(int Num, e_Sprite NumSp, int X, int Y) +void AddButton(int Num, e_Sprite NumSp, int X, int Y) { int const NumS = (int)NumSp; @@ -117,19 +117,19 @@ eMenu Menu::SDLMain() do { SDL_RenderClear(sdlRenderer); // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); - Sprites[menu].Affiche(400, 340, 0, Sprites[fmenu].Image[0]); - Sprites[titre].Affiche(400, 65, 0, Sprites[fmenu].Image[0]); - Sprites[copyright].Affiche(400, 587, 0, Sprites[fmenu].Image[0]); - - AfficheText(400, 229, T_play, Sprites[fmenu].Image[0]); - AddBouton(0, T_play, 400, 229); - AfficheText(400, 306, T_scores, Sprites[fmenu].Image[0]); - AddBouton(1, T_scores, 400, 306); - AfficheText(400, 384, T_moptions, Sprites[fmenu].Image[0]); - AddBouton(2, T_moptions, 400, 384); - AfficheText(400, 461, T_quit, Sprites[fmenu].Image[0]); - AddBouton(3, T_quit, 400, 461); + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[menu].Draw(400, 340, 0, Sprites[fmenu].Image[0]); + Sprites[title].Draw(400, 65, 0, Sprites[fmenu].Image[0]); + Sprites[copyright].Draw(400, 587, 0, Sprites[fmenu].Image[0]); + + DrawText(400, 229, T_play, Sprites[fmenu].Image[0]); + AddButton(0, T_play, 400, 229); + DrawText(400, 306, T_scores, Sprites[fmenu].Image[0]); + AddButton(1, T_scores, 400, 306); + DrawText(400, 384, T_moptions, Sprites[fmenu].Image[0]); + AddButton(2, T_moptions, 400, 384); + DrawText(400, 461, T_quit, Sprites[fmenu].Image[0]); + AddButton(3, T_quit, 400, 461); Menu_Py[4].DepX = -1; SDL_Event event; while (SDL_PollEvent(&event)) { @@ -176,7 +176,7 @@ eMenu Menu::SDLMain() break; default: key = event.key.keysym.sym & 0x7F; // Prend le caracataire correspondant à la touche - if (CharExiste(key) == true) { // Si la caractaire existe bien + if (CharExist(key) == true) { // Si la caractaire existe bien for (i = 2; i >= 0; i--) { MCode[i + 1] = MCode[i]; // décale le code } @@ -195,8 +195,8 @@ eMenu Menu::SDLMain() } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage @@ -221,38 +221,38 @@ eMenu Menu::SDLMain_Language() int Ecart; int i; int x, y; - int const OldLangue = Pref.Langue; + int const OldLangue = Pref.Language; // Initialisations Divers m_mouse.Init(Menu_Py); // Initialise la sourie - PyE = Pref.Langue; + PyE = Pref.Language; if (PyE == -1) { PyE = 1; } SDL_RenderClear(sdlRenderer); // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); - // Affiche les langues possibles + // Draw les langues possibles NCol = 3; - if (Pref.NLangues % NCol == 0) { - NL = Pref.NLangues / NCol; + if (Pref.NLanguages % NCol == 0) { + NL = Pref.NLanguages / NCol; } else { - NL = Pref.NLangues / NCol + 1; + NL = Pref.NLanguages / NCol + 1; } Ecart = 600 / (NL + 1); - for (i = 0; i < Pref.NLangues; i++) { + for (i = 0; i < Pref.NLanguages; i++) { x = (i / NL) * (800 / 3) + (800 / 6); y = (i % NL) * Ecart + Ecart; - Sprites[T_Langue + i].Affiche(x, y, 0, Sprites[fmenu].Image[0]); - AddBouton(i, (e_Sprite)(T_Langue + i), x, y); + Sprites[T_Langue + i].Draw(x, y, 0, Sprites[fmenu].Image[0]); + AddButton(i, (e_Sprite)(T_Langue + i), x, y); } - Menu_Py[Pref.NLangues].DepX = -1; + Menu_Py[Pref.NLanguages].DepX = -1; // Efface le fond SDL_RenderPresent(sdlRenderer); @@ -260,13 +260,13 @@ eMenu Menu::SDLMain_Language() // Prend les evenements do { SDL_RenderClear(sdlRenderer); - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); - for (i = 0; i < Pref.NLangues; i++) { + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + for (i = 0; i < Pref.NLanguages; i++) { x = (i / NL) * (800 / 3) + (800 / 6); y = (i % NL) * Ecart + Ecart; - Sprites[T_Langue + i].Affiche(x, y, 0, Sprites[fmenu].Image[0]); - AddBouton(i, (e_Sprite)(T_Langue + i), x, y); + Sprites[T_Langue + i].Draw(x, y, 0, Sprites[fmenu].Image[0]); + AddButton(i, (e_Sprite)(T_Langue + i), x, y); } SDL_Event event; @@ -286,19 +286,19 @@ eMenu Menu::SDLMain_Language() switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button - if (Pref.Langue == -1) { - Pref.Langue = PyE; + if (Pref.Language == -1) { + Pref.Language = PyE; } return mMenu; case SDLK_UP: PyE--; if (PyE < 0) { - PyE = Pref.NLangues - 1; + PyE = Pref.NLanguages - 1; } break; case SDLK_DOWN: PyE++; - if (PyE >= Pref.NLangues) { + if (PyE >= Pref.NLanguages) { PyE = 0; } break; @@ -308,7 +308,7 @@ eMenu Menu::SDLMain_Language() } break; case SDLK_RIGHT: - if (PyE + NL < Pref.NLangues) { + if (PyE + NL < Pref.NLanguages) { PyE += NL; } break; @@ -320,9 +320,9 @@ eMenu Menu::SDLMain_Language() case ' ': case SDLK_RETURN: case SDLK_KP_ENTER: - Pref.Langue = PyE; - if (Pref.Langue != OldLangue) { - LoadLangue(); + Pref.Language = PyE; + if (Pref.Language != OldLangue) { + LoadLanguage(); } return mMenu; default: @@ -337,8 +337,8 @@ eMenu Menu::SDLMain_Language() } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage @@ -364,29 +364,29 @@ void Menu::InitMain_Options() // PyE=4; // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); - Sprites[gmenu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); - Sprites[keys].Affiche(610, 455, 0, Sprites[fmenu].Image[0]); + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[gmenu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[keys].Draw(610, 455, 0, Sprites[fmenu].Image[0]); - AddBouton(0, bruitage, 140, 110); - AddBouton(1, music, 160, 200); + AddButton(0, sound, 140, 110); + AddButton(1, music, 160, 200); - AddBouton(2, fscreen, 190, 300); + AddButton(2, fscreen, 190, 300); Menu_Py[2].DepX -= 40; Menu_Py[2].FinX = 625 + 40 + Sprites[fscreen].Dim[0].L / 2; - Sprites[fscreen].Affiche(185, 300, 0, Sprites[fmenu].Image[0]); - Sprites[window].Affiche(625, 300, 0, Sprites[fmenu].Image[0]); + Sprites[fscreen].Draw(185, 300, 0, Sprites[fmenu].Image[0]); + Sprites[window].Draw(625, 300, 0, Sprites[fmenu].Image[0]); - AddBouton(3, monde, 180, 400); + AddButton(3, earth, 180, 400); // Centre à gauche le text de menu CentreM = 120 + Sprites[T_menu].Dim[0].L / 2; - AfficheText(CentreM, 490, T_menu, Sprites[fmenu].Image[0]); - AddBouton(4, T_menu, CentreM, 490); + DrawText(CentreM, 490, T_menu, Sprites[fmenu].Image[0]); + AddButton(4, T_menu, CentreM, 490); - // Boutons des bruitages - Sprites[fleches].Affiche(250, 110, 1, Sprites[fmenu].Image[0]); - Sprites[fleches].Affiche(700, 110, 4, Sprites[fmenu].Image[0]); + // Boutons des sounds + Sprites[arrows].Draw(250, 110, 1, Sprites[fmenu].Image[0]); + Sprites[arrows].Draw(700, 110, 4, Sprites[fmenu].Image[0]); Menu_Py[5].DepX = 230; Menu_Py[5].DepY = 70; Menu_Py[5].FinX = 475; @@ -402,8 +402,8 @@ void Menu::InitMain_Options() Menu_Py[6].Valide = true; // Boutons de musics - Sprites[fleches].Affiche(250, 200, 1, Sprites[fmenu].Image[0]); - Sprites[fleches].Affiche(700, 200, 4, Sprites[fmenu].Image[0]); + Sprites[arrows].Draw(250, 200, 1, Sprites[fmenu].Image[0]); + Sprites[arrows].Draw(700, 200, 4, Sprites[fmenu].Image[0]); Menu_Py[7].DepX = 230; Menu_Py[7].DepY = 155; Menu_Py[7].FinX = 475; @@ -591,37 +591,37 @@ eMenu Menu::SDLMain_Options() // SDL_RenderClear(sdlRenderer); // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage // Ec.Efface(fmenu); if (Pref.FullScreen) { - Ec.PrintSprite(fleches, 1, 350, 300); - Ec.PrintSprite(fleches, 3, 450, 300); + Ec.PrintSprite(arrows, 1, 350, 300); + Ec.PrintSprite(arrows, 3, 450, 300); } else { - Ec.PrintSprite(fleches, 0, 350, 300); - Ec.PrintSprite(fleches, 4, 450, 300); + Ec.PrintSprite(arrows, 0, 350, 300); + Ec.PrintSprite(arrows, 4, 450, 300); } - NumSp = (Horloge / 30) % 25; - Ec.PrintSprite(bruitage, NumSp, 150, 110); - NumSp = (Horloge / 30) % 25; + NumSp = (currentTime / 30) % 25; + Ec.PrintSprite(sound, NumSp, 150, 110); + NumSp = (currentTime / 30) % 25; Ec.PrintSprite(music, NumSp, 150, 200); - NumSp = (Horloge / 50) % 50; - Ec.PrintSprite(monde, NumSp, 180, 400); + NumSp = (currentTime / 50) % 50; + Ec.PrintSprite(earth, NumSp, 180, 400); N = (int)(Pref.Volume * 10 + 1) / SDL_MIX_MAXVOLUME; - NumSp = (Horloge / 50) % 40 + 120; + NumSp = (currentTime / 50) % 40 + 120; for (i = 0; i < N; i++) { if (i == N - 1) { Ec.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 110); } else { - Ec.PrintSprite(buches, NumSp, (690 - 300) / 10 * i + 300, 110); + Ec.PrintSprite(logs_wagon, NumSp, (690 - 300) / 10 * i + 300, 110); } } @@ -631,7 +631,7 @@ eMenu Menu::SDLMain_Options() Ec.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 200); } else { - Ec.PrintSprite(buches, NumSp, (690 - 300) / 10 * i + 300, 200); + Ec.PrintSprite(logs_wagon, NumSp, (690 - 300) / 10 * i + 300, 200); } } @@ -689,16 +689,16 @@ eMenu Menu::SDLMain_Speed() Ec.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); - Sprites[menu].Affiche(400, 340, 0, Sprites[fmenu].Image[0]); - Sprites[titre].Affiche(400, 65, 0, Sprites[fmenu].Image[0]); - - AfficheText(400, 225, T_easy, Sprites[fmenu].Image[0]); - AddBouton(0, T_easy, 400, 225); - AfficheText(400, 340, T_normal, Sprites[fmenu].Image[0]); - AddBouton(1, T_normal, 400, 340); - AfficheText(400, 455, T_hard, Sprites[fmenu].Image[0]); - AddBouton(2, T_hard, 400, 455); + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[menu].Draw(400, 340, 0, Sprites[fmenu].Image[0]); + Sprites[title].Draw(400, 65, 0, Sprites[fmenu].Image[0]); + + DrawText(400, 225, T_easy, Sprites[fmenu].Image[0]); + AddButton(0, T_easy, 400, 225); + DrawText(400, 340, T_normal, Sprites[fmenu].Image[0]); + AddButton(1, T_normal, 400, 340); + DrawText(400, 455, T_hard, Sprites[fmenu].Image[0]); + AddButton(2, T_hard, 400, 455); Menu_Py[3].DepX = -1; SDL_Event event; @@ -741,14 +741,14 @@ eMenu Menu::SDLMain_Speed() case SDLK_KP_ENTER: switch (PyE) { case 0: - Pref.Difficulte = Easy; - return Pref.NiveauMax[Pref.Difficulte] > 0 ? mMenuNiveau : mGame; + Pref.Difficulty = Easy; + return Pref.LevelMax[Pref.Difficulty] > 0 ? mMenuLevel : mGame; case 1: - Pref.Difficulte = Normal; - return Pref.NiveauMax[Pref.Difficulte] > 0 ? mMenuNiveau : mGame; + Pref.Difficulty = Normal; + return Pref.LevelMax[Pref.Difficulty] > 0 ? mMenuLevel : mGame; case 2: - Pref.Difficulte = Hard; - return Pref.NiveauMax[Pref.Difficulte] > 0 ? mMenuNiveau : mGame; + Pref.Difficulty = Hard; + return Pref.LevelMax[Pref.Difficulty] > 0 ? mMenuLevel : mGame; } break; default: @@ -763,8 +763,8 @@ eMenu Menu::SDLMain_Speed() } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage @@ -787,27 +787,27 @@ eMenu Menu::SDLMain_Level() // Initialisations Divers m_mouse.Init(Menu_Py); // Initialise la sourie PyE = 0; - Niv = Pref.NiveauMax[Pref.Difficulte]; - Pref.Niveau = 0; + Niv = Pref.LevelMax[Pref.Difficulty]; + Pref.Level = 0; // Prend les evenements do { // Efface le fond SDL_RenderClear(sdlRenderer); // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); - Sprites[menu].Affiche(400, 340, 0, Sprites[fmenu].Image[0]); - Sprites[titre].Affiche(400, 65, 0, Sprites[fmenu].Image[0]); + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[menu].Draw(400, 340, 0, Sprites[fmenu].Image[0]); + Sprites[title].Draw(400, 65, 0, Sprites[fmenu].Image[0]); - AfficheText(400, 225, T_new_game, Sprites[fmenu].Image[0]); - AddBouton(0, T_new_game, 400, 225); - AfficheText(400, 320, T_old_level, Sprites[fmenu].Image[0]); - AddBouton(1, T_old_level, 400, 320); - AfficheText(400, 455, T_menu, Sprites[fmenu].Image[0]); - AddBouton(2, T_menu, 400, 455); + DrawText(400, 225, T_new_game, Sprites[fmenu].Image[0]); + AddButton(0, T_new_game, 400, 225); + DrawText(400, 320, T_old_level, Sprites[fmenu].Image[0]); + AddButton(1, T_old_level, 400, 320); + DrawText(400, 455, T_menu, Sprites[fmenu].Image[0]); + AddButton(2, T_menu, 400, 455); - AddBouton(3, fleches, 330, 380); - AddBouton(4, fleches, 470, 380); + AddButton(3, arrows, 330, 380); + AddButton(4, arrows, 470, 380); Menu_Py[5].DepX = -1; @@ -848,7 +848,7 @@ eMenu Menu::SDLMain_Level() PyE = 1; break; case SDLK_RIGHT: - if (Niv < Pref.NiveauMax[Pref.Difficulte]) { + if (Niv < Pref.LevelMax[Pref.Difficulty]) { Niv++; } PyE = 1; @@ -865,7 +865,7 @@ eMenu Menu::SDLMain_Level() case 0: return mGame; case 1: - Pref.Niveau = Niv; + Pref.Level = Niv; return mGame; case 2: return mMenu; @@ -875,7 +875,7 @@ eMenu Menu::SDLMain_Level() } break; case 4: - if (Niv < Pref.NiveauMax[Pref.Difficulte]) { + if (Niv < Pref.LevelMax[Pref.Difficulty]) { Niv++; } break; @@ -893,39 +893,39 @@ eMenu Menu::SDLMain_Level() } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage Ec.ClearSprite(fmenu); - // Affiche les flèches + // Draw les flèches if (Niv > 0) { if (PyE == 3) { - Ec.PrintSprite(fleches, 2, 330, 380); + Ec.PrintSprite(arrows, 2, 330, 380); } else { - Ec.PrintSprite(fleches, 1, 330, 380); + Ec.PrintSprite(arrows, 1, 330, 380); } } else { - Ec.PrintSprite(fleches, 0, 330, 380); + Ec.PrintSprite(arrows, 0, 330, 380); } - if (Niv < Pref.NiveauMax[Pref.Difficulte]) { + if (Niv < Pref.LevelMax[Pref.Difficulty]) { if (PyE == 4) { - Ec.PrintSprite(fleches, 5, 470, 380); + Ec.PrintSprite(arrows, 5, 470, 380); } else { - Ec.PrintSprite(fleches, 4, 470, 380); + Ec.PrintSprite(arrows, 4, 470, 380); } } else { - Ec.PrintSprite(fleches, 3, 470, 380); + Ec.PrintSprite(arrows, 3, 470, 380); } - AfficheChiffre(400, 380, Niv + 1); + DrawNumber(400, 380, Niv + 1); if (PyE != 3 && PyE != 4) { Print_Main(); @@ -966,25 +966,25 @@ eMenu Menu::SDLMain_HR() Position.h = Sprites[fmenu].Dim[0].H; SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); - Sprites[menu].Affiche(340, 300, 0, Sprites[fmenu].Image[0]); - Sprites[fond_hr].Affiche(340, 74, 0, Sprites[fmenu].Image[0]); - AfficheText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); + Sprites[menu].Draw(340, 300, 0, Sprites[fmenu].Image[0]); + Sprites[fond_hr].Draw(340, 74, 0, Sprites[fmenu].Image[0]); + DrawText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); - Sprites[locomotive].Affiche(115, 110, rand() % 320, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(100, 160 + (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(100, 470 - (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(580, 100 + (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(580, 470 - (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); + Sprites[locomotive].Draw(115, 110, rand() % 320, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(100, 160 + (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(100, 470 - (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(580, 100 + (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(580, 470 - (rand() % 130), rand() % 18, Sprites[fmenu].Image[0]); - AfficheText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); + DrawText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); if (Ordre) { - AddBouton(0, e_Sprite(T_tart1 + N1), 240, 492); - AddBouton(1, e_Sprite(T_tart1 + N2), 440, 492); + AddButton(0, e_Sprite(T_tart1 + N1), 240, 492); + AddButton(1, e_Sprite(T_tart1 + N2), 440, 492); } else { - AddBouton(0, e_Sprite(T_tart1 + N1), 440, 492); - AddBouton(1, e_Sprite(T_tart1 + N2), 240, 492); + AddButton(0, e_Sprite(T_tart1 + N1), 440, 492); + AddButton(1, e_Sprite(T_tart1 + N2), 240, 492); } Menu_Py[0].DepY -= 20; Menu_Py[0].FinY += 20; @@ -1003,26 +1003,26 @@ eMenu Menu::SDLMain_HR() SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); - // Sprites[fond].Affiche(400,300,0,Sprites[fjeu].Image[0]); - Sprites[menu].Affiche(340, 300, 0, Sprites[fmenu].Image[0]); - Sprites[fond_hr].Affiche(340, 74, 0, Sprites[fmenu].Image[0]); - AfficheText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); + // Sprites[fond].Draw(400,300,0,Sprites[fjeu].Image[0]); + Sprites[menu].Draw(340, 300, 0, Sprites[fmenu].Image[0]); + Sprites[fond_hr].Draw(340, 74, 0, Sprites[fmenu].Image[0]); + DrawText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); - Sprites[locomotive].Affiche(115, 110, locoPosition, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(100, 160 + posDeco[0].first, posDeco[0].second, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(100, 470 - (posDeco[1].first), posDeco[1].second, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(580, 100 + (posDeco[2].first), posDeco[2].second, Sprites[fmenu].Image[0]); - Sprites[deco].Affiche(580, 470 - (posDeco[3].first), posDeco[3].second, Sprites[fmenu].Image[0]); + Sprites[locomotive].Draw(115, 110, locoPosition, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(100, 160 + posDeco[0].first, posDeco[0].second, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(100, 470 - (posDeco[1].first), posDeco[1].second, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(580, 100 + (posDeco[2].first), posDeco[2].second, Sprites[fmenu].Image[0]); + Sprites[deco].Draw(580, 470 - (posDeco[3].first), posDeco[3].second, Sprites[fmenu].Image[0]); - AfficheText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); + DrawText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); /* if(Ordre) { - AddBouton(0,e_Sprite(T_tart1+N1),240,492); - AddBouton(1,e_Sprite(T_tart1+N2),440,492); + AddButton(0,e_Sprite(T_tart1+N1),240,492); + AddButton(1,e_Sprite(T_tart1+N2),440,492); } else { - AddBouton(0,e_Sprite(T_tart1+N1),440,492); - AddBouton(1,e_Sprite(T_tart1+N2),240,492); + AddButton(0,e_Sprite(T_tart1+N1),440,492); + AddButton(1,e_Sprite(T_tart1+N2),240,492); } Menu_Py[0].DepY-=20; Menu_Py[0].FinY+=20; @@ -1088,11 +1088,11 @@ eMenu Menu::SDLMain_HR() case 0: m_audio.Play(sEnd); Pref.Score += 50; - Fini = Horloge + 2000; + Fini = currentTime + 2000; break; case 1: m_audio.Play(sLose); - Fini = Horloge + 2000; + Fini = currentTime + 2000; break; } break; @@ -1108,13 +1108,13 @@ eMenu Menu::SDLMain_HR() } // Test si fini - if (Fini != -1 && Fini < Horloge) { + if (Fini != -1 && Fini < currentTime) { return mGame; } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage @@ -1122,17 +1122,17 @@ eMenu Menu::SDLMain_HR() if (Ordre) { Ec.PrintSprite(fond_hrr, 0, 240, 492); - AfficheText(240, 492, e_Sprite(T_tart1 + N1)); + DrawText(240, 492, e_Sprite(T_tart1 + N1)); } else { Ec.PrintSprite(fond_hrr, 0, 440, 492); - AfficheText(440, 492, e_Sprite(T_tart1 + N1)); + DrawText(440, 492, e_Sprite(T_tart1 + N1)); } if (Fini == -1) { if (Ordre) { Ec.PrintSprite(fond_hrr, 0, 440, 492); - AfficheText(440, 492, e_Sprite(T_tart1 + N2)); + DrawText(440, 492, e_Sprite(T_tart1 + N2)); if (PyE == 0) { Print_Main(240); } @@ -1142,7 +1142,7 @@ eMenu Menu::SDLMain_HR() } else { Ec.PrintSprite(fond_hrr, 0, 240, 492); - AfficheText(240, 492, e_Sprite(T_tart1 + N2)); + DrawText(240, 492, e_Sprite(T_tart1 + N2)); if (PyE == 1) { Print_Main(240); } @@ -1178,14 +1178,14 @@ void Menu::Print_InGame() Position.h = Sprites[fmenu].Dim[0].H; SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); - Sprites[menu].Affiche(340, 300, 0, Sprites[fmenu].Image[0]); + Sprites[menu].Draw(340, 300, 0, Sprites[fmenu].Image[0]); - AfficheText(340, 185, T_continue, Sprites[fmenu].Image[0]); - AddBouton(0, T_continue, 340, 185); - AfficheText(340, 300, T_moptions, Sprites[fmenu].Image[0]); - AddBouton(1, T_moptions, 340, 300); - AfficheText(340, 415, T_exit_game, Sprites[fmenu].Image[0]); - AddBouton(2, T_exit_game, 340, 415); + DrawText(340, 185, T_continue, Sprites[fmenu].Image[0]); + AddButton(0, T_continue, 340, 185); + DrawText(340, 300, T_moptions, Sprites[fmenu].Image[0]); + AddButton(1, T_moptions, 340, 300); + DrawText(340, 415, T_exit_game, Sprites[fmenu].Image[0]); + AddButton(2, T_exit_game, 340, 415); Menu_Py[3].DepX = -1; } @@ -1260,8 +1260,8 @@ eMenu Menu::SDLMain_InGame() } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); // Gère l'Affichage @@ -1331,28 +1331,28 @@ eMenu Menu::SDLMain_Score(bool EditScore) Ec.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Affiche(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); - // Affiche le titre et les commandes - AfficheText(400, 50, T_better_scores, Sprites[fmenu].Image[0]); - AfficheText(400, 550, T_press_any_key, Sprites[fmenu].Image[0]); + // Draw le titre et les commandes + DrawText(400, 50, T_better_scores, Sprites[fmenu].Image[0]); + DrawText(400, 550, T_press_any_key, Sprites[fmenu].Image[0]); - // Affiche les scores + // Draw les scores for (i = 0; i < 8; i++) { sprintf(Provi, "%d", i + 1); - AfficheString(70, 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); + DrawString(70, 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); if (EditScore == false || NEdit != i) { if (Pref.Sco[i].Name[0]) { - AfficheString(140, 120 + i * (360 / 7), Pref.Sco[i].Name, Sprites[fmenu].Image[0]); + DrawString(140, 120 + i * (360 / 7), Pref.Sco[i].Name, Sprites[fmenu].Image[0]); } else { - AfficheString(140, 120 + i * (360 / 7), Points, Sprites[fmenu].Image[0]); + DrawString(140, 120 + i * (360 / 7), Points, Sprites[fmenu].Image[0]); } } sprintf(Provi, "%i", Pref.Sco[i].Score); - AfficheString(740 - LongueurString(Provi), 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); + DrawString(740 - StringLength(Provi), 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); } // Efface le fond @@ -1399,7 +1399,7 @@ eMenu Menu::SDLMain_Score(bool EditScore) break; case SDL_TEXTINPUT: /* Add new text onto the end of our text */ - if (LongueurString(Pref.Sco[NEdit].Name) < LSCOREMAX && PosCur < 79 && CharExiste(event.text.text[0])) { + if (StringLength(Pref.Sco[NEdit].Name) < LSCOREMAX && PosCur < 79 && CharExist(event.text.text[0])) { PosCur += strlen(event.text.text); strcat(Pref.Sco[NEdit].Name, event.text.text); } @@ -1413,16 +1413,16 @@ eMenu Menu::SDLMain_Score(bool EditScore) } // Gère les variables - HorlogeAvant = Horloge; - Horloge = SDL_GetTicks(); + previousTime = currentTime; + currentTime = SDL_GetTicks(); Sleeping(); - if (EditScore) { // Gère l'affiche pour l'édition des scores - AfficheString(140, 120 + NEdit * (360 / 7), Pref.Sco[NEdit].Name); + if (EditScore) { // Gère l'Draw pour l'édition des scores + DrawString(140, 120 + NEdit * (360 / 7), Pref.Sco[NEdit].Name); - i = (Horloge / 50) % 20; // Affiche les curseurs - Ec.PrintSprite(fleche_gauche, i, 110, 120 + NEdit * (360 / 7)); - Ec.PrintSprite(fleche_droite, i, 180 + LongueurString(Pref.Sco[NEdit].Name), 120 + NEdit * (360 / 7)); + i = (currentTime / 50) % 20; // Draw les curseurs + Ec.PrintSprite(arrow_left, i, 110, 120 + NEdit * (360 / 7)); + Ec.PrintSprite(arrow_right, i, 180 + StringLength(Pref.Sco[NEdit].Name), 120 + NEdit * (360 / 7)); } // Echange les buffets video @@ -1436,28 +1436,28 @@ eMenu Menu::SDLMain_Score(bool EditScore) return mQuit; } -/*** Affiche le menu Principale ***/ +/*** Draw le menu Principale ***/ /**********************************/ void Menu::Print_Main(int Centre) const { - int const NumSp = (Horloge / 50) % 20; + int const NumSp = (currentTime / 50) % 20; int const x1 = Menu_Py[PyE].DepX - 25; int const x2 = (Centre - x1) + Centre; int const y = (Menu_Py[PyE].FinY + Menu_Py[PyE].DepY) / 2; - Ec.PrintSprite(fleche_gauche, NumSp, x1, y); - Ec.PrintSprite(fleche_droite, NumSp, x2, y); + Ec.PrintSprite(arrow_left, NumSp, x1, y); + Ec.PrintSprite(arrow_right, NumSp, x2, y); } /*** Centre les flèches sur le boutton ***/ /*****************************************/ void Menu::Affiche_Main_Centre() const { - int const NumSp = (Horloge / 50) % 20; + int const NumSp = (currentTime / 50) % 20; int const x1 = Menu_Py[PyE].DepX - 5; int const x2 = Menu_Py[PyE].FinX + 5; int const y = (Menu_Py[PyE].FinY + Menu_Py[PyE].DepY) / 2; - Ec.PrintSprite(fleche_gauche, NumSp, x1, y); - Ec.PrintSprite(fleche_droite, NumSp, x2, y); + Ec.PrintSprite(arrow_left, NumSp, x1, y); + Ec.PrintSprite(arrow_right, NumSp, x2, y); } diff --git a/src/mouse.cc b/src/mouse.cc index 952e8ad..c39762f 100644 --- a/src/mouse.cc +++ b/src/mouse.cc @@ -31,7 +31,7 @@ /*** Variables Globales ***/ /**************************/ -extern int Horloge; +extern int currentTime; extern Screen Ec; extern SDL_Window *sdlWindow; @@ -125,7 +125,7 @@ void Mouse::GetEvent(SDL_Event &event, int &pPy) void Mouse::Print() const { int X = Px, Y = Py; - int const NumSp = (Horloge / 50) % 20; + int const NumSp = (currentTime / 50) % 20; // Corrige la position du curseur au cas ou déborde de l'écran if (X < 5) { @@ -143,6 +143,6 @@ void Mouse::Print() const #ifndef ANDROID // Affiche le curseur - Ec.PrintSprite(curseur, NumSp, X, Y); + Ec.PrintSprite(cursor, NumSp, X, Y); #endif } diff --git a/src/preference.h b/src/preference.h index 76366bc..b24bdef 100644 --- a/src/preference.h +++ b/src/preference.h @@ -26,20 +26,20 @@ #include // for SDL_MIX_MAXVOLUME -#define VITESSE_MAX 180.0 -#define VITESSE_MOY 120.0 -#define VITESSE_MIN 80.0 -#define DUREE_VITESSE (10 * 1000) +#define SPEED_MAX 180.0 +#define SPEED_AVERAGE 120.0 +#define SPEED_MIN 80.0 +#define SPEED_DURATION (10 * 1000) -#define DUREE_PAUSE (3 * 1000) +#define PAUSE_DURATION (3 * 1000) -#define DUREE_REDUIT (10 * 1000) -#define DUREE_ALONGE (10 * 1000) -#define ECARTWAGON_MAX 27.0 -#define ECARTWAGON_MOY 13.0 -#define ECARTWAGON_MIN 4.0 +#define REDUCTION_DURATION (10 * 1000) +#define EXTENSION_DURATION (10 * 1000) +#define WAGON_GAP_MAX 27.0 +#define WAGON_GAP_AVERAGE 13.0 +#define WAGON_GAP_MIN 4.0 -#define N_VIES_DEP 3 +#define N_LIVES_COUNT 3 #define RAYON_TOUCHE (32 * 32) @@ -65,13 +65,13 @@ #define C_Live 6 #define C_Fin 7 -enum e_Difficulte { +enum e_Difficulty { Easy, Normal, Hard }; -/*** Mémorise un score ***/ +/*** Remember score ***/ #define LSCOREMAX 460 struct sScore @@ -80,12 +80,12 @@ struct sScore char Name[80]; }; -/*** Structure des preferences Générales ***/ +/*** Preferences structures ***/ struct sOldPreference { - e_Difficulte Difficulte; // Difficulté de la partie (Vitesse) - int Niveau; // Niveau du joueur - int NVie; // Nombre de vie du joueur + e_Difficulty Difficulte; // Difficulté de la partie (Vitesse) + int Level; // Niveau du joueur + int Lives; // Nombre de vie du joueur int Score; // Score du joueur double Vitesse; // Vitesse suivant le niveau double VitesseMoy; // Vitesse en cours de la loco @@ -101,17 +101,17 @@ struct sOldPreference struct sNewPreference { - e_Difficulte Difficulte { Normal }; // current game difficulty - int Niveau; // current level - int NVie { N_VIES_DEP }; // current number of life + e_Difficulty Difficulty { Normal }; // current game difficulty + int Level; // current level + int Lives { N_LIVES_COUNT }; // current number of life int Score; // current score - double Vitesse { VITESSE_MOY }; // Vitesse suivant le niveau - double VitesseMoy { VITESSE_MOY }; // Vitesse en cours de la loco - float EcartWagon { ECARTWAGON_MOY }; // ecart en pixels entre 2 wagons - int NLangues; // Nombre de langues disponible - int NiveauMax[3] { 0, 0, 0 }; // One per difficulty + double Speed { SPEED_AVERAGE }; // speed ​​depending on level + double SpeedAverage { SPEED_AVERAGE }; // current speed of the locomotive + float WagonGap { WAGON_GAP_AVERAGE }; // size in pixels between wagons + int NLanguages; // number of languages ​​available + int LevelMax[3] { 0, 0, 0 }; // One per difficulty int FullScreen { true }; - int Langue { -1 }; // locale index + int Language { -1 }; // locale index float Volume { (float)SDL_MIX_MAXVOLUME }; // audio volume float VolumeM { (float)SDL_MIX_MAXVOLUME }; // music volume struct sScore Sco[8]; // store scores @@ -120,10 +120,10 @@ struct sNewPreference enum eMenu { mMenu, - mMenuJeux, + mMenuGame, mMenuSpeed, - mMenuNiveau, - mLangue, + mMenuLevel, + mLanguage, mGame, mScore, mScoreEdit, diff --git a/src/screen.cc b/src/screen.cc index e8a38d5..7306925 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -39,7 +39,7 @@ void Screen::PrintSprite(e_Sprite NumSpr, int Num, int x, int y) B[N].y = y; N++; - Sprites[NumSpr].Affiche(x, y, Num); + Sprites[NumSpr].Draw(x, y, Num); } void Screen::PrintCable(int dx, int dy, int fx, int fy) @@ -67,7 +67,7 @@ void Screen::PrintText(e_Sprite Text, int x, int y) B[N].y = y; N++; - Sprites[Text].Affiche(x, y, 0); + Sprites[Text].Draw(x, y, 0); } /*** Affiche les options du jeu ***/ @@ -77,7 +77,7 @@ void Screen::PrintOptions(int NV, int NScore) int x, y; Score = NScore; - AfficheChiffre(740, 215, Score); + DrawNumber(740, 215, Score); if (NV > 10) { NV = 10; // Evite un dépassement de l'affichage @@ -87,7 +87,7 @@ void Screen::PrintOptions(int NV, int NScore) x = x * 44 + 38 + LT * D_Case; y = i / 2; y = 384 + y * 46; - Sprites[logo_vie].Affiche(x, y, 0); + Sprites[logo_vie].Draw(x, y, 0); } } @@ -102,7 +102,7 @@ void Screen::ClearSprite(e_Sprite NumSp) /*******************************************/ void Screen::CleanSpriteAndScreen(e_Sprite NumSp) { - Sprites[NumSp].Affiche(Sprites[NumSp].Dim[0].L / 2, Sprites[NumSp].Dim[0].H / 2, 0); + Sprites[NumSp].Draw(Sprites[NumSp].Dim[0].L / 2, Sprites[NumSp].Dim[0].H / 2, 0); N = 0; Score = -1; } diff --git a/src/sprite.cc b/src/sprite.cc index ea3b243..be8881c 100644 --- a/src/sprite.cc +++ b/src/sprite.cc @@ -43,26 +43,26 @@ static int TableTexte[256]; char Langue[31][16]; // Mémorise les noms des langues int NTextes = 0; -bool AfficheC = false; // Si peut afficher le chargeur lors du chargement +bool DrawL = false; // Si peut afficher le chargeur lors du chargement #define N_SPRITESFOND 2 /*** Affiche le chargeur lors du chargement ***/ /**********************************************/ -void AfficheChargeur() +void DrawLoading() { static int NumAf = -1; // Numéro su sprite affiché int i, Old; - int Hor; + int Clock; - if (AfficheC == true) { - Hor = SDL_GetTicks(); - i = (Hor / (1000 / 25)) % Sprites[chargeur].N; // Calcule le numéro su sprite à afficher + if (DrawL == true) { + Clock = SDL_GetTicks(); + i = (Clock / (1000 / 25)) % Sprites[loading].N; // Calcule le numéro su sprite à afficher if (i != NumAf) { Old = NumAf; NumAf = i; - Sprites[chargeur].Affiche(400, 300, NumAf); + Sprites[loading].Draw(400, 300, NumAf); SDL_RenderPresent(sdlRenderer); // TODO if(Old!=-1) Sprites[chargeur].Efface(400,300,Old,sdlVideo); } @@ -71,17 +71,17 @@ void AfficheChargeur() /*** Charge les Sprites d'une langue ***/ /***************************************/ -bool LoadLangue() +bool LoadLanguage() { long L, P; int i; unsigned char *Buf; char PathFile[512]; - strcpy(PathFile, Langue[Pref.Langue]); + strcpy(PathFile, Langue[Pref.Language]); Utils::GetPath(PathFile); if (Utils::FileExists(PathFile) == false) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find '%s'", Langue[Pref.Langue]); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find '%s'", Langue[Pref.Language]); return false; } L = Utils::LoadFile(PathFile, Buf); @@ -140,29 +140,29 @@ bool LoadSprites() NSp = (int)(Buf[0]) * 256 + (int)(Buf[1]); NSp += N_SPRITESFOND + 2; NTextes = (int)(Buf[2]) * 256 + (int)(Buf[3]); - Pref.NLangues = (int)(Buf[4]) * 256 + (int)(Buf[5]); + Pref.NLanguages = (int)(Buf[4]) * 256 + (int)(Buf[5]); - NSprites = NSp + NTextes + Pref.NLangues; + NSprites = NSp + NTextes + Pref.NLanguages; Sprites = new Sprite[NSprites]; // Récupère les nom des langues P = 6; - for (i = 0; i < Pref.NLangues; i++) { + for (i = 0; i < Pref.NLanguages; i++) { strcpy(Langue[i], (char *)(Buf + P)); P += strlen((char *)(Buf + P)) + 1; } // Charge les sprites des langues - for (i = 0; i < Pref.NLangues; i++) { + for (i = 0; i < Pref.NLanguages; i++) { if (Sprites[T_Langue + i].Load(Buf, P) == false) { return false; } } - if (Sprites[chargeur].Load(Buf, P) == false) { + if (Sprites[loading].Load(Buf, P) == false) { return false; // Sprite du chargeur } - AfficheC = true; // Peut afficher le sprite du chargeur + DrawL = true; // Peut afficher le sprite du chargeur delete[] Buf; @@ -179,18 +179,18 @@ bool LoadSprites() // Lit les sprites P = 0; for (i = 0; i < NSp; i++) { - AfficheChargeur(); + DrawLoading(); switch (i) { case fjeu: case fmenu: - if (Sprites[i].Nouveau(800, 600) == false) { + if (Sprites[i].New(800, 600) == false) { return false; } break; case rope: Sprites[i].N = 0; break; - case chargeur: + case loading: break; default: if (Sprites[i].Load(Buf, P) == false) { @@ -203,22 +203,22 @@ bool LoadSprites() // *** Charge la langue *** // ************************ - if (Pref.Langue != -1) { - LoadLangue(); + if (Pref.Language != -1) { + LoadLanguage(); } - AfficheC = false; // N'affiche plus les sprites du chargeur + DrawL = false; // N'affiche plus les sprites du chargeur return true; } /*** Retourne la longueur d'un nombre ***/ /****************************************/ -int LongueurChiffre(int C) +int NumberLength(int C) { int l = 0; do { - l += Sprites[chiffres].Dim[(C % 10)].L; + l += Sprites[digits].Dim[(C % 10)].L; C /= 10; if (C) { l += ECART_ENTRE_CHIFFRE; @@ -230,7 +230,7 @@ int LongueurChiffre(int C) /*** Retourne la longueur d'un texte ***/ /***************************************/ -int LongueurString(char *Texte) +int StringLength(char *Texte) { int i = 0; int l = 0; @@ -258,7 +258,7 @@ int LongueurString(char *Texte) /*** Test si un caracataire existe ***/ /*************************************/ -bool CharExiste(char C) +bool CharExist(char C) { if ((int)(C) < 0) { return false; @@ -273,21 +273,21 @@ bool CharExiste(char C) } /*** Affiche un nombre ***/ /*************************/ -void AfficheChiffre(int x, int y, int Nombre, SDL_Texture *Fond) +void DrawNumber(int x, int y, int Nombre, SDL_Texture *Fond) { - int const l = LongueurChiffre(Nombre); + int const l = NumberLength(Nombre); x += l / 2; do { - Sprites[chiffres].Affiche(x - (Sprites[chiffres].Dim[(Nombre % 10)].L) / 2, y, Nombre % 10, Fond); - x -= Sprites[chiffres].Dim[(Nombre % 10)].L + ECART_ENTRE_CHIFFRE; + Sprites[digits].Draw(x - (Sprites[digits].Dim[(Nombre % 10)].L) / 2, y, Nombre % 10, Fond); + x -= Sprites[digits].Dim[(Nombre % 10)].L + ECART_ENTRE_CHIFFRE; Nombre /= 10; } while (Nombre); } /*** Affiche un Texte ***/ /************************/ -void AfficheString(int x, int y, char *Texte, SDL_Texture *Fond) +void DrawString(int x, int y, char *Texte, SDL_Texture *Fond) { int i = 0; int Le; @@ -298,7 +298,7 @@ void AfficheString(int x, int y, char *Texte, SDL_Texture *Fond) if (TableTexte[Le] != -1) { // Si un caractaire connue Le = TableTexte[Le]; - Sprites[lettres].Affiche(x + (Sprites[lettres].Dim[Le].L / 2), y, Le, Fond); + Sprites[lettres].Draw(x + (Sprites[lettres].Dim[Le].L / 2), y, Le, Fond); x += Sprites[lettres].Dim[Le].L + ECART_ENTRE_LETTRE; } else { // Si un espace @@ -313,9 +313,9 @@ void AfficheString(int x, int y, char *Texte, SDL_Texture *Fond) /*** Affiche un text dans la langue ***/ /**************************************/ -void AfficheText(int x, int y, e_Sprite Text, SDL_Texture *Fond) +void DrawText(int x, int y, e_Sprite Text, SDL_Texture *Fond) { - Sprites[Text].Affiche(x, y, 0, Fond); + Sprites[Text].Draw(x, y, 0, Fond); } /*** Constructeur ***/ @@ -349,7 +349,7 @@ bool Sprite::Load(unsigned char *Buf, long &P) // Lit tous les sprites for (i = 0; i < N; i++) { // Affiche l'animation de chargement - AfficheChargeur(); + DrawLoading(); // Lit les dimensions Dim[i].L = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); @@ -401,7 +401,7 @@ bool Sprite::Load(unsigned char *Buf, long &P) /*** Affiche le sprite ***/ /*************************/ -void Sprite::Affiche(int X, int Y, int NumSpr, SDL_Texture *Fond) const +void Sprite::Draw(int X, int Y, int NumSpr, SDL_Texture *Fond) const { SDL_Rect Position; SDL_Rect Di; @@ -430,7 +430,7 @@ void Sprite::PrintRope(int dx, int dy, int fx, int fy) /*** Alloue un nouveau sprite vide ***/ /*************************************/ -bool Sprite::Nouveau(int Lx, int Ly) +bool Sprite::New(int Lx, int Ly) { Delete(); // Efface au cas ou diff --git a/src/sprite.h b/src/sprite.h index 9f4e280..df5f7a2 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -45,32 +45,32 @@ struct s_Dim /***********************/ enum e_Sprite { locomotive = 0, - charbon, - buches, - balles, - moteur, - citerne, + coal_wagon, + logs_wagon, + cargo_wagon, + engine_wagon, + cistern_wagon, wagon, pluslong, pluscourt, - vitesse, - vie, - nouveau_wagon, + speed, + life, + new_wagon, logo_vie, rail, dir, lettres, - chiffres, - titre, + digits, + title, copyright, deco, - curseur, - fleche_gauche, - fleche_droite, - fleches, - monde, + cursor, + arrow_left, + arrow_right, + arrows, + earth, music, - bruitage, + sound, fscreen, window, keys, @@ -84,7 +84,7 @@ enum e_Sprite { fjeu, fmenu, rope, - chargeur, + loading, T_level, T_lives, @@ -174,18 +174,18 @@ enum e_Sprite { /*** Fonctions ***/ /*****************/ -void AfficheChargeur(); // Affiche le chargeur sur la page de départ -bool LoadLangue(); // Charge les sprites d'une langue +void DrawLoading(); // Affiche le chargeur sur la page de départ +bool LoadLanguage(); // Charge les sprites d'une langue bool LoadSprites(); // Charge tous les sprites -int LongueurChiffre(int C); // Retourne la longueur en pixels d'un nombre -int LongueurString(char *Texte); // Retourne la longueur en pixels d'un texte -bool CharExiste(char C); // Si un caracataire existe +int NumberLength(int C); // Retourne la longueur en pixels d'un nombre +int StringLength(char *Texte); // Retourne la longueur en pixels d'un texte +bool CharExist(char C); // Si un caracataire existe -void AfficheChiffre(int x, int y, int Nombre, SDL_Texture *Fond = nullptr); // Affiche un chiffre -void AfficheString(int x, int y, char *Texte, SDL_Texture *Fond = nullptr); // Affiche une chaine de caractaire +void DrawNumber(int x, int y, int Nombre, SDL_Texture *Fond = nullptr); // Affiche un chiffre +void DrawString(int x, int y, char *Texte, SDL_Texture *Fond = nullptr); // Affiche une chaine de caractaire -void AfficheText(int x, int y, e_Sprite Text, SDL_Texture *Fond = nullptr); // Affiche un text dans la langue +void DrawText(int x, int y, e_Sprite Text, SDL_Texture *Fond = nullptr); // Affiche un text dans la langue /*** Definition de la classe Sprite ***/ /**************************************/ @@ -197,9 +197,9 @@ class Sprite /*** Fonctions ***/ bool Load(unsigned char *Buf, long &P); // Charge les images - void Affiche(int X, int Y, int NumSpr, SDL_Texture *Fond = nullptr) const; // Affiche un sprite + void Draw(int X, int Y, int NumSpr, SDL_Texture *Fond = nullptr) const; // Affiche un sprite void PrintRope(int dx, int dy, int fx, int fy); - bool Nouveau(int Lx, int Ly); // Alloue un nouveau sprite vide sans transparence + bool New(int Lx, int Ly); // Alloue un nouveau sprite vide sans transparence void Delete(); // Efface la mémoire du sprite /*** Variables ***/ diff --git a/src/utils.cc b/src/utils.cc index daa8225..9070adf 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -39,15 +39,15 @@ #include "SimpleIni.h" -/*** Variables globales ***/ +/*** Global variables ***/ /**************************/ extern sNewPreference Pref; #if defined(__unix__) || defined(__HAIKU__) -extern char DefPath[]; // Chemin par defaut dans arg +extern char DefPath[]; // Default path in argument #endif -/*** Définition générals ***/ -/***************************/ +/*** General defines ***/ +/************************/ #ifdef __APPLE__ #define MAC_LINUX #endif @@ -60,7 +60,7 @@ extern char DefPath[]; // Chemin par defaut dans arg #define MAC_LINUX #endif -/*** Test si un fichier exite ***/ +/*** Check if the file exists ***/ /********************************/ bool Utils::FileExists(const char *Path) { @@ -74,8 +74,8 @@ bool Utils::FileExists(const char *Path) return true; } -/*** Charge un fichier en Mémoire ***/ -/************************************/ +/*** Load a file in memory ***/ +/*****************************/ long Utils::LoadFile(const char *Path, unsigned char *&Buf) { SDL_RWops *file = SDL_RWFromFile(Path, "rb"); @@ -97,7 +97,7 @@ long Utils::LoadFile(const char *Path, unsigned char *&Buf) unsigned char *Po = Buf; while (Compt > 1024) { - AfficheChargeur(); + DrawLoading(); if (SDL_RWread(file, Po, 1, 1024) != 1024) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error while reading '%s'", Path); SDL_RWclose(file); @@ -116,8 +116,8 @@ long Utils::LoadFile(const char *Path, unsigned char *&Buf) return L; } -/*** Sauve un Fichier ***/ -/************************/ +/*** Save a file ***/ +/*******************/ bool Utils::SaveFile(const char *Path, char *Buf, long L) { FILE *file; @@ -150,8 +150,8 @@ bool Utils::SaveFile(const char *Path, char *Buf, long L) return true; } -/*** Met le bon chemin pour charger un fichier ***/ -/*************************************************/ +/*** Add the path to the filename depending on the OS (sprites, levels) ***/ +/**************************************************************************/ #if (defined(__unix__) || defined(ANDROID)) || defined(__HAIKU__) && !defined(__AMIGAOS4__) // Version Linux void Utils::GetPath(char *Path) @@ -221,7 +221,7 @@ void Utils::GetPath(char *Path) #endif #ifdef _WIN32 -// Version Windows , chemin directe +// Windows version, direct path void Utils::GetPath(char *Path) { char Provi[512]; @@ -237,8 +237,8 @@ void Utils::GetPath(char *Path) } #endif -/*** Charge les préferences ***/ -/******************************/ +/*** Load preferences ***/ +/************************/ bool Utils::LoadPref() { int L; @@ -264,7 +264,7 @@ bool Utils::LoadPref() } pv = ini.GetValue("main", "locale"); if (pv) { - Pref.Langue = std::stoi(pv); + Pref.Language = std::stoi(pv); } pv = ini.GetValue("main", "audioVolume"); if (pv) { @@ -280,15 +280,15 @@ bool Utils::LoadPref() } pv = ini.GetValue("easy", "maxLevel"); if (pv) { - Pref.NiveauMax[0] = std::stof(pv); + Pref.LevelMax[0] = std::stof(pv); } pv = ini.GetValue("normal", "maxLevel"); if (pv) { - Pref.NiveauMax[1] = std::stof(pv); + Pref.LevelMax[1] = std::stof(pv); } pv = ini.GetValue("difficult", "maxLevel"); if (pv) { - Pref.NiveauMax[2] = std::stof(pv); + Pref.LevelMax[2] = std::stof(pv); } for (int i = 0; i < 8; ++i) { std::string scoreKey = "score_" + std::to_string(i); @@ -313,13 +313,13 @@ bool Utils::LoadPref() memcpy((char *)&oldPref, Provi, L); delete[] Provi; Pref.FullScreen = oldPref.FullScreen; - Pref.Langue = oldPref.Langue; + Pref.Language = oldPref.Langue; Pref.Volume = oldPref.Volume; Pref.VolumeM = oldPref.VolumeM; // Try to restore max difficulty from the level stored in conf - Pref.NiveauMax[0] = oldPref.Difficulte == Easy ? oldPref.NiveauMax : 0; - Pref.NiveauMax[1] = oldPref.Difficulte == Normal ? oldPref.NiveauMax : 0; - Pref.NiveauMax[2] = oldPref.Difficulte == Hard ? oldPref.NiveauMax : 0; + Pref.LevelMax[0] = oldPref.Difficulte == Easy ? oldPref.NiveauMax : 0; + Pref.LevelMax[1] = oldPref.Difficulte == Normal ? oldPref.NiveauMax : 0; + Pref.LevelMax[2] = oldPref.Difficulte == Hard ? oldPref.NiveauMax : 0; for (int i = 0; i < 8; ++i) { Pref.Sco[i].Score = oldPref.Sco[i].Score; strncpy(Pref.Sco[i].Name, oldPref.Sco[i].Name, 80); @@ -332,9 +332,9 @@ bool Utils::LoadPref() return false; } -/*** Sauve les preferences ***/ -/*****************************/ -void Utils::SauvePref() +/*** Save preferences ***/ +/************************/ +void Utils::SavePref() { char PathPref[512]; char *PrefFolder = SDL_GetPrefPath("Li-Ri", "Li-Ri"); @@ -343,13 +343,13 @@ void Utils::SauvePref() SDL_free(PrefFolder); CSimpleIniA ini(true); // true for unicode ini.SetValue("main", "fullscreen", std::to_string(Pref.FullScreen).c_str()); - ini.SetValue("main", "locale", std::to_string(Pref.Langue).c_str()); + ini.SetValue("main", "locale", std::to_string(Pref.Language).c_str()); ini.SetValue("main", "audioVolume", std::to_string(Pref.Volume).c_str()); ini.SetValue("main", "musicVolume", std::to_string(Pref.VolumeM).c_str()); ini.SetValue("main", "humanRightsQuiz", std::to_string(Pref.HumanRightsQuiz).c_str()); - ini.SetValue("easy", "maxLevel", std::to_string(Pref.NiveauMax[0]).c_str()); - ini.SetValue("normal", "maxLevel", std::to_string(Pref.NiveauMax[1]).c_str()); - ini.SetValue("difficult", "maxLevel", std::to_string(Pref.NiveauMax[2]).c_str()); + ini.SetValue("easy", "maxLevel", std::to_string(Pref.LevelMax[0]).c_str()); + ini.SetValue("normal", "maxLevel", std::to_string(Pref.LevelMax[1]).c_str()); + ini.SetValue("difficult", "maxLevel", std::to_string(Pref.LevelMax[2]).c_str()); for (int i = 0; i < 8; ++i) { std::string scoreKey = "score_" + std::to_string(i); std::string nameKey = "name_" + std::to_string(i); diff --git a/src/utils.h b/src/utils.h index dbf0c17..fa5411e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -35,8 +35,8 @@ class Utils static void GetPath(char *Path); // Add the path to the filename depending on the OS (sprites, levels) - static bool LoadPref(); // Load preferences - static void SauvePref(); // Save preferences + static bool LoadPref(); + static void SavePref(); static void doScreenshot(SDL_Renderer *renderer); };