diff --git a/Sounds/wagon.wav b/Sounds/car.wav similarity index 100% rename from Sounds/wagon.wav rename to Sounds/car.wav diff --git a/Sounds/clic.wav b/Sounds/click.wav similarity index 100% rename from Sounds/clic.wav rename to Sounds/click.wav diff --git a/Sounds/etire.wav b/Sounds/expand.wav similarity index 100% rename from Sounds/etire.wav rename to Sounds/expand.wav diff --git a/Sounds/reduit.wav b/Sounds/shrink.wav similarity index 100% rename from Sounds/reduit.wav rename to Sounds/shrink.wav diff --git a/src/audio.cc b/src/audio.cc index 7663d33..3eb2612 100644 --- a/src/audio.cc +++ b/src/audio.cc @@ -30,29 +30,29 @@ #include "utils.h" #include "preference.h" -/*** Variable globales ***/ +/*** Global variables ***/ /*************************/ extern sNewPreference Pref; extern int currentTime; -/*** Constructeur et Destructeur ***/ -/***********************************/ +/*** Constructors and destructors ***/ +/************************************/ Audio::~Audio() { if (N) { Mix_HaltChannel(-1); for (int i = 0; i < N; i++) { - if (Son[i]) { - Mix_FreeChunk(Son[i]); + if (Sound[i]) { + Mix_FreeChunk(Sound[i]); } } - delete[] Son; + delete[] Sound; } Mix_CloseAudio(); } -/*** Initialise l'Audio ***/ -/**************************/ +/*** Initializes audio ***/ +/*************************/ bool Audio::Init() { char PathFile[512]; @@ -62,46 +62,46 @@ bool Audio::Init() return false; } - /*** Allocation de la mémoire ***/ - N = sFin; - Son = new Mix_Chunk *[sFin]; + /*** Memory allocation ***/ + N = sSize; + Sound = new Mix_Chunk *[sSize]; - /*** Chargement des sons ***/ - strcpy(PathFile, "Sounds/clic.wav"); + /*** Loading sound effects ***/ + strcpy(PathFile, "Sounds/click.wav"); Utils::GetPath(PathFile); - Son[sClic] = Mix_LoadWAV(PathFile); + Sound[sClick] = Mix_LoadWAV(PathFile); strcpy(PathFile, "Sounds/speed.wav"); Utils::GetPath(PathFile); - Son[sSpeed] = Mix_LoadWAV(PathFile); + Sound[sSpeed] = Mix_LoadWAV(PathFile); strcpy(PathFile, "Sounds/crash.wav"); Utils::GetPath(PathFile); - Son[sCrash] = Mix_LoadWAV(PathFile); + Sound[sCrash] = Mix_LoadWAV(PathFile); strcpy(PathFile, "Sounds/end.wav"); Utils::GetPath(PathFile); - Son[sEnd] = Mix_LoadWAV(PathFile); + Sound[sEnd] = Mix_LoadWAV(PathFile); strcpy(PathFile, "Sounds/lose.wav"); Utils::GetPath(PathFile); - Son[sLose] = Mix_LoadWAV(PathFile); + Sound[sLose] = Mix_LoadWAV(PathFile); - strcpy(PathFile, "Sounds/etire.wav"); + strcpy(PathFile, "Sounds/expand.wav"); Utils::GetPath(PathFile); - Son[sEtire] = Mix_LoadWAV(PathFile); + Sound[sExpand] = Mix_LoadWAV(PathFile); - strcpy(PathFile, "Sounds/wagon.wav"); + strcpy(PathFile, "Sounds/car.wav"); Utils::GetPath(PathFile); - Son[sWagon] = Mix_LoadWAV(PathFile); + Sound[sCar] = Mix_LoadWAV(PathFile); - strcpy(PathFile, "Sounds/reduit.wav"); + strcpy(PathFile, "Sounds/shrink.wav"); Utils::GetPath(PathFile); - Son[sReduit] = Mix_LoadWAV(PathFile); + Sound[sShrink] = Mix_LoadWAV(PathFile); strcpy(PathFile, "Sounds/live.wav"); Utils::GetPath(PathFile); - Son[sLive] = Mix_LoadWAV(PathFile); + Sound[sLive] = Mix_LoadWAV(PathFile); strcpy(PathFile, "Sounds/menu.mod"); Utils::GetPath(PathFile); @@ -110,8 +110,8 @@ bool Audio::Init() return true; } -/*** Charge une music 0=menu 1,2,3,4 = game ***/ -/**********************************************/ +/*** Loads a music track, 0 = menu music 1,2,3,4=game music tracks ***/ +/*********************************************************************/ void Audio::LoadMusic(int Num) { char Provi[512] = "Sounds/jeu1.xm"; @@ -124,12 +124,12 @@ void Audio::LoadMusic(int Num) if (Music) { PauseMusic(true); - Mix_HaltMusic(); // Arrete la music + Mix_HaltMusic(); // Stops the music Mix_FreeMusic(Music); Music = nullptr; } - if (Num == 0) { // Si music du menu + if (Num == 0) { // if menu music strcpy(Provi, "Sounds/menu.mod"); Utils::GetPath(Provi); Music = Mix_LoadMUS(Provi); @@ -142,8 +142,8 @@ void Audio::LoadMusic(int Num) PlayMusic(); } -/*** Passe à la music de jeu suivante ***/ -/****************************************/ +/*** Swaps to next game track ***/ +/********************************/ void Audio::NextMusic() { NMus++; @@ -153,26 +153,26 @@ void Audio::NextMusic() LoadMusic(NMus); } -/*** Fait la lecture d'un son ***/ -/********************************/ -void Audio::Play(eSon So) +/*** Plays a sound effect ***/ +/****************************/ +void Audio::Play(eSound index) { if (!N) { return; } - if (So == sClic) { + if (index == sClick) { if (currentTime - MemorizedTime <= 120) { return; } MemorizedTime = currentTime; } - Mix_PlayChannel(-1, Son[So], 0); + Mix_PlayChannel(-1, Sound[index], 0); } -/*** Joue la music ***/ -/*********************/ +/*** Plays the music ***/ +/***********************/ void Audio::PlayMusic() const { if (Music && N) { @@ -181,13 +181,13 @@ void Audio::PlayMusic() const } } -void Audio::PauseMusic(bool Et) const +void Audio::PauseMusic(bool IsMusicPlaying) const { if (!N) { return; } - if (Et) { + if (IsMusicPlaying) { Mix_PauseMusic(); } else { @@ -195,7 +195,7 @@ void Audio::PauseMusic(bool Et) const } } -/*** Valide les Volumes ***/ +/*** Handles sound volumes ***/ /**************************/ void Audio::DoVolume() const { diff --git a/src/audio.h b/src/audio.h index 40f1bb1..a6ad7ad 100644 --- a/src/audio.h +++ b/src/audio.h @@ -26,48 +26,48 @@ #include -/*** Enumération des sons ***/ -/****************************/ -enum eSon { - sClic = 0, +/*** Sound effects enum ***/ +/**************************/ +enum eSound { + sClick = 0, sSpeed, sCrash, sEnd, sLose, - sEtire, - sWagon, - sReduit, + sExpand, + sCar, + sShrink, sLive, - sFin + sSize }; -/*** Définition de la classe Audio ***/ -/*************************************/ +/*** Audio Class definition ***/ +/******************************/ class Audio { public: Audio() = default; ~Audio(); - /*** Fonctions ***/ - bool Init(); // Initialise et charge les fichiers audio - void LoadMusic(int Num); // Charge une music, 0 = music du menu 1,2,3,4=Jeu - void NextMusic(); // Passe à la music suivante + /*** Functions ***/ + bool Init(); // Initializes and loads audio files + void LoadMusic(int Num); // Loads a music track, 0 = menu music 1,2,3,4=game music tracks + void NextMusic(); // Swaps to next game track - void Play(eSon); // Joue un son - void PlayMusic() const; // Joue la music + void Play(eSound); // Plays a sound effect + void PlayMusic() const; // Plays the music - void PauseMusic(bool Etat) const; // Met ou no la music en pause + void PauseMusic(bool IsMusicPlaying) const; // Pauses/Resumes music - void DoVolume() const; // Valide les volumes audio - Mix_Music *Music { nullptr }; // Pointe sur les musics + void DoVolume() const; // Handles sound volumes + Mix_Music *Music { nullptr }; // Pointer to music tracks private: /*** Variables ***/ - int N { 0 }; // Nombre d'échantillon audio - int NMus { 0 }; // Numéro de la music en cours - int MemorizedTime { 0 }; // Mémorise l'horloge pour les clics - Mix_Chunk **Son { nullptr }; // Pointe sur les sons + int N { 0 }; // Number/Amount of sound effects + int NMus { 0 }; // Number of the current music + int MemorizedTime { 0 }; // Memorizes time for clicks + Mix_Chunk **Sound { nullptr }; // Pointer to sound effects }; #endif diff --git a/src/editor.cc b/src/editor.cc index eaf7cd8..760abde 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -36,7 +36,7 @@ #include "gamepad.h" #include "mouse.h" -/*** Variables globales ***/ +/*** Global variables ***/ /**************************/ extern SDL_Renderer *sdlRenderer; @@ -52,27 +52,27 @@ static int NumRail[] = { 10, 10, 10, 0, 10, 1, 2, 3, 10, 4, 5, 6, 7, 8, 9, 10 }; /*** SDL Main ***/ /****************/ -eMenu Editor::SDLMain(int NumNiv) +eMenu Editor::SDLMain(int LevelNumber) { int PyE; int cx = 0, cy = 0; - bool Boutton = false; + bool Button = false; int TypeB = -1; int i, d, dx, dy; - NumN = NumNiv; + NumN = LevelNumber; - Draw(); // Charge le tableau + Draw(); // Loads level SDL_RenderPresent(sdlRenderer); - currentTime = SDL_GetTicks(); // Prend l'horloge + currentTime = SDL_GetTicks(); // Get clock time Option = rail; - // Initialise la sourie + // Initialize mouse m_mouse.Init(nullptr); - // Prend les evenements + // Fetch events do { SDL_Event event; while (SDL_PollEvent(&event)) { @@ -90,18 +90,18 @@ eMenu Editor::SDLMain(int NumNiv) if (event.key.keysym.sym == SDLK_ESCAPE) { return mMenu; } - PrendTouche(event.key.keysym.sym); + GetKeyPress(event.key.keysym.sym); } break; case SDL_MOUSEBUTTONDOWN: if (event.button.state == SDL_PRESSED) { - Boutton = true; + Button = true; TypeB = -1; } break; case SDL_MOUSEBUTTONUP: - Boutton = false; - if (TypeB != -1 && Option == deco && cx >= LT) { // Si doit effacer une décoration + Button = false; + if (TypeB != -1 && Option == deco && cx >= LT) { // If a decoration must be deleted level.T[NumN].NDeco--; } TypeB = -1; @@ -112,15 +112,15 @@ eMenu Editor::SDLMain(int NumNiv) } } - // Gère l'appuis du boutton de la sourie + // Handles mouse click cx = m_mouse.Px / D_Case; cy = m_mouse.Py / D_Case; - if (Boutton && cx < LT) { + if (Button && cx < LT) { switch (Option) { case deco: - if (TypeB == -1) { // Si première fois que appuis sur la touche - for (i = 0; i < level.T[NumN].NDeco; i++) { // Recherche si décoration proche du clic + if (TypeB == -1) { // On first time clicking + for (i = 0; i < level.T[NumN].NDeco; i++) { // Search if there's a decoration nearby the click dx = level.T[NumN].Deco[i].x - m_mouse.Px; dy = level.T[NumN].Deco[i].y - m_mouse.Py; d = dx * dx + dy * dy; @@ -128,14 +128,14 @@ eMenu Editor::SDLMain(int NumNiv) TypeB = i; } } - if (TypeB == -1) { // Si doit fair un nouveau décor + if (TypeB == -1) { // Building a new decor level.T[NumN].NDeco++; level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].NumSpr = NumDeco; level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].x = m_mouse.Px; level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].y = m_mouse.Py; TypeB = 1; } - else { // Fait passe la selection au premier plan + else { // Highlight selection level.T[NumN].Deco[level.T[NumN].NDeco].NumSpr = level.T[NumN].Deco[TypeB].NumSpr; level.T[NumN].Deco[level.T[NumN].NDeco].x = level.T[NumN].Deco[TypeB].x; level.T[NumN].Deco[level.T[NumN].NDeco].y = level.T[NumN].Deco[TypeB].y; @@ -147,7 +147,7 @@ eMenu Editor::SDLMain(int NumNiv) NumDeco = level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].NumSpr; } } - else { // Si pas la première fois remplace + else { // if not the first click, replace level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].NumSpr = NumDeco; level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].x = m_mouse.Px; level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].y = m_mouse.Py; @@ -164,14 +164,14 @@ eMenu Editor::SDLMain(int NumNiv) } level.T[NumN].T[cy * LT + cx] = TypeB; break; - case wagon: - level.T[NumN].T[cy * LT + cx] = C_Wagon; + case car: + level.T[NumN].T[cy * LT + cx] = C_Car; break; - case pluslong: - level.T[NumN].T[cy * LT + cx] = C_Allonge; + case expander: + level.T[NumN].T[cy * LT + cx] = C_Expand; break; - case pluscourt: - level.T[NumN].T[cy * LT + cx] = C_Reduit; + case shrinker: + level.T[NumN].T[cy * LT + cx] = C_Shrink; break; case speed: level.T[NumN].T[cy * LT + cx] = C_Speed; @@ -183,21 +183,21 @@ eMenu Editor::SDLMain(int NumNiv) case (e_Sprite)(locomotive + D_Bottom): case (e_Sprite)(locomotive + D_Left): case (e_Sprite)(locomotive + D_Right): - level.T[NumN].DepX = cx; - level.T[NumN].DepY = cy; - level.T[NumN].DepDir = (int)(Option) - (int)(locomotive); + level.T[NumN].StartX = cx; + level.T[NumN].StartY = cy; + level.T[NumN].StartDir = (int)(Option) - (int)(locomotive); break; default: break; } } - // Gère les Horloges et la pose + // Handles time and pause previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - // Fait l'affichage + // Handles displaying Draw(); SDL_RenderPresent(sdlRenderer); @@ -206,38 +206,38 @@ eMenu Editor::SDLMain(int NumNiv) return mQuit; } -/*** Charge un tableau ***/ -/*************************/ +/*** Loads a map ***/ +/*******************/ void Editor::Draw() const { int i, x, y, m, cx, cy; unsigned char *T; - // Prend l'adresse du niveau + // Adress of the level T = level.T[NumN].T; - // Fabrique le fond du jeu - Sprites[fond].Draw(400, 300, 0); + // Builds the game's background + Sprites[background].Draw(400, 300, 0); - // Affiche le circuit + // Displays the train track for (i = 0; i < LT * HT; i++) { - if (T[i] >= C_Rail && T[i] < C_Fin) { + if (T[i] >= C_Rail && T[i] < C_Size) { y = i / LT * D_Case + D_Case / 2; x = i % LT * D_Case + D_Case / 2; m = 0; cx = i % LT; cy = i / LT; - if (cy > 0 && T[i - LT] >= 1 && T[i - LT] < C_Fin) { + if (cy > 0 && T[i - LT] >= 1 && T[i - LT] < C_Size) { m += 8; } - if (cy < HT - 1 && T[i + LT] >= 1 && T[i + LT] < C_Fin) { + if (cy < HT - 1 && T[i + LT] >= 1 && T[i + LT] < C_Size) { m += 4; } - if (cx > 0 && T[i - 1] >= 1 && T[i - 1] < C_Fin) { + if (cx > 0 && T[i - 1] >= 1 && T[i - 1] < C_Size) { m += 2; } - if (cx < LT - 1 && T[i + 1] >= 1 && T[i + 1] < C_Fin) { + if (cx < LT - 1 && T[i + 1] >= 1 && T[i + 1] < C_Size) { m += 1; } @@ -245,57 +245,57 @@ void Editor::Draw() const } } - // Affiche les décorations + // Displays decorations for (i = 0; i < level.T[NumN].NDeco; i++) { 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 + // Displays the level number DrawNumber(740, 130, NumN + 1); - // Affiche les options + // Display possible sprites for (i = 0; i < LT * HT; i++) { switch (T[i]) { - case C_Wagon: // Si un loco - Sprites[wagon].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + case C_Car: // Car sprite + Sprites[car].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].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + case C_Expand: // Expand sprite + Sprites[expander].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].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); + case C_Shrink: // Shrink sprite + Sprites[shrinker].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; - case C_Speed: // Si plus vite + case C_Speed: // Speed sprite 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 + case C_Live: // Life sprite Sprites[life].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; } } - // Affiche le départ de la locomotive - switch (level.T[NumN].DepDir) { + // Displays the starting point of the locomotive + switch (level.T[NumN].StartDir) { case D_Top: - Sprites[locomotive].Draw(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].StartX * D_Case + D_Case / 2, level.T[NumN].StartY * D_Case + D_Case / 2, 0); break; case D_Bottom: - Sprites[locomotive].Draw(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].StartX * D_Case + D_Case / 2, level.T[NumN].StartY * D_Case + D_Case / 2, 40); break; case D_Left: - Sprites[locomotive].Draw(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].StartX * D_Case + D_Case / 2, level.T[NumN].StartY * D_Case + D_Case / 2, 80); break; case D_Right: - Sprites[locomotive].Draw(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].StartX * D_Case + D_Case / 2, level.T[NumN].StartY * D_Case + D_Case / 2, 120); break; } - // Affiche l'option choisi dans le menu + // Displays selected option in the menu switch (Option) { case rail: - case wagon: - case pluslong: - case pluscourt: + case car: + case expander: + case shrinker: case speed: case life: Sprites[Option].Draw(740, 200, 0); @@ -319,7 +319,7 @@ void Editor::Draw() const break; } - // Affiche le curseur + // Displays the cursor if (Option != deco) { Sprites[cursor].Draw(m_mouse.Px, m_mouse.Py, 0); } @@ -328,13 +328,13 @@ void Editor::Draw() const } } -/*** Prend les touches enfoncées ***/ -/***********************************/ -void Editor::PrendTouche(int Tou) +/*** Fetches pressed/held keys ***/ +/*********************************/ +void Editor::GetKeyPress(int Key) { int i, j; - switch (Tou) { + switch (Key) { case SDLK_PAGEUP: if (NumN < level.N - 1) { NumN++; @@ -392,23 +392,23 @@ void Editor::PrendTouche(int Tou) level.Clear(NumN); break; case '$': - // test si le dernier niveau est vide + // Checks if the last level is empty for (j = i = 0; i < LT * HT; i++) { j += level.T[level.N - 1].T[i]; } if (j == 0) { if (NumN < level.N - 1) { - level.N--; // Si vide ne le compte pas + level.N--; // Not counted if empty } } - // Sauve le niveau + // Saving the level if (level.Save() == false) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error while saving levels"); exit(-1); } - // test le niveau + // Testing the level Pref.Level = NumN; m_game.SDLMain(); m_mouse.Init(nullptr); @@ -418,13 +418,13 @@ void Editor::PrendTouche(int Tou) Option = rail; break; case 'z': - Option = wagon; + Option = car; break; case 'e': - Option = pluslong; + Option = expander; break; case 'r': - Option = pluscourt; + Option = shrinker; break; case 't': Option = speed; diff --git a/src/editor.h b/src/editor.h index f305e3c..01dc39f 100644 --- a/src/editor.h +++ b/src/editor.h @@ -31,7 +31,7 @@ class Mouse; class Game; class Gamepad; -/*** Définition de la class ***/ +/*** Editor Class definition ***/ /******************************/ class Editor { @@ -40,15 +40,15 @@ class Editor m_mouse(mouse), m_game(game), m_gamepad(gamepad) { }; ~Editor() = default; - /*** Fonctions ***/ + /*** Functions ***/ /*****************/ - eMenu SDLMain(int NumNiveau); // Boucle principale - void Draw() const; // Charge un tableau - void PrendTouche(int Touche); // Prend les touches enfoncées + eMenu SDLMain(int LevelNumber); // Main loop + void Draw() const; // Loads a map + void GetKeyPress(int Key); // Fetches pressed/held keys private: /*** Variables ***/ - int N { 0 }; // Numero du tableau à éditer + int N { 0 }; // Index of the edited level e_Sprite Option { locomotive }; int NumDeco { 0 }; int NumN { 0 }; diff --git a/src/game.cc b/src/game.cc index 6f17fea..f67471c 100644 --- a/src/game.cc +++ b/src/game.cc @@ -37,7 +37,7 @@ #include "utils.h" #include "audio.h" -/*** Variables globales ***/ +/*** Global variables ***/ /**************************/ extern SDL_Renderer *sdlRenderer; @@ -47,23 +47,23 @@ extern sNewPreference Pref; extern int currentTime; extern int previousTime; -extern Screen Ec; +extern Screen screen; extern Level level; static int NumRail[] = { -1, -1, -1, 0, -1, 1, 2, 3, -1, 4, 5, 6, 7, 8, 9, 10 }; -int MasqueK; // Masque pour les touches de déplacement +int MaskK; // Mask for movement keys -/*** Constructeur et Destructeur ***/ +/*** Constructors and Destructors ***/ /***********************************/ Game::Game(Audio &sounds, Gamepad &gamepad) : m_sounds(sounds), m_gamepad(gamepad), Lo(m_sounds) { - Touche[0] = D_Top; - Touche[1] = D_Bottom; - Touche[2] = D_Left; - Touche[3] = D_Right; + KeyPress[0] = D_Top; + KeyPress[1] = D_Bottom; + KeyPress[2] = D_Left; + KeyPress[3] = D_Right; } /*** SDL Main ***/ @@ -74,20 +74,20 @@ eMenu Game::SDLMain() int NumN = Pref.Level; Help = true; - Load(NumN); // Charge le tableau + Load(NumN); // Loads map/level SDL_RenderPresent(sdlRenderer); - Ec.CleanSpriteAndScreen(fjeu); + screen.CleanSpriteAndScreen(fgame); Pause = true; - currentTime = SDL_GetTicks(); // Prend l'horloge - DureeJeu = 0; + currentTime = SDL_GetTicks(); // get Clock time + GameClock = 0; Key = 0; - // Met le options de départ du joueur + // Set initial options for the player Pref.Lives = N_LIVES_COUNT; Pref.Score = 0; - // Prend les evenements + // Event Handling do { bool doScreenshot = false; SDL_RenderClear(sdlRenderer); @@ -99,8 +99,8 @@ eMenu Game::SDLMain() case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_ENTER) { } - else if (event.window.event == SDL_WINDOWEVENT_LEAVE) { // Si désactive l'ecran - Pause = true; // Met en Pause + else if (event.window.event == SDL_WINDOWEVENT_LEAVE) { // If window is inactive + Pause = true; // Pause game } break; case SDL_MOUSEBUTTONDOWN: @@ -123,7 +123,7 @@ eMenu Game::SDLMain() Pause = false; } else { - TourneFleche(); + TurnArrow(); } } break; @@ -153,20 +153,20 @@ eMenu Game::SDLMain() } switch (Key) { case SDLK_UP: - BufTouche(D_Top); - MasqueK |= 1; + BufKeyPress(D_Top); + MaskK |= 1; break; case SDLK_DOWN: - BufTouche(D_Bottom); - MasqueK |= 2; + BufKeyPress(D_Bottom); + MaskK |= 2; break; case SDLK_LEFT: - BufTouche(D_Left); - MasqueK |= 4; + BufKeyPress(D_Left); + MaskK |= 4; break; case SDLK_RIGHT: - BufTouche(D_Right); - MasqueK |= 8; + BufKeyPress(D_Right); + MaskK |= 8; break; case SDLK_F12: // Save screenshot doScreenshot = true; @@ -193,21 +193,21 @@ eMenu Game::SDLMain() case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_UP: - MasqueK &= 14; + MaskK &= 14; break; case SDLK_DOWN: - MasqueK &= 13; + MaskK &= 13; break; case SDLK_LEFT: - MasqueK &= 11; + MaskK &= 11; break; case SDLK_RIGHT: - MasqueK &= 7; + MaskK &= 7; break; default: break; } - if (!MasqueK) { + if (!MaskK) { Key = 0; } break; @@ -218,35 +218,35 @@ eMenu Game::SDLMain() } } - // Gère les Horloges et la pose + // Handling pause and clocks previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - if (Pause == true || Lo.Mort > currentTime) { + if (Pause == true || Lo.Dead > currentTime) { previousTime = currentTime; } - DureeJeu += currentTime - previousTime; + GameClock += currentTime - previousTime; - // Fait l'affichage + // Handles display DrawLevel(NumN); - AfficheEcran(); + DisplayScreen(); SDL_RenderPresent(sdlRenderer); if (doScreenshot) { Utils::doScreenshot(sdlRenderer); } - // Fait avancer la loco - if (Lo.Mort == -1 && Pause == false) { - Lo.Avance(currentTime - previousTime, DureeJeu, Touche, T); + // Locomotive moves forward + if (Lo.Dead == -1 && Pause == false) { + Lo.MoveForward(currentTime - previousTime, GameClock, KeyPress, T); } - // Test la fin d'une partie - if (Lo.Mort > -1 && Lo.Mort < currentTime) { // Si est Mort test si doit continuer ou quitter + // Checks if the game ended (Death or timeout) + if (Lo.Dead > -1 && Lo.Dead < currentTime) { // If dead, check for remaining lives if (Pref.Lives < 0) { - return mScoreEdit; // Si mort fini + return mScoreEdit; // Game ends } - if (Lo.Gagne) { + if (Lo.Win) { #ifndef DCHILDREN if (Pref.HumanRightsQuiz && m_menu->SDLMain_HR() == mQuit) { return mQuit; @@ -262,9 +262,9 @@ eMenu Game::SDLMain() } } m_sounds.NextMusic(); - DureeJeu = 0; + GameClock = 0; Pause = true; - Key = MasqueK = 0; + Key = MaskK = 0; Load(NumN); } @@ -273,20 +273,20 @@ eMenu Game::SDLMain() return mQuit; } -/*** Charge un tableau ***/ +/*** Loads a level/map ***/ /*************************/ -bool Game::Load(int NivN) +bool Game::Load(int LevelN) { int i; - Pref.Level = NivN; + Pref.Level = LevelN; - // Recopie le tableau + // Copy wanted level to current for (i = 0; i < LT * HT; i++) { - T[i] = (int)level.T[NivN].T[i]; + T[i] = (int)level.T[LevelN].T[i]; } - // Laisse ou efface la vie suivant le niveau + // Change lives count with difficulty settings switch (Pref.Difficulty) { case Easy: i = 5; @@ -305,12 +305,12 @@ bool Game::Load(int NivN) } } - // Initialise la locomotive - Lo.Init(level.T[NivN].DepX + level.T[NivN].DepY * LT, level.T[NivN].DepDir); - BufTouche(level.T[NivN].DepDir); - MasqueK = 0; + // Initialize locomotive + Lo.Init(level.T[LevelN].StartX + level.T[LevelN].StartY * LT, level.T[LevelN].StartDir); + BufKeyPress(level.T[LevelN].StartDir); + MaskK = 0; - // Met la vitesse suivant difficulté + // Adapt speed with difficulty switch (Pref.Difficulty) { case Easy: Pref.Speed = Pref.SpeedAverage = SPEED_MIN; @@ -322,184 +322,183 @@ bool Game::Load(int NivN) Pref.Speed = Pref.SpeedAverage = SPEED_AVERAGE; } - return DrawLevel(NivN); + return DrawLevel(LevelN); } -/*** Dessine le fond de l'ecran de jeu ***/ -/*****************************************/ -bool Game::DrawLevel(int NivN) +/*** Draws the background of the game ***/ +/****************************************/ +bool Game::DrawLevel(int LevelN) { int i, x, y, m, cx, cy; - // Fabrique le fond du jeu - Sprites[fond].Draw(400, 300, 0, Sprites[fjeu].Image[0]); + // Builds the background of the game + Sprites[background].Draw(400, 300, 0, Sprites[fgame].Image[0]); - // Affiche le circuit + // Displays the train track for (i = 0; i < LT * HT; i++) { - if (T[i] >= C_Rail && T[i] < C_Fin) { + if (T[i] >= C_Rail && T[i] < C_Size) { y = i / LT * D_Case + D_Case / 2; x = i % LT * D_Case + D_Case / 2; m = 0; cx = i % LT; cy = i / LT; - if (cy > 0 && T[i - LT] >= C_Rail && T[i - LT] < C_Fin) { + if (cy > 0 && T[i - LT] >= C_Rail && T[i - LT] < C_Size) { m += 8; } - if (cy < HT - 1 && T[i + LT] >= C_Rail && T[i + LT] < C_Fin) { + if (cy < HT - 1 && T[i + LT] >= C_Rail && T[i + LT] < C_Size) { m += 4; } - if (cx > 0 && T[i - 1] >= C_Rail && T[i - 1] <= C_Fin) { + if (cx > 0 && T[i - 1] >= C_Rail && T[i - 1] <= C_Size) { m += 2; } - if (cx < LT - 1 && T[i + 1] >= C_Rail && T[i + 1] <= C_Fin) { + if (cx < LT - 1 && T[i + 1] >= C_Rail && T[i + 1] <= C_Size) { m += 1; } - Sprites[rail].Draw(x, y, NumRail[m], Sprites[fjeu].Image[0]); + Sprites[rail].Draw(x, y, NumRail[m], Sprites[fgame].Image[0]); } } - // Affiche les décorations + // Display decorations #ifndef DCHILDREN - for (i = 0; i < level.T[NivN].NDeco; i++) { - 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]); + for (i = 0; i < level.T[LevelN].NDeco; i++) { + Sprites[deco].Draw(level.T[LevelN].Deco[i].x, level.T[LevelN].Deco[i].y, level.T[LevelN].Deco[i].NumSpr, + Sprites[fgame].Image[0]); } #endif - // Affiche les textes suivant la langue - 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]); + // Displays texts for selected language + DrawText(740, 110, T_level, Sprites[fgame].Image[0]); + DrawText(740, 180, T_score, Sprites[fgame].Image[0]); + DrawText(740, 260, T_options, Sprites[fgame].Image[0]); + DrawText(740, 340, T_lives, Sprites[fgame].Image[0]); - DrawNumber(740, 140, Pref.Level + 1, Sprites[fjeu].Image[0]); + DrawNumber(740, 140, Pref.Level + 1, Sprites[fgame].Image[0]); return true; } -/*** Fait tourner la fleche d'une simple touche ***/ -/**************************************************/ -void Game::TourneFleche() +/*** Turn arrow with a keypress ***/ +/**********************************/ +void Game::TurnArrow() { - int To = Touche[0]; - bool Cherche = false; - int const x = Lo.PInter % LT; - int const y = Lo.PInter / LT; + int Key = KeyPress[0]; + bool Search = false; + int const x = Lo.IntersectPos % LT; + int const y = Lo.IntersectPos / LT; do { - // Fait toucher la direction dans le sens des aiguilles d'une montre - // et test si la nouvelle direction est possible - switch (To) { + // Key turns clockwise and searches if the new wanted direction is possible + switch (Key) { case D_Top: - To = D_Right; - if (Lo.PEntree != D_Right && x + 1 < LT && T[Lo.PInter + 1] != 0) { - Cherche = true; + Key = D_Right; + if (Lo.EntryPos != D_Right && x + 1 < LT && T[Lo.IntersectPos + 1] != 0) { + Search = true; } break; case D_Right: - To = D_Bottom; - if (Lo.PEntree != D_Bottom && y + 1 < HT && T[Lo.PInter + LT] != 0) { - Cherche = true; + Key = D_Bottom; + if (Lo.EntryPos != D_Bottom && y + 1 < HT && T[Lo.IntersectPos + LT] != 0) { + Search = true; } break; case D_Bottom: - To = D_Left; - if (Lo.PEntree != D_Left && x > 0 && T[Lo.PInter - 1] != 0) { - Cherche = true; + Key = D_Left; + if (Lo.EntryPos != D_Left && x > 0 && T[Lo.IntersectPos - 1] != 0) { + Search = true; } break; case D_Left: - To = D_Top; - if (Lo.PEntree != D_Top && y > 0 && T[Lo.PInter - LT] != 0) { - Cherche = true; + Key = D_Top; + if (Lo.EntryPos != D_Top && y > 0 && T[Lo.IntersectPos - LT] != 0) { + Search = true; } break; } - } while (Cherche == false); + } while (Search == false); - BufTouche(To); // Mémorise la nouvelle touche par defaut. + BufKeyPress(Key); // Stores the new default key } -/*** Mémorise une touche dans le buffet des touches ***/ -/******************************************************/ -void Game::BufTouche(int Tou) +/*** Stores key presses in an array ***/ +/**************************************/ +void Game::BufKeyPress(int Key) { int n = 0; - // Favorise la touche - while (Touche[n] != Tou) { - n++; // Prend position de la touche + // Prioritize new key + while (KeyPress[n] != Key) { + n++; // Stores the position of the key } - if (n) { // Si changement doit faire un décalage + if (n) { // On change, shift indices while (n) { - Touche[n] = Touche[n - 1]; + KeyPress[n] = KeyPress[n - 1]; n--; } - Touche[0] = Tou; // Mémorise la touche + KeyPress[0] = Key; // Store key } - // Cherche son oposé - switch (Tou) { + // Search the key's opposite + switch (Key) { case D_Top: - Tou = D_Bottom; + Key = D_Bottom; break; case D_Bottom: - Tou = D_Top; + Key = D_Top; break; case D_Left: - Tou = D_Right; + Key = D_Right; break; case D_Right: - Tou = D_Left; + Key = D_Left; break; } - // Défavorise son oposé. + // Disadvantage its opposite n = 3; - while (Touche[n] != Tou) { - n--; // Prend position de la touche + while (KeyPress[n] != Key) { + n--; // Stores the position of the key } - if (n < 3) { // Si changement doit faire un décalage + if (n < 3) { // On change, shift indices while (n < 3) { - Touche[n] = Touche[n + 1]; + KeyPress[n] = KeyPress[n + 1]; n++; } - Touche[3] = Tou; // Mémorise la touche + KeyPress[3] = Key; // Store key } } -/*** Test les directions possibles pour les fleches ***/ -/******************************************************/ -int Game::TestFleche(int Haut, int Bas, int Gauche, int Droite) +/*** Attempts possible directions for the arrows ***/ +/***************************************************/ +int Game::TestArrows(int Up, int Down, int Left, int Right) { int i; - int const x = Lo.PInter % LT; - int const y = Lo.PInter / LT; + int const x = Lo.IntersectPos % LT; + int const y = Lo.IntersectPos / LT; for (i = 0; i < 4; i++) { - switch (Touche[i]) { + switch (KeyPress[i]) { case D_Top: - if (y > 0 && Haut != -1 && T[Lo.PInter - LT] != 0) { - return Haut; + if (y > 0 && Up != -1 && T[Lo.IntersectPos - LT] != 0) { + return Up; } break; case D_Bottom: - if (y + 1 < HT && Bas != -1 && T[Lo.PInter + LT] != 0) { - return Bas; + if (y + 1 < HT && Down != -1 && T[Lo.IntersectPos + LT] != 0) { + return Down; } break; case D_Left: - if (x > 0 && Gauche != -1 && T[Lo.PInter - 1] != 0) { - return Gauche; + if (x > 0 && Left != -1 && T[Lo.IntersectPos - 1] != 0) { + return Left; } break; case D_Right: - if (x + 1 < LT && Droite != -1 && T[Lo.PInter + 1] != 0) { - return Droite; + if (x + 1 < LT && Right != -1 && T[Lo.IntersectPos + 1] != 0) { + return Right; } break; } @@ -507,70 +506,70 @@ int Game::TestFleche(int Haut, int Bas, int Gauche, int Droite) return 0; } -/*** Affiche un ecran du jeu ***/ -/*******************************/ -void Game::AfficheEcran() +/*** Displays game screen ***/ +/****************************/ +void Game::DisplayScreen() { int i; int ndir = 0; - // Fait nouvelle Affichage - Lo.Display(Ec); // Affiche la loco + // New Display + Lo.Display(screen); // Display locomotive - if (Lo.PInter != -1 && Help) { // Affiche la fleche sur la futur intersection - switch (Lo.PEntree) { + if (Lo.IntersectPos != -1 && Help) { // Display arrow on future intersection + switch (Lo.EntryPos) { case D_Left: - ndir = TestFleche(0, 2, -1, 1); + ndir = TestArrows(0, 2, -1, 1); break; case D_Right: - ndir = TestFleche(8, 6, 7, -1); + ndir = TestArrows(8, 6, 7, -1); break; case D_Top: - ndir = TestFleche(-1, 4, 5, 3); + ndir = TestArrows(-1, 4, 5, 3); break; case D_Bottom: - ndir = TestFleche(10, -1, 9, 11); + ndir = TestArrows(10, -1, 9, 11); break; } - Ec.PrintSprite(dir, ndir, (Lo.PInter % LT) * D_Case + D_Case / 2, (Lo.PInter / LT) * D_Case + D_Case / 2); + screen.PrintSprite(dir, ndir, (Lo.IntersectPos % LT) * D_Case + D_Case / 2, (Lo.IntersectPos / LT) * D_Case + D_Case / 2); } - // Affiche les options + // Display options for (i = 0; i < LT * HT; i++) { switch (T[i]) { - case C_Wagon: // Si un loco - Ec.PrintSprite(wagon, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + case C_Car: // if car sprite + screen.PrintSprite(car, (GameClock * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; - case C_Allonge: // Si plus long - Ec.PrintSprite(pluslong, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + case C_Expand: // if expander sprite + screen.PrintSprite(expander, (GameClock * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; - case C_Reduit: // Si plus court - Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + case C_Shrink: // if shrinker sprite + screen.PrintSprite(shrinker, (GameClock * 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(speed, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + case C_Speed: // if speed sprite + screen.PrintSprite(speed, (GameClock * 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(life, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); + case C_Live: // if life sprite + screen.PrintSprite(life, (GameClock * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; } } - // Si en pose demande une touche + // When paused, asks for a key press if (Pause) { - Ec.PrintText(T_press_any_key, LT * D_Case / 2, 300); + screen.PrintText(T_press_any_key, LT * D_Case / 2, 300); } - // Affiche tableau de bord - Ec.PrintOptions(Pref.Lives, Pref.Score); + // Prints a dashboard + screen.PrintOptions(Pref.Lives, Pref.Score); if (Pref.WagonGap < WAGON_GAP_MIN) { - Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000) % 50, 715, 295); + screen.PrintSprite(shrinker, (GameClock * 40 / 1000) % 50, 715, 295); } if (Pref.WagonGap > WAGON_GAP_AVERAGE) { - Ec.PrintSprite(pluslong, (DureeJeu * 40 / 1000) % 50, 715, 295); + screen.PrintSprite(expander, (GameClock * 40 / 1000) % 50, 715, 295); } if (Pref.SpeedAverage > Pref.Speed) { - Ec.PrintSprite(speed, (DureeJeu * 40 / 1000 + 7) % 50, 765, 295); + screen.PrintSprite(speed, (GameClock * 40 / 1000 + 7) % 50, 765, 295); } } diff --git a/src/game.h b/src/game.h index 3fdaa5a..aef9f4f 100644 --- a/src/game.h +++ b/src/game.h @@ -31,8 +31,8 @@ class Audio; class Menu; class Gamepad; -/*** Définition de la class ***/ -/******************************/ +/*** Game class definition ***/ +/*****************************/ class Game { public: @@ -40,33 +40,33 @@ class Game ~Game() = default; void setMenu(Menu *menu) { m_menu = menu; } - /*** Fonctions ***/ + /*** Functions ***/ /*****************/ - eMenu SDLMain(); // Boucle principale - bool Load(int NivN); // Charge un tableau - bool DrawLevel(int NivN); // Dessine le niveau + eMenu SDLMain(); // Main loop + bool Load(int LevelN); // Load a level/map + bool DrawLevel(int LevelN); // draws the level - void TourneFleche(); // Fait tourner la fleche d'un simple clic. - void BufTouche(int Touche); // Met une nouvelle touche dans le buffet - int TestFleche(int Haut, int Bas, int Gauche, int Droite); // Test la direction de sortie de la fleche - void AfficheEcran(); // Fait l'affichage d'un ecran de jeu + void TurnArrow(); // Turn intersection arrow on key presses + void BufKeyPress(int Key); // Store key presses in Keypress array + int TestArrows(int Up, int Down, int Left, int Right); // Attempts possible directions for the arrows + void DisplayScreen(); // Displays game screen private: /*** Variables ***/ - bool Pause { false }; // Si en pose + bool Pause { false }; // if paused - long DureeJeu { 0 }; // Horloge de durée du jeu + long GameClock { 0 }; // In game time clock - int Key { 0 }; // Mémorise la touche enfoncée - int Touche[4]; // Direction demandée - int T[LT * HT]; // Pointe sur le tableau + int Key { 0 }; // Stores keypress + int KeyPress[4]; // Stores wanted direction + int T[LT * HT]; // Pointer to level - bool Help { true }; // Si doit affiche les fleches d'aide + bool Help { true }; // Show intersection arrows Audio &m_sounds; Gamepad &m_gamepad; Menu *m_menu { nullptr }; - Loco Lo; // Gère la locomotive + Loco Lo; // locomotive }; #endif diff --git a/src/level.cc b/src/level.cc index 2a64f36..2607244 100644 --- a/src/level.cc +++ b/src/level.cc @@ -25,7 +25,7 @@ #include "utils.h" #include "level.h" -/*** Constructeurs ***/ +/*** Constructor ***/ /*********************/ Level::Level() { @@ -35,8 +35,8 @@ Level::Level() } } -/*** Charge les tableaux ***/ -/***************************/ +/*** Load levels/maps ***/ +/************************/ bool Level::Load() { unsigned char *Buf; @@ -50,16 +50,16 @@ bool Level::Load() return false; } - // Charge les tableaux + // Store levels, N is the number of levels N = (int)(Buf[0]) * 256 + (int)(Buf[1]); for (i = 0; i < N; i++) { for (j = 0; j < LT * HT; j++) { T[i].T[j] = Buf[P++]; } - T[i].DepX = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); - T[i].DepY = (int)(Buf[P + 2]) * 256 + (int)(Buf[P + 3]); - T[i].DepDir = (int)(Buf[P + 4]) * 256 + (int)(Buf[P + 5]); + T[i].StartX = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); + T[i].StartY = (int)(Buf[P + 2]) * 256 + (int)(Buf[P + 3]); + T[i].StartDir = (int)(Buf[P + 4]) * 256 + (int)(Buf[P + 5]); T[i].NDeco = (int)(Buf[P + 6]) * 256 + (int)(Buf[P + 7]); P += 8; for (j = 0; j < T[i].NDeco; j++) { @@ -75,8 +75,8 @@ bool Level::Load() return true; } -/*** Sauve les tableaux ***/ -/**************************/ +/*** Save levels ***/ +/*******************/ bool Level::Save() { unsigned char *Buf; @@ -84,13 +84,13 @@ bool Level::Save() int i, j; char NameLevelFile[512] = "levels.dat"; - // Alloue la mémoire + // Allocate memory Buf = new unsigned char[sizeof(s_Level) * N + sizeof(int) + 1]; if (Buf == nullptr) { return false; } - // Charge les tableaux + // Load levels Buf[0] = N / 256; Buf[1] = N % 256; @@ -98,12 +98,12 @@ bool Level::Save() for (j = 0; j < LT * HT; j++) { Buf[P++] = T[i].T[j]; } - Buf[P] = T[i].DepX / 256; - Buf[P + 1] = T[i].DepX % 256; - Buf[P + 2] = T[i].DepY / 256; - Buf[P + 3] = T[i].DepY % 256; - Buf[P + 4] = T[i].DepDir / 256; - Buf[P + 5] = T[i].DepDir % 256; + Buf[P] = T[i].StartX / 256; + Buf[P + 1] = T[i].StartX % 256; + Buf[P + 2] = T[i].StartY / 256; + Buf[P + 3] = T[i].StartY % 256; + Buf[P + 4] = T[i].StartDir / 256; + Buf[P + 5] = T[i].StartDir % 256; Buf[P + 6] = T[i].NDeco / 256; Buf[P + 7] = T[i].NDeco % 256; @@ -119,7 +119,7 @@ bool Level::Save() } } - // Sauve les tableaux + // Save Levels Utils::GetPath(NameLevelFile); if (Utils::SaveFile(NameLevelFile, (char *)Buf, P) == false) { delete[] Buf; @@ -130,8 +130,8 @@ bool Level::Save() return true; } -/*** Efface un Tableau ***/ -/*************************/ +/*** Delete Level with level number ***/ +/**************************************/ void Level::Del(int Num) { int i, j; @@ -141,9 +141,9 @@ void Level::Del(int Num) for (j = 0; j < LT * HT; j++) { T[i].T[j] = T[i + 1].T[j]; } - T[i].DepX = T[i + 1].DepX; - T[i].DepY = T[i + 1].DepY; - T[i].DepDir = T[i + 1].DepDir; + T[i].StartX = T[i + 1].StartX; + T[i].StartY = T[i + 1].StartY; + T[i].StartDir = T[i + 1].StartDir; T[i].NDeco = T[i + 1].NDeco; for (j = 0; j < T[i].NDeco; j++) { T[i].Deco[j].x = T[i + 1].Deco[j].x; @@ -155,8 +155,8 @@ void Level::Del(int Num) } } -/*** Insert un Tableau ***/ -/*************************/ +/*** Insert level ***/ +/********************/ void Level::Ins(int Num) { int i, j; @@ -166,9 +166,9 @@ void Level::Ins(int Num) for (j = 0; j < LT * HT; j++) { T[i].T[j] = T[i - 1].T[j]; } - T[i].DepX = T[i - 1].DepX; - T[i].DepY = T[i - 1].DepY; - T[i].DepDir = T[i - 1].DepDir; + T[i].StartX = T[i - 1].StartX; + T[i].StartY = T[i - 1].StartY; + T[i].StartDir = T[i - 1].StartDir; T[i].NDeco = T[i - 1].NDeco; for (j = 0; j < T[i].NDeco; j++) { T[i].Deco[j].x = T[i - 1].Deco[j].x; @@ -182,8 +182,8 @@ void Level::Ins(int Num) } } -/*** Vide un tableau ***/ -/***********************/ +/*** Empty/Clear levels ***/ +/**************************/ void Level::Clear(int Num) { int i; @@ -191,7 +191,7 @@ void Level::Clear(int Num) for (i = 0; i < LT * HT; i++) { T[Num].T[i] = C_None; } - T[Num].DepX = LT / 2; - T[Num].DepY = HT / 2; + T[Num].StartX = LT / 2; + T[Num].StartY = HT / 2; T[Num].NDeco = 0; } diff --git a/src/level.h b/src/level.h index a4f0576..6d521c8 100644 --- a/src/level.h +++ b/src/level.h @@ -26,26 +26,26 @@ #include "preference.h" -/*** Définition de la structure d'un tableau ***/ -/***********************************************/ +/*** struct definition for levels ***/ +/************************************/ struct s_Deco { - int NumSpr; // Numéro et position du sprite décoratif + int NumSpr; // Number and position of decorative sprite int x; int y; }; struct s_Level { - unsigned char T[LT * HT]; // Définition du circuit et des options - int DepX; // Départ de la locomotive - int DepY; - int DepDir; // Direction du départ - int NDeco; // Nombre d'éléments décoratifs + unsigned char T[LT * HT]; // Circuit and settings definition + int StartX; // Locomotive starting point. + int StartY; + int StartDir; // Locomotive starting direction + int NDeco; // Number of decoration elements struct s_Deco Deco[32]; }; -/*** Définition de la classe ***/ +/*** Level class definition ***/ /*******************************/ class Level { @@ -53,16 +53,16 @@ class Level Level(); ~Level() = default; - /*** Fonctions ***/ - bool Load(); // charge les tableaux - bool Save(); // Sauve les tableaux - void Del(int Num); // efface un tableau - void Ins(int Num); // Insert un tableau vièrge - void Clear(int Num); // Vide un tableau + /*** Functions ***/ + bool Load(); // Loads level/maps + bool Save(); // Save level + void Del(int Num); // Delete level + void Ins(int Num); // Insert (empty) Level + void Clear(int Num); // Empty/Clear level /*** Variables ***/ - int N { 0 }; // Nombre de niveau - s_Level T[MAX_N_LEVEL_IN_MEMORY]; // Pointe sur les tableaux + int N { 0 }; // Number of levels + s_Level T[MAX_N_LEVEL_IN_MEMORY]; // Pointer to levels }; #endif diff --git a/src/loco.cc b/src/loco.cc index db30b66..ddede3e 100644 --- a/src/loco.cc +++ b/src/loco.cc @@ -33,15 +33,15 @@ #define M_PI 3.141592654 #endif -/*** Variables globales ***/ +/*** Global variables ***/ /**************************/ extern sNewPreference Pref; extern int currentTime; -extern int MasqueK; +extern int MaskK; int AddDir[] = { -1, 1, -LT, LT }; -/*** Construteur et Destructeur ***/ +/*** Constructor and destructor ***/ /**********************************/ Loco::Loco(Audio &audio) : m_audio(audio) @@ -49,26 +49,26 @@ Loco::Loco(Audio &audio) : Init(LT / 2 + HT / 2 * LT, D_Right); } -/*** Initialise la locomotive ***/ -/********************************/ +/*** Initialize locomotive ***/ +/*****************************/ void Loco::Init(int Pos, int Direction) { int i; unsigned char Ar = 0; - PLoco = 0; // Pointe sur la première case - PInter = -1; - Speed = Reduce = Extend = 0; // Pas d'alongement - Mort = -1; - Gagne = false; + LocoPos = 0; // Points toward first tile + IntersectPos = -1; + Speed = Reduce = Extend = 0; // No extending + Dead = -1; + Win = false; Pref.WagonGap = WAGON_GAP_AVERAGE; - // Initialise les variables + // Initializing variables for (i = 0; i < 256; i++) { PosWagon[i].SprStart = 0; } - // Cherche le case Avant + // Look for the front tile switch (Direction) { case D_Top: Pos += LT; @@ -88,19 +88,19 @@ void Loco::Init(int Pos, int Direction) break; } - // Initialise le Tableau et la loco - D = D_Case * 1.99; // Positionne la tete presque à la fin + // Initialialize Level and locomotive + D = D_Case * 1.99; // Position the head in front of the locomotive - T[PLoco].P = Pos; - T[PLoco].Arrive = Ar; - T[PLoco].Sortie = Direction; - T[PLoco].D = D_Case; + T[LocoPos].P = Pos; + T[LocoPos].Arrive = Ar; + T[LocoPos].Exit = Direction; + T[LocoPos].D = D_Case; - // Fait avancer d'une case + // Going forward one tile Go(Direction); Go(Direction); - // Initialise la loco et son wagon à charbon + // Initializing the locomotive and its coal wagon NWagon = 2; Wagon[0] = locomotive; Wagon[1] = coal_wagon; @@ -110,23 +110,23 @@ void Loco::Init(int Pos, int Direction) PosWagon[1].dx = PosWagon[1].dy = -10; PosWagon[1].fx = PosWagon[1].fy = -10; - MemoDuree = 0; + MemoDuration = 0; } -/*** Affiche la locomotive ***/ -/*****************************/ -void Loco::Display(Screen &Ec) +/*** Display the locomotive ***/ +/******************************/ +void Loco::Display(Screen &screen) { float ltrain = 0; float p1, p2, a, ar, vx, vy; int x1, x2, y1, y2; int i, ns = 0; - int cdx, cdy, cfx = 0, cfy = 0; // Points d'accroche des cables + int cdx, cdy, cfx = 0, cfy = 0; // Attachment point for cables float lv; - // Affiche tous les wagons + // Display all wagon/(cars) for (i = 0; i < NWagon; i++) { - // Cherche les points du wagons + // Search wagon points switch (Wagon[i]) { case coal_wagon: p1 = ltrain + 11; @@ -141,17 +141,17 @@ void Loco::Display(Screen &Ec) lv = 20; } - // Calcule la position des points + // Calculate cars point's position FindPoint(D - p1, x1, y1); FindPoint(D - p2, x2, y2); - PosWagon[i].dx = x1; // Sauve la position des points pour test de colision futur + PosWagon[i].dx = x1; // Save position points for future collision checks PosWagon[i].dy = y1; PosWagon[i].fx = x2; PosWagon[i].fy = y2; - // Calcule l'angle de rotation de la loco et le N° du Sprite - if (x1 <= x2) { // Angle 0 à 180 compris + // Calculate the locomotive's angle of rotation and the number of the sprite + if (x1 <= x2) { // Angle 0 through 180 vy = (float)(x2 - x1); vx = (float)(y2 - y1); if (vx != 0) { @@ -164,7 +164,7 @@ void Loco::Display(Screen &Ec) a = 180.0 + a; } } - else { // Angle 180.001 à 359.999 + else { // Angle 180.001 through 359.999 vy = (float)(x1 - x2); vx = (float)(y1 - y2); if (vx != 0) { @@ -179,35 +179,35 @@ void Loco::Display(Screen &Ec) } ar = a * M_PI / 180.0; - // Prend le centre du sprite + // store the center of the sprite x1 = (x1 + x2) / 2; y1 = (y1 + y2) / 2; - // Affiche les cables de liaison - if (i > 0) { // Si doit afficher les cables - // Calcule le point d'accroche en sortie + // Ropes/Cables + if (i > 0) { // if we need to display cable + // Calculate the attachment point behind cdx = x1 - (int)(sin(ar) * lv); cdy = y1 - (int)(cos(ar) * lv); - // Affiche le cable - Ec.PrintCable(cdx, cdy, cfx, cfy); + // Displays the cable + screen.PrintCable(cdx, cdy, cfx, cfy); } - // Calcule le crocher de fin pour le prochaine wagon + // Calculate the attachment point for the next Wagon/car cfx = x1 - (int)(sin(ar + M_PI) * lv); cfy = y1 - (int)(cos(ar + M_PI) * lv); - // Cherche le N° du Sprite + // Search the sprite's Number switch ((int)a) { - case 0: // En haut + case 0: // Up ns = (int)(y1 + D_Case / 2) % (int)D_Case; break; - case 180: // En bas + case 180: // Down ns = (int)(y1 + D_Case / 2) % (int)D_Case + 40; break; - case 90: // Gauche + case 90: // Left ns = (int)(x1 + D_Case / 2) % (int)D_Case + 80; break; - case 270: // Droite + case 270: // Right ns = (int)(x1 + D_Case / 2) % (int)D_Case + 120; break; default: @@ -218,86 +218,86 @@ void Loco::Display(Screen &Ec) ns += 160; } - Ec.PrintSprite(Wagon[i], ns, x1, y1); + screen.PrintSprite(Wagon[i], ns, x1, y1); - // Si pas fini la sequence d'affiche de départ du wagon + // If not done, display the start sequence of the wagon if (PosWagon[i].SprStart < N_SPR_START) { - PosWagon[i].SprStart += MemoDuree * N_SPR_START / 750.0; + PosWagon[i].SprStart += MemoDuration * N_SPR_START / 750.0; if (PosWagon[i].SprStart < N_SPR_START) { - Ec.PrintSprite(new_wagon, (int)(PosWagon[i].SprStart), x1, y1); + screen.PrintSprite(new_wagon, (int)(PosWagon[i].SprStart), x1, y1); } } - // Met l'ecart entre les wagons + // Add gap between the wagons/cars ltrain += Pref.WagonGap; } } -/*** Test les options sur une case ***/ -/*************************************/ -void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) +/*** Checking for items/options on a tile ***/ +/*******************************************/ +void Loco::TestTile(float Dist, long GameDuration, int *Level) { int i; float DMoy; float Ec1, vx, vy, Ec2; - // test si depasse milieu d'une case pour teste de colision - DMoy = (T[PLoco].D + T[PLoco - 1].D) / 2.0; + // Check for collisions, half a tile in front of the locomotive + DMoy = (T[LocoPos].D + T[LocoPos - 1].D) / 2.0; if (D <= DMoy && D + Dist >= DMoy) { - // Test si sur une option - switch (Tableau[T[PLoco].P]) { - case C_Wagon: // Une nouvelle loco - m_audio.Play(sWagon); - Tableau[T[PLoco].P] = 1; // efface l'option + // Check if on an item + switch (Level[T[LocoPos].P]) { + case C_Car: // New wagon/car + m_audio.Play(sCar); + Level[T[LocoPos].P] = 1; // Remove item from level Pref.Score += 5; - AddLoco(); // Ajoute une loco au azard + AddLoco(); // Add a random wagon - Gagne = true; // Test si la dernière loco + Win = true; // Check if it was the last wagon for win condition for (i = 0; i < LT * HT; i++) { - if (Tableau[i] == C_Wagon) { - Gagne = false; + if (Level[i] == C_Car) { + Win = false; } } - if (Gagne) { - Mort = currentTime + PAUSE_DURATION; + if (Win) { + Dead = currentTime + PAUSE_DURATION; m_audio.Play(sEnd); } break; - case C_Allonge: // Alonge la loco - m_audio.Play(sEtire); - Tableau[T[PLoco].P] = 1; // efface l'option + case C_Expand: // Expand locomotive item + m_audio.Play(sExpand); + Level[T[LocoPos].P] = 1; // Remove item from map Pref.Score += 20; - if (Reduce > DureeJeu) { - Reduce = DureeJeu - 1; + if (Reduce > GameDuration) { + Reduce = GameDuration - 1; } else { - Extend = DureeJeu + EXTENSION_DURATION; + Extend = GameDuration + EXTENSION_DURATION; } break; - case C_Reduit: // Si réduit la loco - m_audio.Play(sReduit); - Tableau[T[PLoco].P] = 1; // efface l'option - if (Extend > DureeJeu) { - Extend = DureeJeu - 1; + case C_Shrink: // Shrink locomotive item + m_audio.Play(sShrink); + Level[T[LocoPos].P] = 1; // remove item from map + if (Extend > GameDuration) { + Extend = GameDuration - 1; } else { - Reduce = DureeJeu + REDUCTION_DURATION; + Reduce = GameDuration + REDUCTION_DURATION; } break; - case C_Speed: // Si Vitesse + case C_Speed: // Speed item m_audio.Play(sSpeed); - Tableau[T[PLoco].P] = 1; // efface l'option + Level[T[LocoPos].P] = 1; // remove item from map Pref.Score += 30; - Speed = DureeJeu + SPEED_DURATION; + Speed = GameDuration + SPEED_DURATION; break; case C_Live: // Si Vie m_audio.Play(sLive); - Tableau[T[PLoco].P] = 1; // efface l'option + Level[T[LocoPos].P] = 1; // remove item from map Pref.Lives++; break; } - // Test de colision avec un autre Wagon + // Collision check with another wagon/car for (i = 1; i < NWagon; i++) { vx = (float)(PosWagon[i].dx - PosWagon[0].dx); vy = (float)(PosWagon[i].dy - PosWagon[0].dy); @@ -306,206 +306,206 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) vy = (float)(PosWagon[i].fy - PosWagon[0].dy); Ec2 = vx * vx + vy * vy; - // Si colition le signale - if (Mort < currentTime && (Ec1 < RAYON_TOUCHE || Ec2 <= RAYON_TOUCHE)) { + // Death upon hitting wagon in range + if (Dead < currentTime && (Ec1 < RAY_HIT || Ec2 <= RAY_HIT)) { m_audio.Play(sCrash); Pref.Lives--; - Mort = currentTime + PAUSE_DURATION; + Dead = currentTime + PAUSE_DURATION; } } } } -/*** Fait Avancer la locomotive ***/ -/**********************************/ -void Loco::Avance(int Duree, long DureeJeu, int *Touche, int *Tableau) +/*** Makes locomotive move forward ***/ +/*************************************/ +void Loco::MoveForward(int Duration, long GameDuration, int *Key, int *Level) { int i; - float Dist = Pref.SpeedAverage * (float)(Duree) / 1000.0; + float Dist = Pref.SpeedAverage * (float)(Duration) / 1000.0; - MemoDuree = (float)(Duree); + MemoDuration = (float)(Duration); - TestCase(Dist, DureeJeu, Tableau); + TestTile(Dist, GameDuration, Level); - // Test si doit Réduire le wagon - if (Reduce > DureeJeu) { + // Check if Locomotive should shrink + if (Reduce > GameDuration) { if (Pref.WagonGap > WAGON_GAP_MIN) { // Si doit réduire - Pref.WagonGap -= (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon - 1)) / 1000.0; + Pref.WagonGap -= (float)(Duration) * (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.WagonGap < WAGON_GAP_AVERAGE) { // Si doit ralonger le wagon - Pref.WagonGap += (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon)) / 1000.0; + else { // If time passed + if (Pref.WagonGap < WAGON_GAP_AVERAGE) { // If locomotive must be Expanded + Pref.WagonGap += (float)(Duration) * (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 (Extend > DureeJeu) { - if (Pref.WagonGap < WAGON_GAP_MAX) { // Si doit Ralonger - Pref.WagonGap += (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon)) / 1000.0; + // Check if locomotive must be expanded + if (Extend > GameDuration) { + if (Pref.WagonGap < WAGON_GAP_MAX) { // If locomotive must be Expanded + Pref.WagonGap += (float)(Duration) * (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.WagonGap > WAGON_GAP_AVERAGE) { // Si doit ralonger le wagon - Pref.WagonGap -= (float)(Duree) * (Pref.SpeedAverage * 0.8 / (float)(NWagon - 1)) / 1000.0; + else { // If time passed + if (Pref.WagonGap > WAGON_GAP_AVERAGE) { // If locomotive must be Expanded + Pref.WagonGap -= (float)(Duration) * (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 (Speed > DureeJeu) { - if (Pref.SpeedAverage < Pref.Speed * 2) { // Si doit accelerer - Pref.SpeedAverage += (float)(Duree) / 40.0; + // Check if locomotive speed must change + if (Speed > GameDuration) { + if (Pref.SpeedAverage < Pref.Speed * 2) { // if must accelerate + Pref.SpeedAverage += (float)(Duration) / 40.0; if (Pref.SpeedAverage > Pref.Speed * 2) { Pref.SpeedAverage = Pref.Speed * 2; } } } else { - if (Pref.SpeedAverage > Pref.Speed) { // Si doit ralentir - Pref.SpeedAverage -= (float)(Duree) / 40.0; + if (Pref.SpeedAverage > Pref.Speed) { // if must slow down + Pref.SpeedAverage -= (float)(Duration) / 40.0; if (Pref.SpeedAverage < Pref.Speed) { Pref.SpeedAverage = Pref.Speed; } } } - // Tand que dépasse la case en distante - while (D + Dist > T[PLoco].D) { - Dist -= T[PLoco].D - D; // Enleve la distance restant à parcourir - D = T[PLoco].D; + // While distant tile isn't reached + while (D + Dist > T[LocoPos].D) { + Dist -= T[LocoPos].D - D; // Substract the remaining distance + D = T[LocoPos].D; - i = 0; // Cherche la direction possible - while (TestDir(Touche[i], Tableau) == false) { + i = 0; // Search possible directions + while (TestDir(Key[i], Level) == false) { i++; } - Go(Touche[i]); // Fait avancer le loco suivant le désir du joueur + Go(Key[i]); // Locomotive advances in the player's wanted direction - DoFleche(Tableau, Touche); // Recherche la position de la futur intersection + FindArrow(Level, Key); // Search the position of the next intersection - TestCase(Dist, DureeJeu, Tableau); // Test la case au cas ou le jeu est vraiment lent + TestTile(Dist, GameDuration, Level); // Checks the tile for an item in case the game was really slow } - D += Dist; // Met à la bonne position finale + D += Dist; // Add distance to total distance - if (PInter == -1) { - DoFleche(Tableau, Touche); + if (IntersectPos == -1) { + FindArrow(Level, Key); } } -/*** Recherche la position de la futur intersection ***/ -/******************************************************/ -void Loco::DoFleche(int *Tableau, int *Touche) +/*** Search the position of the next intersection ***/ +/****************************************************/ +void Loco::FindArrow(int *Level, int *Key) { - int Sortie = T[PLoco].Sortie; + int Exit = T[LocoPos].Exit; int MemoS; - int NVoie; - int x, y, Tou; + int NTracks; + int x, y, Keypress; int i = 0; - if (T[PLoco].P != PInter && PInter != -1) { - return; // Si pas encore arrivé sur la case de croisement + if (T[LocoPos].P != IntersectPos && IntersectPos != -1) { + return; // If the crossing tile wasn't reached yet } - PInter = T[PLoco].P; // Prend la position de la loco + IntersectPos = T[LocoPos].P; // Store the locomotive position do { - // Vas à la nouvelle case - switch (Sortie) { + // Goes to the next tile + switch (Exit) { case D_Top: - PInter -= LT; - PEntree = D_Bottom; + IntersectPos -= LT; + EntryPos = D_Bottom; break; case D_Left: - PInter--; - PEntree = D_Right; + IntersectPos--; + EntryPos = D_Right; break; case D_Bottom: - PInter += LT; - PEntree = D_Top; + IntersectPos += LT; + EntryPos = D_Top; break; case D_Right: - PInter++; - PEntree = D_Left; + IntersectPos++; + EntryPos = D_Left; break; } - // Compte les voies disponibles. - MemoS = Sortie; - x = PInter % LT; - y = PInter / LT; - NVoie = 0; - if (y > 0 && PEntree != D_Top && Tableau[PInter - LT] != 0) { - Sortie = D_Top; - NVoie++; + // Counts the different possible tracks + MemoS = Exit; + x = IntersectPos % LT; + y = IntersectPos / LT; + NTracks = 0; + if (y > 0 && EntryPos != D_Top && Level[IntersectPos - LT] != 0) { + Exit = D_Top; + NTracks++; } - if (y + 1 < HT && PEntree != D_Bottom && Tableau[PInter + LT] != 0) { - Sortie = D_Bottom; - NVoie++; + if (y + 1 < HT && EntryPos != D_Bottom && Level[IntersectPos + LT] != 0) { + Exit = D_Bottom; + NTracks++; } - if (x > 0 && PEntree != D_Left && Tableau[PInter - 1] != 0) { - Sortie = D_Left; - NVoie++; + if (x > 0 && EntryPos != D_Left && Level[IntersectPos - 1] != 0) { + Exit = D_Left; + NTracks++; } - if (x + 1 < LT && PEntree != D_Right && Tableau[PInter + 1] != 0) { - Sortie = D_Right; - NVoie++; + if (x + 1 < LT && EntryPos != D_Right && Level[IntersectPos + 1] != 0) { + Exit = D_Right; + NTracks++; } - } while (NVoie == 1); + } while (NTracks == 1); - // Prend la direction de sortie comme direction par defaut - while (Touche[i] != MemoS) { + // Set the exit direction as default direction + while (Key[i] != MemoS) { i++; } - if (i > 0 && !MasqueK) { // Prend la direction de la loco comme direction par defaut - Tou = Touche[i]; + if (i > 0 && !MaskK) { // Set the locomotive's direction as default direction + Keypress = Key[i]; while (i) { - Touche[i] = Touche[i - 1]; + Key[i] = Key[i - 1]; i--; } - Touche[0] = Tou; // Mémorise la touche + Key[0] = Keypress; // Store key/dir } } -/*** Test si une direction est possible ***/ -/******************************************/ -bool Loco::TestDir(int FDir, int *Tableau) +/*** Check if a direction/turn is possible ***/ +/*********************************************/ +bool Loco::TestDir(int FDir, int *Level) { - int PAvant = T[PLoco].P; + int PosBefore = T[LocoPos].P; int x, y; - // Test si les directions ne sont pas opposées - if (T[PLoco].Sortie == D_Top && FDir == D_Bottom) { + // Checks if directions aren't opposites + if (T[LocoPos].Exit == D_Top && FDir == D_Bottom) { return false; } - if (T[PLoco].Sortie == D_Bottom && FDir == D_Top) { + if (T[LocoPos].Exit == D_Bottom && FDir == D_Top) { return false; } - if (T[PLoco].Sortie == D_Left && FDir == D_Right) { + if (T[LocoPos].Exit == D_Left && FDir == D_Right) { return false; } - if (T[PLoco].Sortie == D_Right && FDir == D_Left) { + if (T[LocoPos].Exit == D_Right && FDir == D_Left) { return false; } - PAvant += AddDir[(T[PLoco].Sortie)]; // Position dans virage + PosBefore += AddDir[(T[LocoPos].Exit)]; // Position in turns - // Test si un bord - x = PAvant % LT; - y = PAvant / LT; + // Check if there's a border + x = PosBefore % LT; + y = PosBefore / LT; if (FDir == D_Top && y == 0) { return false; } @@ -519,98 +519,98 @@ bool Loco::TestDir(int FDir, int *Tableau) return false; } - PAvant += AddDir[FDir]; // Position futur + PosBefore += AddDir[FDir]; // Set as future position - if (Tableau[PAvant] == 0) { - return false; // Test si il y a un rail + if (Level[PosBefore] == 0) { + return false; // Check if there's a rail } return true; } -/*** Deplace la locomotive ***/ -/*****************************/ -bool Loco::Go(int FuturDir) +/*** Move the locomotive ***/ +/***************************/ +bool Loco::Go(int FutureDir) { - int PTab = T[PLoco].P; - int const Dir = T[PLoco].Sortie; + int PTab = T[LocoPos].P; + int const Dir = T[LocoPos].Exit; int Mask; int i; - // Test si risque de dépassement et enleve une bonne partie - if (PLoco == 255) { + // Test if there's a risk of exceeding track + if (LocoPos == 255) { for (i = 0; i < 256 - 50; i++) { T[i].P = T[i + 50].P; T[i].D = T[i + 50].D; T[i].Arrive = T[i + 50].Arrive; - T[i].Sortie = T[i + 50].Sortie; + T[i].Exit = T[i + 50].Exit; } - PLoco -= 50; + LocoPos -= 50; } - // Mémorise la prochaine case - PLoco++; // Passe à la case suivante + // Store next tile + LocoPos++; // Move to next tile switch (Dir) { case D_Top: PTab -= LT; - T[PLoco].Arrive = D_Bottom; + T[LocoPos].Arrive = D_Bottom; break; case D_Bottom: PTab += LT; - T[PLoco].Arrive = D_Top; + T[LocoPos].Arrive = D_Top; break; case D_Left: PTab--; - T[PLoco].Arrive = D_Right; + T[LocoPos].Arrive = D_Right; break; default: PTab++; - T[PLoco].Arrive = D_Left; + T[LocoPos].Arrive = D_Left; } - // Donne futur direction et N° case avant - T[PLoco].P = PTab; - T[PLoco].Sortie = FuturDir; + // Gives future direction and the number of the tile before + T[LocoPos].P = PTab; + T[LocoPos].Exit = FutureDir; - // Calcule la distance - Mask = T[PLoco].Arrive * 4 + T[PLoco].Sortie; + // Calculates the distance + Mask = T[LocoPos].Arrive * 4 + T[LocoPos].Exit; switch (Mask) { - case (D_Left * 4 + D_Right): // Si vas tous droit + case (D_Left * 4 + D_Right): // if going straight forward case (D_Right * 4 + D_Left): case (D_Top * 4 + D_Bottom): case (D_Bottom * 4 + D_Top): - T[PLoco].D = T[PLoco - 1].D + D_Case; + T[LocoPos].D = T[LocoPos - 1].D + D_Case; break; default: - T[PLoco].D = T[PLoco - 1].D + D_CaseR; + T[LocoPos].D = T[LocoPos - 1].D + D_CaseR; return true; } return false; } -/*** Recherche un point sur le parcour ***/ -/*****************************************/ +/*** Searching a point on the map ***/ +/************************************/ void Loco::FindPoint(float Dist, int &x, int &y) { - int NP = PLoco; + int NP = LocoPos; int P; float D_Rest; - // Recherche la case d'avant + // Find the previous tile while (T[NP - 1].D > Dist) { NP--; } P = T[NP].P; - // Calcule les coordonnée suivant la direction + // Calculate coordinates following the direction D_Rest = T[NP].D - Dist; if (D_Rest == 0) { - D_Rest = D_Case / 1000.0; // Evite les erreurs de division + D_Rest = D_Case / 1000.0; // Avoid problems with divisons } - switch (T[NP].Arrive * 4 + T[NP].Sortie) { + switch (T[NP].Arrive * 4 + T[NP].Exit) { case (D_Left * 4 + D_Right): y = int(P / LT * D_Case + D_Case / 2); x = int(P % LT * D_Case + D_Case - D_Rest); @@ -665,13 +665,13 @@ void Loco::FindPoint(float Dist, int &x, int &y) } } -/*** Ajoute une loco au azrard ***/ -/*********************************/ +/*** Adds a random car sprite to the locomotive ***/ +/**************************************************/ void Loco::AddLoco() { - 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] = (e_Sprite)(rand() % (car - logs_wagon) + logs_wagon); + if (Wagon[NWagon] == Wagon[NWagon - 1]) { // Avoids adding the same sprite twice + if (Wagon[NWagon] + 1 == car) { Wagon[NWagon] = logs_wagon; } else { diff --git a/src/loco.h b/src/loco.h index 302a78e..51af95a 100644 --- a/src/loco.h +++ b/src/loco.h @@ -29,61 +29,61 @@ class Screen; class Audio; -/*** Definition de la classe qui mémorise les cases ***/ -/******************************************************/ +/*** Structs to store tile positions ***/ +/***************************************/ struct s_TLoco { - int P; // Pointe sur le N° de la case - float D; // Distance parcoure (case comprie) - unsigned char Arrive, Sortie; // Direction d'arrivée et de sortie + int P; // Tile index + float D; // Distance traveled + unsigned char Arrive, Exit; // Arrival and Exit directions }; struct s_PosWagon -{ // Mémorise la position avant et arrière des wagons pour le test de colision +{ // Stores positions in front and behind the locomotives for collision checks int dx, dy; int fx, fy; - float SprStart; // Si fini sa sequence d'affiche de départ + float SprStart; // if start display sequence is finished }; #define N_SPR_START 50 -/*** Définition de la class ***/ -/******************************/ +/*** Locomotive class definition ***/ +/***********************************/ class Loco { public: explicit Loco(Audio &audio); ~Loco() = default; - /*** Fonctions ***/ - void Init(int Pos, int Direction); // Initialise la loco sur le tableau - void Display(Screen &Ec); // Fait l'affichage de la loco. - void TestCase(float Dist, long DureeJeu, int *Tableau); // Test les options sur la case si passe au centre - void Avance(int Dureems, long DureeJeu, int *Touche, int *Tableau); // Fait avancer la locomotive - void DoFleche(int *Tableau, int *Touche); // Recherche la position de la futur intersection - bool TestDir(int FDir, int *Tableau); // Test si une direction est possible - void AddLoco(); // Ajoute une loco au azard + /*** Functions ***/ + void Init(int Pos, int Direction); // Initialize locomotive + void Display(Screen &screen); // Display the locomotive + void TestTile(float Dist, long GameDuration, int *Level); // Checking for items/options on a tile + void MoveForward(int Duration, long GameDuration, int *Key, int *Level); // Makes locomotive move forward for Duration in ms + void FindArrow(int *Level, int *Key); // Search the position of the next intersection + bool TestDir(int FDir, int *Level); // Check if a direction/turn is possible + void AddLoco(); // Adds a random car to the locomotive - /*** Fonctions privées ***/ - inline bool Go(int FuturDirection); // Fait avancer le tableau (retourne true si tourne) - inline void FindPoint(float Dist, int &x, int &y); // Retourne la position d'un point sur le parcour + /*** Private Functions ***/ + inline bool Go(int FutureDirection); // Move the locomotive + inline void FindPoint(float Dist, int &x, int &y); // Searching a point on the map - int Mort; // Mémorise l'heure + duree pour faire une pause aprés avoir touché un wagon - bool Gagne; // Si a fini le niveau - int PEntree; // Entrée le la loco sur une case pour la fleche - int PInter; // Position de la futur intersection pour afficher la fleche + int Dead; // Stores current time + duration for a pause after losing game + bool Win; // If we finished a level + int EntryPos; // Entry position of the locomotive on a tile for arrows + int IntersectPos; // Position of the incoming intersection to display the arrow at private: /*** Variables ***/ - 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 - int NWagon; // Mémorise le nombre de wagon - e_Sprite Wagon[256]; // Mémorise les wagons - struct s_PosWagon PosWagon[256]; // Mémorise position des wagons à l'écran pour test de colision - float MemoDuree; // Memorise la precedente durée pour faire avancer les explosions du depart + long Reduce, Extend, Speed; // Stores the end clock to decide shrinking or expanding + int LocoPos; // Locomotive's head position in the level + float D; // Distance traveled by the locomotive + struct s_TLoco T[256]; // Stores the route traveled by the locomotive, up to 256 tiles + int NWagon; // Stores the number of wagons + e_Sprite Wagon[256]; // Stores the wagons + struct s_PosWagon PosWagon[256]; // Store wagon positions to check for collisions + float MemoDuration; // Stores old duration to make start explosions move Audio &m_audio; }; -#endif +#endif \ No newline at end of file diff --git a/src/main.cc b/src/main.cc index 054bc14..647156d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -55,7 +55,7 @@ char Titre[] = "Li-ri V" VERSION; Sprite *Sprites = nullptr; // Sprites pointer int NSprites = 0; // Number of sprites in memory -Screen Ec; // 2 Video buffer pointer +Screen screen; // 2 Video buffer pointer sNewPreference Pref; // Preference table. Level level; diff --git a/src/menu.cc b/src/menu.cc index 446491c..07c4b31 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -56,14 +56,14 @@ extern int previousTime; extern SDL_Window *sdlWindow; extern SDL_Renderer *sdlRenderer; extern Sprite *Sprites; -extern Screen Ec; +extern Screen screen; extern sNewPreference Pref; static char Points[] = ". . . . . . . . . . . . . ."; static struct mPy Menu_Py[20]; -/*** Fait une attente pour 50fps ***/ -/***********************************/ +/*** Sleeping for 50fps ***/ +/**************************/ void Sleeping() { int delay; @@ -75,22 +75,22 @@ void Sleeping() } } -/*** Ajoute une entrée dans le tableau des boutons ***/ -/*****************************************************/ +/*** Add an button to the menu array ***/ +/***************************************/ void AddButton(int Num, e_Sprite NumSp, int X, int Y) { int const NumS = (int)NumSp; - Menu_Py[Num].DepX = X - Sprites[NumS].Dim[0].L / 2; - Menu_Py[Num].DepY = Y - Sprites[NumS].Dim[0].H / 2; - Menu_Py[Num].FinX = X + Sprites[NumS].Dim[0].L / 2; - Menu_Py[Num].FinY = Y + Sprites[NumS].Dim[0].H / 2; + Menu_Py[Num].StartX = X - Sprites[NumS].Dim[0].L / 2; + Menu_Py[Num].StartY = Y - Sprites[NumS].Dim[0].H / 2; + Menu_Py[Num].EndX = X + Sprites[NumS].Dim[0].L / 2; + Menu_Py[Num].EndY = Y + Sprites[NumS].Dim[0].H / 2; Menu_Py[Num].Py = Num; - Menu_Py[Num].Valide = true; + Menu_Py[Num].Valid = true; } -/*** Change le vidéo ***/ -/***********************/ +/*** Change Windowed/Fullscreen ***/ +/**********************************/ void ChangeVideo() { Uint32 flag = SDL_WINDOW_RESIZABLE; @@ -98,27 +98,27 @@ void ChangeVideo() flag = SDL_WINDOW_FULLSCREEN_DESKTOP; } SDL_SetWindowFullscreen(sdlWindow, flag); - SDL_ShowCursor(0); // Cache le curseur + SDL_ShowCursor(0); // Hide cursor } -/*** SDL Main Menu principale ***/ -/********************************/ +/*** SDL Main Menu ***/ +/*********************/ eMenu Menu::SDLMain() { int i; char MCode[5] = { 0, 0, 0, 0, 0 }; char key; - // Initialisations Divers - m_mouse.Init(Menu_Py); // Initialise la sourie + // Miscellaneous inits + m_mouse.Init(Menu_Py); // Mouse init PyE = 0; - // Prend les evenements + // Fetching events do { - Ec.CleanSpriteAndScreen(fmenu); + screen.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); - // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + // Get background image and build menu + Sprites[background_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]); @@ -131,7 +131,7 @@ eMenu Menu::SDLMain() 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; + Menu_Py[4].StartX = -1; SDL_Event event; while (SDL_PollEvent(&event)) { m_mouse.GetEvent(event, PyE); // Handle mouse @@ -139,7 +139,7 @@ eMenu Menu::SDLMain() switch (event.type) { case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -176,14 +176,14 @@ eMenu Menu::SDLMain() } break; default: - key = event.key.keysym.sym & 0x7F; // Prend le caracataire correspondant à la touche - if (CharExist(key) == true) { // Si la caractaire existe bien + key = event.key.keysym.sym & 0x7F; // Gets the character corresponding to the key + if (CharExist(key) == true) { // if character exists for (i = 2; i >= 0; i--) { - MCode[i + 1] = MCode[i]; // décale le code + MCode[i + 1] = MCode[i]; // shift code } MCode[0] = key; if (strcmp(MCode, "tide") == 0 || strcmp(MCode, "TIDE") == 0) { - return mEdit; // Si editeur de niveau + return mEdit; // If level editor selected } } } @@ -195,16 +195,16 @@ eMenu Menu::SDLMain() } } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - // Gère l'Affichage + // Handle display Print_Main(); m_mouse.Print(); - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -212,27 +212,27 @@ eMenu Menu::SDLMain() return mQuit; } -/*** SDL Main Menu Choix de la langue ***/ -/****************************************/ +/*** SDL Main Menu Language choice ***/ +/*************************************/ eMenu Menu::SDLMain_Language() { int NCol = 1; int NL; - int Ecart; + int Gap; int i; int x, y; - int const OldLangue = Pref.Language; + int const OldLanguage = Pref.Language; - // Initialisations Divers - m_mouse.Init(Menu_Py); // Initialise la sourie + // Miscellaneous inits + m_mouse.Init(Menu_Py); // Mouse init PyE = Pref.Language; if (PyE == -1) { PyE = 1; } SDL_RenderClear(sdlRenderer); - // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + // Set background image and build display + Sprites[background_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); // Draw available languages NCol = 3; @@ -242,31 +242,31 @@ eMenu Menu::SDLMain_Language() else { NL = Pref.NLanguages / NCol + 1; } - Ecart = 600 / (NL + 1); + Gap = 600 / (NL + 1); for (i = 0; i < Pref.NLanguages; i++) { x = (i / NL) * (800 / 3) + (800 / 6); - y = (i % NL) * Ecart + Ecart; + y = (i % NL) * Gap + Gap; - Sprites[T_Langue + i].Draw(x, y, 0, Sprites[fmenu].Image[0]); - AddButton(i, (e_Sprite)(T_Langue + i), x, y); + Sprites[T_Language + i].Draw(x, y, 0, Sprites[fmenu].Image[0]); + AddButton(i, (e_Sprite)(T_Language + i), x, y); } - Menu_Py[Pref.NLanguages].DepX = -1; + Menu_Py[Pref.NLanguages].StartX = -1; - // Efface le fond + // Erase background SDL_RenderPresent(sdlRenderer); - // Prend les evenements + // Fetch events do { SDL_RenderClear(sdlRenderer); - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + Sprites[background_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; + y = (i % NL) * Gap + Gap; - Sprites[T_Langue + i].Draw(x, y, 0, Sprites[fmenu].Image[0]); - AddButton(i, (e_Sprite)(T_Langue + i), x, y); + Sprites[T_Language + i].Draw(x, y, 0, Sprites[fmenu].Image[0]); + AddButton(i, (e_Sprite)(T_Language + i), x, y); } SDL_Event event; @@ -282,7 +282,7 @@ eMenu Menu::SDLMain_Language() break; case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -321,7 +321,7 @@ eMenu Menu::SDLMain_Language() case SDLK_RETURN: case SDLK_KP_ENTER: Pref.Language = PyE; - if (Pref.Language != OldLangue) { + if (Pref.Language != OldLanguage) { LoadLanguage(); } return mMenu; @@ -336,17 +336,17 @@ eMenu Menu::SDLMain_Language() } } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - // Gère l'Affichage - Affiche_Main_Centre(); + // Handle display + Center_Arrows(); m_mouse.Print(); - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -354,16 +354,16 @@ eMenu Menu::SDLMain_Language() return mQuit; } -/*** SDL Main Menu Choix des Options ***/ -/***************************************/ +/*** SDL Main Menu Settings ***/ +/******************************/ void Menu::InitMain_Options() { - // Initialisations Divers - m_mouse.Init(Menu_Py); // Initialise la sourie + // Miscellaneous inits + m_mouse.Init(Menu_Py); // Mouse init // PyE=4; - // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + // Set background image and build display + Sprites[background_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]); @@ -371,56 +371,56 @@ void Menu::InitMain_Options() AddButton(1, music, 160, 200); AddButton(2, fscreen, 190, 300); - Menu_Py[2].DepX -= 40; - Menu_Py[2].FinX = 625 + 40 + Sprites[fscreen].Dim[0].L / 2; + Menu_Py[2].StartX -= 40; + Menu_Py[2].EndX = 625 + 40 + Sprites[fscreen].Dim[0].L / 2; Sprites[fscreen].Draw(185, 300, 0, Sprites[fmenu].Image[0]); Sprites[window].Draw(625, 300, 0, Sprites[fmenu].Image[0]); AddButton(3, earth, 180, 400); - // Centre à gauche le text de menu - CentreM = 120 + Sprites[T_menu].Dim[0].L / 2; - DrawText(CentreM, 490, T_menu, Sprites[fmenu].Image[0]); - AddButton(4, T_menu, CentreM, 490); + // Center text left + CenterM = 120 + Sprites[T_menu].Dim[0].L / 2; + DrawText(CenterM, 490, T_menu, Sprites[fmenu].Image[0]); + AddButton(4, T_menu, CenterM, 490); - // Boutons des sounds + // Sound buttons 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; - Menu_Py[5].FinY = 145; + Menu_Py[5].StartX = 230; + Menu_Py[5].StartY = 70; + Menu_Py[5].EndX = 475; + Menu_Py[5].EndY = 145; Menu_Py[5].Py = 5; - Menu_Py[5].Valide = true; + Menu_Py[5].Valid = true; - Menu_Py[6].DepX = 476; - Menu_Py[6].DepY = 70; - Menu_Py[6].FinX = 720; - Menu_Py[6].FinY = 145; + Menu_Py[6].StartX = 476; + Menu_Py[6].StartY = 70; + Menu_Py[6].EndX = 720; + Menu_Py[6].EndY = 145; Menu_Py[6].Py = 6; - Menu_Py[6].Valide = true; + Menu_Py[6].Valid = true; - // Boutons de musics + // Music buttons 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; - Menu_Py[7].FinY = 245; + Menu_Py[7].StartX = 230; + Menu_Py[7].StartY = 155; + Menu_Py[7].EndX = 475; + Menu_Py[7].EndY = 245; Menu_Py[7].Py = 7; - Menu_Py[7].Valide = true; + Menu_Py[7].Valid = true; - Menu_Py[8].DepX = 476; - Menu_Py[8].DepY = 155; - Menu_Py[8].FinX = 720; - Menu_Py[8].FinY = 245; + Menu_Py[8].StartX = 476; + Menu_Py[8].StartY = 155; + Menu_Py[8].EndX = 720; + Menu_Py[8].EndY = 245; Menu_Py[8].Py = 8; - Menu_Py[8].Valide = true; + Menu_Py[8].Valid = true; - Menu_Py[9].DepX = -1; + Menu_Py[9].StartX = -1; } -/*** Gestion du menu Options ***/ +/*** Options menu management ***/ /*******************************/ eMenu Menu::SDLMain_Options() { @@ -428,11 +428,11 @@ eMenu Menu::SDLMain_Options() int NumSp; PyE = 4; - // Prend les evenements + // Fetch events do { - Ec.CleanSpriteAndScreen(fmenu); + screen.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); - InitMain_Options(); // Prépare le menu + InitMain_Options(); // Prepare menu SDL_Event event; while (SDL_PollEvent(&event)) { m_mouse.GetEvent(event, PyE); // Handle mouse @@ -446,7 +446,7 @@ eMenu Menu::SDLMain_Options() break; case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -461,7 +461,7 @@ eMenu Menu::SDLMain_Options() } break; case 0: - case 5: // Diminue volume sons + case 5: // Lowers sound effects volume case 6: Pref.Volume -= SDL_MIX_MAXVOLUME / 10.0; if (Pref.Volume < 0) { @@ -471,7 +471,7 @@ eMenu Menu::SDLMain_Options() m_audio.Play(sLive); break; case 1: - case 7: // Diminue volume music + case 7: // Lowers music volume case 8: Pref.VolumeM -= SDL_MIX_MAXVOLUME / 10.0; if (Pref.VolumeM < 0) { @@ -535,16 +535,16 @@ eMenu Menu::SDLMain_Options() case 0: case 1: break; - case 2: // Type d'affichage + case 2: // Display type Pref.FullScreen = (Pref.FullScreen + 1) & 1; ChangeVideo(); PyE = 2; break; - case 3: // Choix de la langue + case 3: // Language choice SDLMain_Language(); PyE = 3; break; - case 5: // Diminue volume sons + case 5: // Lower sound effects volume Pref.Volume -= SDL_MIX_MAXVOLUME / 10.0; if (Pref.Volume < 0) { Pref.Volume = 0; @@ -560,7 +560,7 @@ eMenu Menu::SDLMain_Options() m_audio.DoVolume(); m_audio.Play(sLive); break; - case 7: // Diminue volume music + case 7: // Lower music volume Pref.VolumeM -= SDL_MIX_MAXVOLUME / 10.0; if (Pref.VolumeM < 0) { Pref.VolumeM = 0; @@ -589,48 +589,48 @@ eMenu Menu::SDLMain_Options() } // SDL_RenderClear(sdlRenderer); - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - // Gère l'Affichage - // Ec.Efface(fmenu); + // Handle Display + // Ec.Efface(fmenu); (Ec replaced with screen) if (Pref.FullScreen) { - Ec.PrintSprite(arrows, 1, 350, 300); - Ec.PrintSprite(arrows, 3, 450, 300); + screen.PrintSprite(arrows, 1, 350, 300); + screen.PrintSprite(arrows, 3, 450, 300); } else { - Ec.PrintSprite(arrows, 0, 350, 300); - Ec.PrintSprite(arrows, 4, 450, 300); + screen.PrintSprite(arrows, 0, 350, 300); + screen.PrintSprite(arrows, 4, 450, 300); } NumSp = (currentTime / 30) % 25; - Ec.PrintSprite(sound, NumSp, 150, 110); + screen.PrintSprite(sound, NumSp, 150, 110); NumSp = (currentTime / 30) % 25; - Ec.PrintSprite(music, NumSp, 150, 200); + screen.PrintSprite(music, NumSp, 150, 200); NumSp = (currentTime / 50) % 50; - Ec.PrintSprite(earth, NumSp, 180, 400); + screen.PrintSprite(earth, NumSp, 180, 400); N = (int)(Pref.Volume * 10 + 1) / SDL_MIX_MAXVOLUME; 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); + screen.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 110); } else { - Ec.PrintSprite(logs_wagon, NumSp, (690 - 300) / 10 * i + 300, 110); + screen.PrintSprite(logs_wagon, NumSp, (690 - 300) / 10 * i + 300, 110); } } N = (int)(Pref.VolumeM * 10 + 1) / SDL_MIX_MAXVOLUME; for (i = 0; i < N; i++) { if (i == N - 1) { - Ec.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 200); + screen.PrintSprite(locomotive, NumSp, (690 - 300) / 10 * i + 300, 200); } else { - Ec.PrintSprite(logs_wagon, NumSp, (690 - 300) / 10 * i + 300, 200); + screen.PrintSprite(logs_wagon, NumSp, (690 - 300) / 10 * i + 300, 200); } } @@ -639,7 +639,7 @@ eMenu Menu::SDLMain_Options() Print_Main(180); break; case 4: - Print_Main(CentreM); + Print_Main(CenterM); break; case 5: PyE = 0; @@ -667,7 +667,7 @@ eMenu Menu::SDLMain_Options() m_mouse.Print(); - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -675,20 +675,20 @@ eMenu Menu::SDLMain_Options() return mQuit; } -/*** SDL Main Menu Choix de la difficulté ***/ -/********************************************/ +/*** SDL Main Menu difficulty choice ***/ +/***************************************/ eMenu Menu::SDLMain_Speed() { - // Initialisations Divers - m_mouse.Init(Menu_Py); // Initialise la sourie + // Miscellaneous inits + m_mouse.Init(Menu_Py); // Mouse init PyE = 1; - // Prend les evenements + // Fetch events do { - Ec.CleanSpriteAndScreen(fmenu); + screen.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); - // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + // Set background image and build display + Sprites[background_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]); @@ -698,7 +698,7 @@ eMenu Menu::SDLMain_Speed() 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; + Menu_Py[3].StartX = -1; SDL_Event event; while (SDL_PollEvent(&event)) { @@ -713,7 +713,7 @@ eMenu Menu::SDLMain_Speed() break; case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -761,16 +761,16 @@ eMenu Menu::SDLMain_Speed() } } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - // Gère l'Affichage + // Handle display Print_Main(); m_mouse.Print(); - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -778,23 +778,23 @@ eMenu Menu::SDLMain_Speed() return mQuit; } -/*** SDL Main Menu Choix du niveau ***/ -/*************************************/ +/*** SDL Main Menu Level choice ***/ +/**********************************/ eMenu Menu::SDLMain_Level() { - // Initialisations Divers - m_mouse.Init(Menu_Py); // Initialise la sourie + // Miscellaneous inits + m_mouse.Init(Menu_Py); // Mouse init PyE = 0; - Niv = Pref.LevelMax[Pref.Difficulty]; + Level = Pref.LevelMax[Pref.Difficulty]; Pref.Level = 0; - // Prend les evenements + // Fetch events do { - // Efface le fond - Ec.CleanSpriteAndScreen(fmenu); + // Erase background + screen.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); - // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + // Set background image and build display + Sprites[background_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]); @@ -808,7 +808,7 @@ eMenu Menu::SDLMain_Level() AddButton(3, arrows, 330, 380); AddButton(4, arrows, 470, 380); - Menu_Py[5].DepX = -1; + Menu_Py[5].StartX = -1; SDL_Event event; while (SDL_PollEvent(&event)) { @@ -823,7 +823,7 @@ eMenu Menu::SDLMain_Level() break; case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -841,14 +841,14 @@ eMenu Menu::SDLMain_Level() } break; case SDLK_LEFT: - if (Niv > 0) { - Niv--; + if (Level > 0) { + Level--; } PyE = 1; break; case SDLK_RIGHT: - if (Niv < Pref.LevelMax[Pref.Difficulty]) { - Niv++; + if (Level < Pref.LevelMax[Pref.Difficulty]) { + Level++; } PyE = 1; break; @@ -864,18 +864,18 @@ eMenu Menu::SDLMain_Level() case 0: return mGame; case 1: - Pref.Level = Niv; + Pref.Level = Level; return mGame; case 2: return mMenu; case 3: - if (Niv > 0) { - Niv--; + if (Level > 0) { + Level--; } break; case 4: - if (Niv < Pref.LevelMax[Pref.Difficulty]) { - Niv++; + if (Level < Pref.LevelMax[Pref.Difficulty]) { + Level++; } break; } @@ -891,44 +891,44 @@ eMenu Menu::SDLMain_Level() } } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); // Draw arrows - if (Niv > 0) { + if (Level > 0) { if (PyE == 3) { - Ec.PrintSprite(arrows, 2, 330, 380); + screen.PrintSprite(arrows, 2, 330, 380); } else { - Ec.PrintSprite(arrows, 1, 330, 380); + screen.PrintSprite(arrows, 1, 330, 380); } } else { - Ec.PrintSprite(arrows, 0, 330, 380); + screen.PrintSprite(arrows, 0, 330, 380); } - if (Niv < Pref.LevelMax[Pref.Difficulty]) { + if (Level < Pref.LevelMax[Pref.Difficulty]) { if (PyE == 4) { - Ec.PrintSprite(arrows, 5, 470, 380); + screen.PrintSprite(arrows, 5, 470, 380); } else { - Ec.PrintSprite(arrows, 4, 470, 380); + screen.PrintSprite(arrows, 4, 470, 380); } } else { - Ec.PrintSprite(arrows, 3, 470, 380); + screen.PrintSprite(arrows, 3, 470, 380); } - DrawNumber(400, 380, Niv + 1); + DrawNumber(400, 380, Level + 1); if (PyE != 3 && PyE != 4) { Print_Main(); } m_mouse.Print(); - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -936,34 +936,34 @@ eMenu Menu::SDLMain_Level() return mQuit; } -/*** SDL Main questions sur les droits de l'homme ***/ -/****************************************************/ +/*** SDL Main questions on human rights ***/ +/******************************************/ #ifndef DCHILDREN eMenu Menu::SDLMain_HR() { - int Fini = -1; - int N1, N2, Ordre; + int Done = -1; + int N1, N2, Order; SDL_Rect Position; // InitialisationsDivers m_mouse.Init(Menu_Py); // Initialise la sourie PyE = rand() % 2; - // Choix de la question N1=reponse + // Question choice, N1=answer N1 = rand() % 30; do { N2 = rand() % 30; } while (N2 == N1); - Ordre = rand() % 2; // Si 0=bonne ordre, 1=inverse + Order = rand() % 2; // if 0=right order, 1=inverted - // Prend l'image du fond et fait l'affichage + // Set background image and build display Position.x = Position.y = 0; Position.w = Sprites[fmenu].Dim[0].L; Position.h = Sprites[fmenu].Dim[0].H; SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); Sprites[menu].Draw(340, 300, 0, Sprites[fmenu].Image[0]); - Sprites[fond_hr].Draw(340, 74, 0, Sprites[fmenu].Image[0]); + Sprites[background_hr].Draw(340, 74, 0, Sprites[fmenu].Image[0]); DrawText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); Sprites[locomotive].Draw(115, 110, rand() % 320, Sprites[fmenu].Image[0]); @@ -974,7 +974,7 @@ eMenu Menu::SDLMain_HR() DrawText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); - if (Ordre) { + if (Order) { AddButton(0, e_Sprite(T_tart1 + N1), 240, 492); AddButton(1, e_Sprite(T_tart1 + N2), 440, 492); } @@ -982,26 +982,26 @@ eMenu Menu::SDLMain_HR() 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; - Menu_Py[1].DepY -= 20; - Menu_Py[1].FinY += 20; + Menu_Py[0].StartY -= 20; + Menu_Py[0].EndY += 20; + Menu_Py[1].StartY -= 20; + Menu_Py[1].EndY += 20; - Menu_Py[2].DepX = -1; + Menu_Py[2].StartX = -1; std::array, 4> posDeco = { std::make_pair(rand() % 130, rand() % 18), std::make_pair(rand() % 130, rand() % 18), std::make_pair(rand() % 130, rand() % 18), std::make_pair(rand() % 130, rand() % 18) }; int const locoPosition = rand() % 320; - // Prend les evenements + // Fetch events do { - // Efface le fond + // Erase background SDL_RenderClear(sdlRenderer); SDL_RenderCopy(sdlRenderer, Sprites[fmenu].Image[0], &Position, &Position); - // Sprites[fond].Draw(400,300,0,Sprites[fjeu].Image[0]); + // Sprites[Background].Draw(400,300,0,Sprites[fgame].Image[0]); Sprites[menu].Draw(340, 300, 0, Sprites[fmenu].Image[0]); - Sprites[fond_hr].Draw(340, 74, 0, Sprites[fmenu].Image[0]); + Sprites[background_hr].Draw(340, 74, 0, Sprites[fmenu].Image[0]); DrawText(338, 70, e_Sprite(T_question), Sprites[fmenu].Image[0]); Sprites[locomotive].Draw(115, 110, locoPosition, Sprites[fmenu].Image[0]); @@ -1012,7 +1012,7 @@ eMenu Menu::SDLMain_HR() DrawText(340, 300, e_Sprite(T_art1 + N1), Sprites[fmenu].Image[0]); /* - if(Ordre) { + if(Order) { AddButton(0,e_Sprite(T_tart1+N1),240,492); AddButton(1,e_Sprite(T_tart1+N2),440,492); } @@ -1020,12 +1020,12 @@ eMenu Menu::SDLMain_HR() 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; - Menu_Py[1].DepY-=20; - Menu_Py[1].FinY+=20; + Menu_Py[0].StartX-=20; + Menu_Py[0].EndX+=20; + Menu_Py[1].StartY-=20; + Menu_Py[1].EndY+=20; - Menu_Py[2].DepX=-1; + Menu_Py[2].StartX=-1; */ SDL_Event event; while (SDL_PollEvent(&event)) { @@ -1038,8 +1038,8 @@ eMenu Menu::SDLMain_HR() } break; case SDL_KEYDOWN: - if (Fini == -1 && event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + if (Done == -1 && event.key.state == SDL_PRESSED) { + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -1057,7 +1057,7 @@ eMenu Menu::SDLMain_HR() } break; case SDLK_LEFT: - if (Ordre) { + if (Order) { PyE = 0; } else { @@ -1065,7 +1065,7 @@ eMenu Menu::SDLMain_HR() } break; case SDLK_RIGHT: - if (Ordre) { + if (Order) { PyE = 1; } else { @@ -1084,11 +1084,11 @@ eMenu Menu::SDLMain_HR() case 0: m_audio.Play(sEnd); Pref.Score += 50; - Fini = currentTime + 2000; + Done = currentTime + 2000; break; case 1: m_audio.Play(sLose); - Fini = currentTime + 2000; + Done = currentTime + 2000; break; } break; @@ -1103,28 +1103,28 @@ eMenu Menu::SDLMain_HR() } } - // Test si fini - if (Fini != -1 && Fini < currentTime) { + // Test if finished + if (Done != -1 && Done < currentTime) { return mGame; } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - if (Ordre) { - Ec.PrintSprite(fond_hrr, 0, 240, 492); + if (Order) { + screen.PrintSprite(background_hrr, 0, 240, 492); DrawText(240, 492, e_Sprite(T_tart1 + N1)); } else { - Ec.PrintSprite(fond_hrr, 0, 440, 492); + screen.PrintSprite(background_hrr, 0, 440, 492); DrawText(440, 492, e_Sprite(T_tart1 + N1)); } - if (Fini == -1) { - if (Ordre) { - Ec.PrintSprite(fond_hrr, 0, 440, 492); + if (Done == -1) { + if (Order) { + screen.PrintSprite(background_hrr, 0, 440, 492); DrawText(440, 492, e_Sprite(T_tart1 + N2)); if (PyE == 0) { Print_Main(240); @@ -1134,7 +1134,7 @@ eMenu Menu::SDLMain_HR() } } else { - Ec.PrintSprite(fond_hrr, 0, 240, 492); + screen.PrintSprite(background_hrr, 0, 240, 492); DrawText(240, 492, e_Sprite(T_tart1 + N2)); if (PyE == 1) { Print_Main(240); @@ -1146,7 +1146,7 @@ eMenu Menu::SDLMain_HR() m_mouse.Print(); } - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -1155,17 +1155,17 @@ eMenu Menu::SDLMain_HR() } #endif -/*** SDL Main dans la partie ***/ -/*******************************/ +/*** SDL Main InGame ***/ +/***********************/ void Menu::Print_InGame() { SDL_Rect Position; - // InitialisationsDivers - m_mouse.Init(Menu_Py); // Initialise la sourie + // Miscellaneous inits + m_mouse.Init(Menu_Py); // Mouse init // PyE=0; - // Prend l'image du fond et fait l'affichage + // Set background image and build display Position.x = Position.y = 0; Position.w = Sprites[fmenu].Dim[0].L; Position.h = Sprites[fmenu].Dim[0].H; @@ -1179,18 +1179,18 @@ void Menu::Print_InGame() 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; + Menu_Py[3].StartX = -1; } -/*** Gestion du menu dans le jeu ***/ -/***********************************/ +/*** Managing menu InGame ***/ +/****************************/ eMenu Menu::SDLMain_InGame() { Print_InGame(); - // Prend les evenements + // Fetch events do { - Ec.CleanSpriteAndScreen(fmenu); + screen.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); SDL_Event event; while (SDL_PollEvent(&event)) { @@ -1206,7 +1206,7 @@ eMenu Menu::SDLMain_InGame() break; case SDL_KEYDOWN: if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); switch (event.key.keysym.sym) { case SDLK_ESCAPE: case SDLK_AC_BACK: // Android back button @@ -1253,17 +1253,17 @@ eMenu Menu::SDLMain_InGame() } } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); - // Gère l'Affichage + // Handle display Print_InGame(); Print_Main(340); m_mouse.Print(); - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -1271,8 +1271,8 @@ eMenu Menu::SDLMain_InGame() return mQuit; } -/*** SDL Main Menu Choix de la difficulté ***/ -/********************************************/ +/*** SDL Main Menu difficulty choice ***/ +/***************************************/ eMenu Menu::SDLMain_Score(bool EditScore) { int i; @@ -1281,7 +1281,7 @@ eMenu Menu::SDLMain_Score(bool EditScore) int PosCur = 0; char key; - // Cherche le numéro du score à remplacer si edition des scores + // Searches the score index to edit if (EditScore) { for (i = 7; i >= 0; i--) { if (Pref.Sco[i].Score < Pref.Score) { @@ -1292,39 +1292,39 @@ eMenu Menu::SDLMain_Score(bool EditScore) return mMenu; } - if (NEdit < 7) { // Si doit fair un décalage + if (NEdit < 7) { // if shifting must be done for (i = 7; i > NEdit; i--) { Pref.Sco[i].Score = Pref.Sco[i - 1].Score; strcpy(Pref.Sco[i].Name, Pref.Sco[i - 1].Name); } } - // Efface le nouveau nom et met le score + // Erase name and enter score Pref.Sco[NEdit].Score = Pref.Score; Pref.Sco[NEdit].Name[0] = 0; } - // Met la sourie sur tous l'ecran - m_mouse.Init(Menu_Py); // Initialise la sourie - Menu_Py[0].DepX = 0; - Menu_Py[0].DepY = 0; - Menu_Py[0].FinX = 800; - Menu_Py[0].FinY = 600; + // Sets mouse on entire display + m_mouse.Init(Menu_Py); // Mouse init + Menu_Py[0].StartX = 0; + Menu_Py[0].StartY = 0; + Menu_Py[0].EndX = 800; + Menu_Py[0].EndY = 600; Menu_Py[0].Py = 0; - Menu_Py[0].Valide = true; - Menu_Py[1].DepX = -1; + Menu_Py[0].Valid = true; + Menu_Py[1].StartX = -1; if (EditScore) { SDL_StartTextInput(); } - // Prend les evenements + // Fetch events do { - // Efface le fond - Ec.CleanSpriteAndScreen(fmenu); + // Erase background + screen.CleanSpriteAndScreen(fmenu); SDL_RenderClear(sdlRenderer); - // Prend l'image du fond et fait l'affichage - Sprites[fond_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); + // Set background image and build display + Sprites[background_menu].Draw(400, 300, 0, Sprites[fmenu].Image[0]); // Draw title and commands DrawText(400, 50, T_better_scores, Sprites[fmenu].Image[0]); @@ -1348,7 +1348,7 @@ eMenu Menu::SDLMain_Score(bool EditScore) DrawString(740 - StringLength(Provi), 120 + i * (360 / 7), Provi, Sprites[fmenu].Image[0]); } - // Efface le fond + // Erase background SDL_Event event; while (SDL_PollEvent(&event)) { m_mouse.GetEvent(event, PyE); // Handle mouse @@ -1360,9 +1360,9 @@ eMenu Menu::SDLMain_Score(bool EditScore) SDL_RenderPresent(sdlRenderer); } break; - case SDL_KEYDOWN: // Prend un touche au clavier + case SDL_KEYDOWN: // Waits a Keyboard press if (event.key.state == SDL_PRESSED) { - m_audio.Play(sClic); + m_audio.Play(sClick); if (EditScore == false && event.key.keysym.sym != SDLK_F12) { event.key.keysym.sym = SDLK_RETURN; } @@ -1372,14 +1372,14 @@ eMenu Menu::SDLMain_Score(bool EditScore) Utils::doScreenshot(sdlRenderer); } break; - case SDLK_ESCAPE: // Valide l'entrée + case SDLK_ESCAPE: // Validates entry case SDLK_RETURN: case SDLK_KP_ENTER: if (EditScore) { SDL_StopTextInput(); } return mMenu; - case SDLK_BACKSPACE: // Fait un retour de chariot + case SDLK_BACKSPACE: // Erases if (PosCur) { PosCur--; Pref.Sco[NEdit].Name[PosCur] = 0; @@ -1405,7 +1405,7 @@ eMenu Menu::SDLMain_Score(bool EditScore) } } - // Gère les variables + // Handle variables previousTime = currentTime; currentTime = SDL_GetTicks(); Sleeping(); @@ -1414,11 +1414,11 @@ eMenu Menu::SDLMain_Score(bool EditScore) DrawString(140, 120 + NEdit * (360 / 7), Pref.Sco[NEdit].Name); i = (currentTime / 50) % 20; // Draw cursors - 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)); + screen.PrintSprite(arrow_left, i, 110, 120 + NEdit * (360 / 7)); + screen.PrintSprite(arrow_right, i, 180 + StringLength(Pref.Sco[NEdit].Name), 120 + NEdit * (360 / 7)); } - // Echange les buffets video + // Update render SDL_RenderPresent(sdlRenderer); } while (true); @@ -1431,26 +1431,26 @@ eMenu Menu::SDLMain_Score(bool EditScore) /*** Draw main menu ***/ /**********************/ -void Menu::Print_Main(int Centre) const +void Menu::Print_Main(int Center) const { 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; + int const x1 = Menu_Py[PyE].StartX - 25; + int const x2 = (Center - x1) + Center; + int const y = (Menu_Py[PyE].EndY + Menu_Py[PyE].StartY) / 2; - Ec.PrintSprite(arrow_left, NumSp, x1, y); - Ec.PrintSprite(arrow_right, NumSp, x2, y); + screen.PrintSprite(arrow_left, NumSp, x1, y); + screen.PrintSprite(arrow_right, NumSp, x2, y); } -/*** Centre les flèches sur le boutton ***/ -/*****************************************/ -void Menu::Affiche_Main_Centre() const +/*** Center arrows on the menu ***/ +/*********************************/ +void Menu::Center_Arrows() const { 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; + int const x1 = Menu_Py[PyE].StartX - 5; + int const x2 = Menu_Py[PyE].EndX + 5; + int const y = (Menu_Py[PyE].EndY + Menu_Py[PyE].StartY) / 2; - Ec.PrintSprite(arrow_left, NumSp, x1, y); - Ec.PrintSprite(arrow_right, NumSp, x2, y); + screen.PrintSprite(arrow_left, NumSp, x1, y); + screen.PrintSprite(arrow_right, NumSp, x2, y); } diff --git a/src/menu.h b/src/menu.h index 009eb68..298ba57 100644 --- a/src/menu.h +++ b/src/menu.h @@ -26,7 +26,7 @@ #include "preference.h" -/*** Fonction d'attente ***/ +/*** Waiting function ***/ /**************************/ void Sleeping(); @@ -35,7 +35,7 @@ class Audio; class Gamepad; class Mouse; -/*** Définition de la class ***/ +/*** Manu Class definition ***/ /******************************/ class Menu { @@ -44,30 +44,30 @@ class Menu m_game(game), m_audio(audio), m_mouse(mouse), m_gamepad(gamepad) { }; ~Menu() = default; - /*** Fonctions ***/ + /*** Functions ***/ /*****************/ - eMenu SDLMain(); // Menu principale - eMenu SDLMain_Language(); // Menu du choix de la langue - void InitMain_Options(); // Prépare l'affichage du menu options - eMenu SDLMain_Options(); // Menu du choix des options - eMenu SDLMain_Speed(); // Menu du choix de la difficulté - eMenu SDLMain_Level(); // Choisi le niveau + eMenu SDLMain(); // Main menu + eMenu SDLMain_Language(); // Language choice menu + void InitMain_Options(); // Preparing settings menu display + eMenu SDLMain_Options(); // Settings menun + eMenu SDLMain_Speed(); // Difficulty menu + eMenu SDLMain_Level(); // Level selection menu #ifndef DCHILDREN - eMenu SDLMain_HR(); // Menu de question sur les droits de l'homme + eMenu SDLMain_HR(); // Human rights questions menu #endif - void Print_InGame(); // Affiche le menu InGame - eMenu SDLMain_InGame(); // Menu dans le jeu - eMenu SDLMain_Score(bool EditScore = false); // Affiche les scores + void Print_InGame(); // Print menu InGame + eMenu SDLMain_InGame(); // InGame Menu + eMenu SDLMain_Score(bool EditScore = false); // Display scores - void Print_Main(int Centre = 400) const; // Affiche le menu principale - void Affiche_Main_Centre() const; // Centre les flèches sur le bouton + void Print_Main(int Center = 400) const; // Display main menu + void Center_Arrows() const; // Center arrows on the button private: /*** Variables ***/ /*****************/ - int PyE { 0 }; // Position du curseur dans le menu - int Niv { 0 }; - int CentreM { 0 }; // Variable pour le menu options + int PyE { 0 }; // Position of the cursor in the menu + int Level { 0 }; + int CenterM { 0 }; // Variable for the settings menu Game &m_game; Audio &m_audio; diff --git a/src/mouse.cc b/src/mouse.cc index c39762f..d261b6d 100644 --- a/src/mouse.cc +++ b/src/mouse.cc @@ -29,49 +29,49 @@ #include "screen.h" #include "sprite.h" // for e_Sprite -/*** Variables Globales ***/ +/*** Global variables ***/ /**************************/ extern int currentTime; -extern Screen Ec; +extern Screen screen; extern SDL_Window *sdlWindow; -/*** Initialise la sourie ***/ -/****************************/ +/*** Mouse init ***/ +/******************/ void Mouse::InitStart() { - // Initialise les coordonnées de la sourie + // Init mouse coordinates Px = 400; Py = 300; SDL_WarpMouseInWindow(sdlWindow, Px, Py); } -/*** Initialise un bebut d'utilisation ***/ +/*** Initialise the mouse for use ***/ /*****************************************/ void Mouse::Init(struct mPy *TablePy, struct mButton *B) { - // Sauve les adresses utils + // Save useful pointers tPy = TablePy; Bo = B; } -/*** Prend les evenements de la sourie ***/ -/*****************************************/ +/*** Fetch mouse events ***/ +/**************************/ void Mouse::GetEvent(SDL_Event &event, int &pPy) { int i; switch (event.type) { - case SDL_MOUSEMOTION: // Si mouvement de la sourie + case SDL_MOUSEMOTION: // If mouse moves Px = event.motion.x; Py = event.motion.y; - // regarde si doit bouger la position de Py - if (tPy) { // Si bien une table + // Check if py's position must move + if (tPy) { // If the table exists i = 0; - while (tPy[i].DepX != -1) { // Fait toutes les coordonnées - if (Px >= tPy[i].DepX && Px <= tPy[i].FinX && Py >= tPy[i].DepY && Py <= tPy[i].FinY) { + while (tPy[i].StartX != -1) { // iterate through all coordinates + if (Px >= tPy[i].StartX && Px <= tPy[i].EndX && Py >= tPy[i].StartY && Py <= tPy[i].EndY) { if (pPy != tPy[i].Py) { pPy = tPy[i].Py; - m_audio.Play(sClic); + m_audio.Play(sClick); } } i++; @@ -83,12 +83,12 @@ void Mouse::GetEvent(SDL_Event &event, int &pPy) Px = event.button.x; Py = event.button.y; - // regarde si doit valider un enter - if (tPy) { // Si bien une table + // Trigger Enter key if clicking on a valid region + if (tPy) { // If table exists i = 0; - while (tPy[i].DepX != -1) { // Fait toutes les coordonnées - if (Px >= tPy[i].DepX && Px <= tPy[i].FinX && Py >= tPy[i].DepY && Py <= tPy[i].FinY) { - if (tPy[i].Valide == true) { + while (tPy[i].StartX != -1) { // iterate through defined regions + if (Px >= tPy[i].StartX && Px <= tPy[i].EndX && Py >= tPy[i].StartY && Py <= tPy[i].EndY) { + if (tPy[i].Valid == true) { event.type = SDL_KEYDOWN; event.key.state = SDL_PRESSED; event.key.keysym.sym = SDLK_RETURN; @@ -98,18 +98,18 @@ void Mouse::GetEvent(SDL_Event &event, int &pPy) }; } - // Fait la gestion des bouttons - if (Bo) { // Si bien une table + // Handle button interactions + if (Bo) { // If table exists i = 0; - while (Bo[i].DepX != -1) { // Fait toutes les coordonnées - if (Px >= Bo[i].DepX && Px <= Bo[i].FinX && Py >= Bo[i].DepY && Py <= Bo[i].FinY) { - if (Bo[i].Adr == nullptr) { // Si doit fair une touche + while (Bo[i].StartX != -1) { // Iterate through defined regions + if (Px >= Bo[i].StartX && Px <= Bo[i].EndX && Py >= Bo[i].StartY && Py <= Bo[i].EndY) { + if (Bo[i].Adr == nullptr) { // If a key press should be triggered event.type = SDL_KEYDOWN; event.key.state = SDL_PRESSED; - event.key.keysym.sym = (SDL_Keycode)Bo[i].Valeur; + event.key.keysym.sym = (SDL_Keycode)Bo[i].Value; } - else { // Si doit changer une variable - *(Bo[i].Adr) = Bo[i].Valeur; + else { // If a variable should be changed + *(Bo[i].Adr) = Bo[i].Value; } } i++; @@ -120,14 +120,14 @@ void Mouse::GetEvent(SDL_Event &event, int &pPy) } } -/*** Affiche le curseur ***/ +/*** Display cursor ***/ /**************************/ void Mouse::Print() const { int X = Px, Y = Py; int const NumSp = (currentTime / 50) % 20; - // Corrige la position du curseur au cas ou déborde de l'écran + // Correct cursor position if it goes off screen if (X < 5) { X = 5; } @@ -142,7 +142,7 @@ void Mouse::Print() const } #ifndef ANDROID - // Affiche le curseur - Ec.PrintSprite(cursor, NumSp, X, Y); + // Display cursor + screen.PrintSprite(cursor, NumSp, X, Y); #endif } diff --git a/src/mouse.h b/src/mouse.h index 097492b..b0da744 100644 --- a/src/mouse.h +++ b/src/mouse.h @@ -27,25 +27,25 @@ #include class Audio; -/*** Structure pour la position dans le menu Py ***/ +/*** Structure for the positions in the Py menu ***/ /**************************************************/ struct mPy -{ // DepX==-1 si derniere entrée - int DepX, DepY; - int FinX, FinY; +{ // DepX==-1 if last entry + int StartX, StartY; + int EndX, EndY; int Py; - bool Valide; // Si doit valider un enter quand click de la sourie + bool Valid; // Trigger enter key on mouse click }; struct mButton -{ // DepX=-1 si derniere entrée - int DepX, DepY; - int FinX, FinY; - int Valeur; +{ // DepX=-1 if last entry + int StartX, StartY; + int EndX, EndY; + int Value; int *Adr; }; -/*** Définition de la class Tableau ***/ +/*** Mouse class definition ***/ /**************************************/ class Mouse { @@ -54,17 +54,17 @@ class Mouse m_audio(audio) { } ~Mouse() = default; - void InitStart(); // Initialise les coordonnées de la sourie - void Init(struct mPy *TablePy, struct mButton *B = nullptr); // Initialise la sourie - void GetEvent(SDL_Event &event, int &Py); // Prend les evenements - void Print() const; // Affiche le curseur + void InitStart(); // Inits the mouse coordinates + void Init(struct mPy *TablePy, struct mButton *B = nullptr); // Mouse init + void GetEvent(SDL_Event &event, int &Py); // Fetches events + void Print() const; // Displays cursor int Px { 400 }, Py { 300 }; // Mouse screen position private: Audio &m_audio; - struct mPy *tPy { nullptr }; // Pointe sur coordonées pour Py - struct mButton *Bo { nullptr }; // Pointe sur les coordonnées des bouttons + struct mPy *tPy { nullptr }; // Pointer to py coordinates + struct mButton *Bo { nullptr }; // Pointer to Button coordinates }; #endif diff --git a/src/preference.h b/src/preference.h index b24bdef..5e929e9 100644 --- a/src/preference.h +++ b/src/preference.h @@ -41,7 +41,7 @@ #define N_LIVES_COUNT 3 -#define RAYON_TOUCHE (32 * 32) +#define RAY_HIT (32 * 32) #define LT 17 #define HT 15 @@ -58,12 +58,12 @@ /*** Possible pieces on the level ***/ #define C_None 0 #define C_Rail 1 -#define C_Wagon 2 -#define C_Allonge 3 -#define C_Reduit 4 +#define C_Car 2 +#define C_Expand 3 +#define C_Shrink 4 #define C_Speed 5 #define C_Live 6 -#define C_Fin 7 +#define C_Size 7 enum e_Difficulty { Easy, @@ -80,23 +80,23 @@ struct sScore char Name[80]; }; -/*** Preferences structures ***/ +/*** Old Preferences structures, UNUSED ***/ struct sOldPreference { - 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 - float EcartWagon; // ecart en pixels entre 2 wagons + e_Difficulty Difficulte; // Difficulty (Speed) + int Level; // Player Level + int Lives; // Player Life count + int Score; // Player Score + double Vitesse; // Speed according to level + double VitesseMoy; // Current locomotive speed + float EcartWagon; // gap in pixels between wagons int NiveauMax; int FullScreen; - int Langue; // Langue à afficher - int NLangues; // Nombre de langues disponible - float Volume; // Volumes audio - float VolumeM; // Volume de la music - struct sScore Sco[8]; // Mémorise les scores + int Langue; // Language displayed + int NLangues; // Available languages + float Volume; // Sound effects volume + float VolumeM; // Music volume + struct sScore Sco[8]; // Store scores }; struct sNewPreference diff --git a/src/screen.cc b/src/screen.cc index e3c10b3..25031a7 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -25,11 +25,11 @@ #include "sprite.h" #include "screen.h" -/*** Variables globales ***/ +/*** Global variables ***/ /**************************/ extern Sprite *Sprites; -/*** Affiche un Sprite ***/ +/*** Displaying a sprite ***/ /*************************/ void Screen::PrintSprite(e_Sprite NumSpr, int Num, int x, int y) { @@ -42,35 +42,35 @@ void Screen::PrintCable(int dx, int dy, int fx, int fy) Sprites[rope].PrintRope(dx, dy, fx, fy); } -/*** Affiche un text ***/ +/*** Display a text ***/ /***********************/ void Screen::PrintText(e_Sprite Text, int x, int y) { Sprites[Text].Draw(x, y, 0); } -/*** Affiche les options du jeu ***/ +/*** Display game settings ***/ /**********************************/ -void Screen::PrintOptions(int NV, int NScore) +void Screen::PrintOptions(int Nlives, int NScore) { int x, y; Score = NScore; DrawNumber(740, 215, Score); - if (NV > 10) { - NV = 10; // Evite un dépassement de l'affichage + if (Nlives > 10) { + Nlives = 10; // Clamp to avoid going off screen } - for (int i = 0; i < NV; ++i) { // Affiche les vies + for (int i = 0; i < Nlives; ++i) { // Display lives x = i % 2; x = x * 44 + 38 + LT * D_Case; y = i / 2; y = 384 + y * 46; - Sprites[logo_vie].Draw(x, y, 0); + Sprites[logo_health].Draw(x, y, 0); } } -/*** Efface l'ecran avec l'image de fond ***/ +/*** Erase display with background image ***/ /*******************************************/ void Screen::CleanSpriteAndScreen(e_Sprite NumSp) { diff --git a/src/screen.h b/src/screen.h index c47941e..6e65941 100644 --- a/src/screen.h +++ b/src/screen.h @@ -33,15 +33,15 @@ class Screen Screen() = default; ~Screen() = default; - void PrintSprite(e_Sprite NumSpr, int Num, int x, int y); // Affiche un sprite - void PrintCable(int dx, int dy, int fx, int fy); // Affiche un cable - void PrintText(e_Sprite Text, int x, int y); // Affiche un text à l'ecran - void PrintOptions(int NVies, int NScore); // Affiche les options sur le coté - void CleanSpriteAndScreen(e_Sprite NumSpriteFondEcran); // Efface l'ecran avec l'image de fond + void PrintSprite(e_Sprite NumSpr, int Num, int x, int y); // Displays a sprite + void PrintCable(int dx, int dy, int fx, int fy); // Displays a cable/rope + void PrintText(e_Sprite Text, int x, int y); // Displays text + void PrintOptions(int Nlives, int NScore); // Displays information on the side + void CleanSpriteAndScreen(e_Sprite NumSpritebackground); // Erases display with background image private: /*** Variables ***/ - int Score { -1 }; // Mémorise le score affiché + int Score { -1 }; // Stores displayed score }; #endif diff --git a/src/sprite.cc b/src/sprite.cc index 754e372..0c4f8d6 100644 --- a/src/sprite.cc +++ b/src/sprite.cc @@ -37,40 +37,40 @@ extern Sprite *Sprites; extern int NSprites; extern sNewPreference Pref; -static const char *OrdreTexte = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-!?*+<>%$()&;"; -static const char *OrdreTexte2 = "abcdefghijklmnopqrstuvwxyz0123456789,_|?*+<>%$[]&;"; -static int TableTexte[256]; +static const char *TextOrder = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-!?*+<>%$()&;"; +static const char *TextOrder2 = "abcdefghijklmnopqrstuvwxyz0123456789,_|?*+<>%$[]&;"; +static int TextTable[256]; -char Langue[31][16]; // Mémorise les noms des langues -int NTextes = 0; +char Languages[31][16]; // Stores languages +int NTexts = 0; bool shouldDrawLoading = false; #define N_SPRITESFOND 2 -/*** Affiche le chargeur lors du chargement ***/ -/**********************************************/ +/*** Displays loader when loading ***/ +/************************************/ void DrawLoading() { - static int NumAf = -1; // Numéro su sprite affiché + static int NumDisplayed = -1; // Number of the displayed sprite int i, Old; int Clock; if (shouldDrawLoading == true) { Clock = SDL_GetTicks(); - i = (Clock / (1000 / 25)) % Sprites[loading].N; // Calcule le numéro su sprite à afficher + i = (Clock / (1000 / 25)) % Sprites[loading].N; // Calculates the Number of the wanted sprite - if (i != NumAf) { - Old = NumAf; - NumAf = i; - Sprites[loading].Draw(400, 300, NumAf); + if (i != NumDisplayed) { + Old = NumDisplayed; + NumDisplayed = i; + Sprites[loading].Draw(400, 300, NumDisplayed); SDL_RenderPresent(sdlRenderer); // TODO if(Old!=-1) Sprites[chargeur].Efface(400,300,Old,sdlVideo); } } } -/*** Charge les Sprites d'une langue ***/ -/***************************************/ +/*** Loads the sprite of a language ***/ +/**************************************/ bool LoadLanguage() { long L, P; @@ -78,17 +78,17 @@ bool LoadLanguage() unsigned char *Buf; char PathFile[512]; - strcpy(PathFile, Langue[Pref.Language]); + strcpy(PathFile, Languages[Pref.Language]); Utils::GetPath(PathFile); if (Utils::FileExists(PathFile) == false) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find '%s'", Langue[Pref.Language]); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find '%s'", Languages[Pref.Language]); return false; } L = Utils::LoadFile(PathFile, Buf); - // Lit les sprites + // Reads sprites P = 0; - for (i = 0; i < NTextes; i++) { + for (i = 0; i < NTexts; i++) { if (Sprites[T_level + i].N) { Sprites[T_level + i].Delete(); } @@ -96,13 +96,13 @@ bool LoadLanguage() return false; } } - delete[] Buf; // Libère la mémoire du fichier des sprites + delete[] Buf; // Frees memory from the sprite file return true; } -/*** Charge les Sprites du jeu ***/ -/*********************************/ +/*** Loads the game's sprites ***/ +/********************************/ bool LoadSprites() { long L, P; @@ -115,21 +115,21 @@ bool LoadSprites() // Initialise la table de caractaire des textes for (i = 0; i < 256; i++) { - TableTexte[i] = -1; + TextTable[i] = -1; } i = 0; - while (OrdreTexte[i] != 0) { - TableTexte[(int)(OrdreTexte[i])] = i; + while (TextOrder[i] != 0) { + TextTable[(int)(TextOrder[i])] = i; i++; } i = 0; - while (OrdreTexte2[i] != 0) { - TableTexte[(int)(OrdreTexte2[i])] = i; + while (TextOrder2[i] != 0) { + TextTable[(int)(TextOrder2[i])] = i; i++; } - // *** Charge le fichier des langues *** - // ************************************* + // *** Loads the languages file *** + // ******************************** if (Utils::FileExists(PathFile) == false) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find 'language.dat'"); return false; @@ -139,34 +139,34 @@ bool LoadSprites() // Prend le nombre de sprites NSp = (int)(Buf[0]) * 256 + (int)(Buf[1]); NSp += N_SPRITESFOND + 2; - NTextes = (int)(Buf[2]) * 256 + (int)(Buf[3]); + NTexts = (int)(Buf[2]) * 256 + (int)(Buf[3]); Pref.NLanguages = (int)(Buf[4]) * 256 + (int)(Buf[5]); - NSprites = NSp + NTextes + Pref.NLanguages; + NSprites = NSp + NTexts + Pref.NLanguages; Sprites = new Sprite[NSprites]; - // Récupère les nom des langues + // Fetch languages names P = 6; for (i = 0; i < Pref.NLanguages; i++) { - strcpy(Langue[i], (char *)(Buf + P)); + strcpy(Languages[i], (char *)(Buf + P)); P += strlen((char *)(Buf + P)) + 1; } - // Charge les sprites des langues + // Load languages sprite for (i = 0; i < Pref.NLanguages; i++) { - if (Sprites[T_Langue + i].Load(Buf, P) == false) { + if (Sprites[T_Language + i].Load(Buf, P) == false) { return false; } } if (Sprites[loading].Load(Buf, P) == false) { - return false; // Sprite du chargeur + return false; // Loading sprite } - shouldDrawLoading = true; // Peut afficher le sprite du chargeur + shouldDrawLoading = true; // can display loading sprite delete[] Buf; - // *** Charge le fichier des sprites *** + // *** loads sprites file *** // ************************************* strcpy(PathFile, "sprites.dat"); Utils::GetPath(PathFile); @@ -176,12 +176,12 @@ bool LoadSprites() } L = Utils::LoadFile(PathFile, Buf); - // Lit les sprites + // Reads sprites P = 0; for (i = 0; i < NSp; i++) { DrawLoading(); switch (i) { - case fjeu: + case fgame: case fmenu: if (Sprites[i].New(800, 600) == false) { return false; @@ -199,20 +199,20 @@ bool LoadSprites() } } - delete[] Buf; // Libère la mémoire du fichier des sprites + delete[] Buf; // Frees memory from the sprites file - // *** Charge la langue *** + // *** Loads language *** // ************************ if (Pref.Language != -1) { LoadLanguage(); } - shouldDrawLoading = false; // N'affiche plus les sprites du chargeur + shouldDrawLoading = false; // Disable loading sprite return true; } -/*** Retourne la longueur d'un nombre ***/ -/****************************************/ +/*** Returns the length of a number ***/ +/**************************************/ int NumberLength(int C) { int l = 0; @@ -221,32 +221,32 @@ int NumberLength(int C) l += Sprites[digits].Dim[(C % 10)].L; C /= 10; if (C) { - l += ECART_ENTRE_CHIFFRE; + l += GAP_BETWEEN_NUMBERS; } } while (C); return l; } -/*** Retourne la longueur d'un texte ***/ -/***************************************/ -int StringLength(char *Texte) +/*** Returns the length of a string ***/ +/**************************************/ +int StringLength(char *Text) { int i = 0; int l = 0; int Le; - while (Texte[i] != 0) { - Le = (int)(Texte[i]); - if (TableTexte[Le] != -1) { - l += Sprites[lettres].Dim[(TableTexte[Le])].L; - if (Texte[i + 1] != 0) { - l += ECART_ENTRE_LETTRE; + while (Text[i] != 0) { + Le = (int)(Text[i]); + if (TextTable[Le] != -1) { + l += Sprites[letters].Dim[(TextTable[Le])].L; + if (Text[i + 1] != 0) { + l += GAP_BETWEEN_LETTERS; } } else { if (Le == (int)(' ')) { - l += LONGUEUR_ESPACE; + l += SPACE_LENGTH; } } @@ -256,8 +256,8 @@ int StringLength(char *Texte) return l; } -/*** Test si un caracataire existe ***/ -/*************************************/ +/*** Checks if a char exists ***/ +/********************************/ bool CharExist(char C) { if ((int)(C) < 0) { @@ -266,44 +266,44 @@ bool CharExist(char C) if (C == ' ') { return true; } - if (TableTexte[(int)(C)] != -1) { + if (TextTable[(int)(C)] != -1) { return true; } return false; } -/*** Affiche un nombre ***/ +/*** Displays a number ***/ /*************************/ -void DrawNumber(int x, int y, int Nombre, SDL_Texture *Fond) +void DrawNumber(int x, int y, int Number, SDL_Texture *Background) { - int const l = NumberLength(Nombre); + int const l = NumberLength(Number); x += l / 2; do { - 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); + Sprites[digits].Draw(x - (Sprites[digits].Dim[(Number % 10)].L) / 2, y, Number % 10, Background); + x -= Sprites[digits].Dim[(Number % 10)].L + GAP_BETWEEN_NUMBERS; + Number /= 10; + } while (Number); } -/*** Affiche un Texte ***/ +/*** Display a string ***/ /************************/ -void DrawString(int x, int y, char *Texte, SDL_Texture *Fond) +void DrawString(int x, int y, char *Text, SDL_Texture *background) { int i = 0; int Le; // TODO Handle here unicode - while (Texte[i] != 0) { - Le = (int)(Texte[i]); + while (Text[i] != 0) { + Le = (int)(Text[i]); - if (TableTexte[Le] != -1) { // Si un caractaire connue - Le = TableTexte[Le]; - Sprites[lettres].Draw(x + (Sprites[lettres].Dim[Le].L / 2), y, Le, Fond); - x += Sprites[lettres].Dim[Le].L + ECART_ENTRE_LETTRE; + if (TextTable[Le] != -1) { // If known char + Le = TextTable[Le]; + Sprites[letters].Draw(x + (Sprites[letters].Dim[Le].L / 2), y, Le, background); + x += Sprites[letters].Dim[Le].L + GAP_BETWEEN_LETTERS; } - else { // Si un espace + else { // if there's a space if (Le == (int)(' ')) { - x += LONGUEUR_ESPACE - ECART_ENTRE_LETTRE; + x += SPACE_LENGTH - GAP_BETWEEN_LETTERS; } } @@ -311,14 +311,14 @@ void DrawString(int x, int y, char *Texte, SDL_Texture *Fond) } } -/*** Affiche un text dans la langue ***/ -/**************************************/ -void DrawText(int x, int y, e_Sprite Text, SDL_Texture *Fond) +/*** Display text in a language ***/ +/**********************************/ +void DrawText(int x, int y, e_Sprite Text, SDL_Texture *Background) { - Sprites[Text].Draw(x, y, 0, Fond); + Sprites[Text].Draw(x, y, 0, Background); } -/*** Constructeur ***/ +/*** Constructor ***/ /********************/ Sprite::~Sprite() { @@ -331,27 +331,27 @@ Sprite::~Sprite() } } -/*** Charge les sprites ***/ +/*** Load Sprites ***/ /**************************/ bool Sprite::Load(unsigned char *Buf, long &P) { int i, j; unsigned char *B; - unsigned long ul = 1; // test le type de processeur + unsigned long ul = 1; // Checks processor type unsigned char *pul = (unsigned char *)(&ul); - // Prend nombre de sprites + // Gets Number of sprites N = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); P += 2; Dim = new s_Dim[N]; Image = new SDL_Texture *[N]; - // Lit tous les sprites + // Read all sprites for (i = 0; i < N; i++) { - // Affiche l'animation de chargement + // Displays loading DrawLoading(); - // Lit les dimensions + // Reads dimensions Dim[i].L = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); P += 2; Dim[i].H = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); @@ -363,7 +363,7 @@ bool Sprite::Load(unsigned char *Buf, long &P) Dim[i].bpp = (int)(Buf[P]) * 256 + (int)(Buf[P + 1]); P += 2; - // Fabrique la surface + // Build surface SDL_Surface *surface = SDL_CreateRGBSurface(0, Dim[i].L, Dim[i].H, Dim[i].bpp * 8, 0xff, 0xff00, 0xff0000, 0xff000000 * (Dim[i].bpp - 3)); if (surface == nullptr) { @@ -371,11 +371,11 @@ bool Sprite::Load(unsigned char *Buf, long &P) return false; } - // Copie les pixels + // Copy pixels SDL_LockSurface(surface); B = (unsigned char *)surface->pixels; - if (pul[0] == 0) { // Processeur type Power PC, 68000, .. + if (pul[0] == 0) { // Processor type Power PC, 68000, .. for (j = 0; j < Dim[i].L * Dim[i].H * Dim[i].bpp; j += Dim[i].bpp) { if (Dim[i].bpp == 4) { B[j + 3] = Buf[P++]; @@ -399,9 +399,9 @@ bool Sprite::Load(unsigned char *Buf, long &P) return true; } -/*** Affiche le sprite ***/ +/*** Displaying sprite ***/ /*************************/ -void Sprite::Draw(int X, int Y, int NumSpr, SDL_Texture *Fond) const +void Sprite::Draw(int X, int Y, int NumSpr, SDL_Texture *Background) const { SDL_Rect Position; SDL_Rect Di; @@ -428,11 +428,11 @@ void Sprite::PrintRope(int dx, int dy, int fx, int fy) SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 0); } -/*** Alloue un nouveau sprite vide ***/ -/*************************************/ +/*** Allocates a new empty sprite ***/ +/************************************/ bool Sprite::New(int Lx, int Ly) { - Delete(); // Efface au cas ou + Delete(); // Delete "just in case" N = 1; Dim = new s_Dim[N]; @@ -444,7 +444,7 @@ bool Sprite::New(int Lx, int Ly) Dim[0].cy = Ly / 2; Dim[0].bpp = 3; // No transparency - // Fabrique la surface + // Builds surface SDL_Surface *surface = SDL_CreateRGBSurface(0, Dim[0].L, Dim[0].H, Dim[0].bpp * 8, 0xff, 0xff00, 0xff0000, 0xff000000 * (Dim[0].bpp - 3)); if (surface == nullptr) { @@ -456,7 +456,7 @@ bool Sprite::New(int Lx, int Ly) return true; } -/*** Efface le sprite ***/ +/*** Deletes a sprite ***/ /************************/ void Sprite::Delete() { diff --git a/src/sprite.h b/src/sprite.h index df5f7a2..fae2642 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -27,22 +27,22 @@ #include #define FCOLOR 128 -#define ALPHA_OMBRE 125 -#define ECART_ENTRE_CHIFFRE 1 -#define ECART_ENTRE_LETTRE 2 -#define LONGUEUR_ESPACE 30 +#define ALPHA_SHADOW 125 +#define GAP_BETWEEN_NUMBERS 1 +#define GAP_BETWEEN_LETTERS 2 +#define SPACE_LENGTH 30 -/*** Definition de la structure Dim ***/ -/**************************************/ +/*** Dim struct definition ***/ +/*****************************/ struct s_Dim { int L, H; - int cx, cy; // Centre de l'image après recadrage - int bpp; // Nombre de bytes par pixels 3 ou 4 avec l'alpha + int cx, cy; // Image center after cropping + int bpp; // Number of bytes per pixels, 3 or 4 with alpha }; -/*** Nom des sprites ***/ -/***********************/ +/*** Sprite names ***/ +/********************/ enum e_Sprite { locomotive = 0, coal_wagon, @@ -50,16 +50,16 @@ enum e_Sprite { cargo_wagon, engine_wagon, cistern_wagon, - wagon, - pluslong, - pluscourt, + car, + expander, + shrinker, speed, life, new_wagon, - logo_vie, + logo_health, rail, dir, - lettres, + letters, digits, title, copyright, @@ -76,12 +76,12 @@ enum e_Sprite { keys, gmenu, menu, - fond_hr, - fond_hrr, - fond_menu, - fond, + background_hr, + background_hrr, + background_menu, + background, - fjeu, + fgame, fmenu, rope, loading, @@ -167,45 +167,45 @@ enum e_Sprite { T_art29, T_art30, #endif - T_Langue, + T_Language, T_ENDTEXT }; -/*** Fonctions ***/ +/*** Functions ***/ /*****************/ -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 +void DrawLoading(); // displays the loader on the startup page +bool LoadLanguage(); // Loads sprites of a language +bool LoadSprites(); // Loads all sprites -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 +int NumberLength(int C); // Returns the length in pixels of a number +int StringLength(char *Text); // Returns the length in pixels of a string. +bool CharExist(char C); // Checks if a character exists -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 DrawNumber(int x, int y, int Number, SDL_Texture *Background = nullptr); // Displays a number +void DrawString(int x, int y, char *Text, SDL_Texture *Background = nullptr); // Displays a string -void DrawText(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 *Background = nullptr); // Displays a text in the language -/*** Definition de la classe Sprite ***/ -/**************************************/ +/*** Sprite class definition ***/ +/*******************************/ class Sprite { public: Sprite() = default; ~Sprite(); - /*** Fonctions ***/ - bool Load(unsigned char *Buf, long &P); // Charge les images - void Draw(int X, int Y, int NumSpr, SDL_Texture *Fond = nullptr) const; // Affiche un sprite + /*** Functions ***/ + bool Load(unsigned char *Buf, long &P); // Loads images + void Draw(int X, int Y, int NumSpr, SDL_Texture *Background = nullptr) const; // Displays a sprite void PrintRope(int dx, int dy, int fx, int fy); - bool New(int Lx, int Ly); // Alloue un nouveau sprite vide sans transparence - void Delete(); // Efface la mémoire du sprite + bool New(int Lx, int Ly); // Allocates a new empty sprite without transparency + void Delete(); // Erases memory from the sprite /*** Variables ***/ - int N { 0 }; // Nombre de sprite - SDL_Texture **Image { nullptr }; // Pointe sur les sprites - s_Dim *Dim { nullptr }; // Dimensions des sprites + int N { 0 }; // Amount of sprites + SDL_Texture **Image { nullptr }; // Pointer to the sprites + s_Dim *Dim { nullptr }; // Dimensions of the sprites }; -#endif +#endif \ No newline at end of file diff --git a/src/utils.cc b/src/utils.cc index 9070adf..0de11f5 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -108,7 +108,7 @@ long Utils::LoadFile(const char *Path, unsigned char *&Buf) Po += 1024; } - if (Compt) { // Ne fait pas le test à cause d'un bug dans windows + if (Compt) { // "Does not do the check due to a bug in Windows" SDL_RWread(file, Po, 1, (unsigned int)Compt); }