diff --git a/data/sprites.dat b/data/sprites.dat index b7e8eb3..d44ba04 100644 Binary files a/data/sprites.dat and b/data/sprites.dat differ diff --git a/src/audio.cc b/src/audio.cc index 5b812af..b177510 100644 --- a/src/audio.cc +++ b/src/audio.cc @@ -30,12 +30,12 @@ #include "utils.h" #include "preference.h" -/*** Variable globales ***/ +/*** Global varibles ***/ /*************************/ extern sNewPreference Pref; extern int Horloge; -/*** Constructeur et Destructeur ***/ +/*** Contructor and Destructor ***/ /***********************************/ Audio::~Audio() { @@ -51,7 +51,7 @@ Audio::~Audio() Mix_CloseAudio(); } -/*** Initialise l'Audio ***/ +/*** Audio initialization***/ /**************************/ bool Audio::Init() { @@ -62,11 +62,11 @@ bool Audio::Init() return false; } - /*** Allocation de la mémoire ***/ + /*** Memory allocation ***/ N = sFin; Son = new Mix_Chunk *[sFin]; - /*** Chargement des sons ***/ + /*** Loading sounds ***/ strcpy(PathFile, "Sounds/clic.wav"); Utils::GetPath(PathFile); Son[sClic] = Mix_LoadWAV(PathFile); @@ -110,7 +110,7 @@ bool Audio::Init() return true; } -/*** Charge une music 0=menu 1,2,3,4 = game ***/ +/*** Load music 0=menu 1,2,3,4 = game ***/ /**********************************************/ void Audio::LoadMusic(int Num) { @@ -124,12 +124,12 @@ void Audio::LoadMusic(int Num) if (Music) { PauseMusic(true); - Mix_HaltMusic(); // Arrete la music + Mix_HaltMusic(); // Stop music Mix_FreeMusic(Music); Music = nullptr; } - if (Num == 0) { // Si music du menu + if (Num == 0) { // If music from the menu strcpy(Provi, "Sounds/menu.mod"); Utils::GetPath(Provi); Music = Mix_LoadMUS(Provi); @@ -142,7 +142,7 @@ void Audio::LoadMusic(int Num) PlayMusic(); } -/*** Passe à la music de jeu suivante ***/ +/*** Skip to the next game music ***/ /****************************************/ void Audio::NextMusic() { @@ -153,7 +153,7 @@ void Audio::NextMusic() LoadMusic(NMus); } -/*** Fait la lecture d'un son ***/ +/*** Plays a sound ***/ /********************************/ void Audio::Play(eSon So) { @@ -171,7 +171,7 @@ void Audio::Play(eSon So) Mix_PlayChannel(-1, Son[So], 0); } -/*** Joue la music ***/ +/*** Play music ***/ /*********************/ void Audio::PlayMusic() const { @@ -195,7 +195,7 @@ void Audio::PauseMusic(bool Et) const } } -/*** Valide les Volumes ***/ +/*** Validates Volumes ***/ /**************************/ void Audio::DoVolume() const { diff --git a/src/audio.h b/src/audio.h index 4823562..b15ade1 100644 --- a/src/audio.h +++ b/src/audio.h @@ -26,7 +26,7 @@ #include -/*** Enumération des sons ***/ +/*** Enumeration of sounds***/ /****************************/ enum eSon { sClic = 0, @@ -41,7 +41,7 @@ enum eSon { sFin }; -/*** Définition de la classe Audio ***/ +/*** Audio class define ***/ /*************************************/ class Audio { @@ -49,25 +49,25 @@ class Audio 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(); // Initialization of audio + void LoadMusic(int Num); // Load music, 0 = music for menu 1,2,3,4=Jeu + void NextMusic(); // Skip to the next game music - void Play(eSon); // Joue un son - void PlayMusic() const; // Joue la music + void Play(eSon); // Plays a sound + void PlayMusic() const; // Plays a music - void PauseMusic(bool Etat) const; // Met ou no la music en pause + void PauseMusic(bool Etat) const; // Pause music - void DoVolume() const; // Valide les volumes audio - Mix_Music *Music { nullptr }; // Pointe sur les musics + void DoVolume() const; // Validates Volumes + Mix_Music *Music { nullptr }; // Music pointer private: /*** Variables ***/ - int N { 0 }; // Nombre d'échantillon audio - int NMus { 0 }; // Numéro de la music en cours - int MemoHorloge { 0 }; // Mémorise l'horloge pour les clics - Mix_Chunk **Son { nullptr }; // Pointe sur les sons + int N { 0 }; // Number of audio samples + int NMus { 0 }; // Current music number + int MemoHorloge { 0 }; // Remembers the time for clicks + Mix_Chunk **Son { nullptr }; // Sound pointer }; #endif diff --git a/src/editor.cc b/src/editor.cc index b6ed9c2..94d81e7 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -36,7 +36,7 @@ #include "gamepad.h" #include "mouse.h" -/*** Variables globales ***/ +/*** Global varibles ***/ /**************************/ extern SDL_Renderer *sdlRenderer; @@ -62,17 +62,17 @@ eMenu Editor::SDLMain(int NumNiv) NumN = NumNiv; - Affiche(); // Charge le tableau + Affiche(); // Load the table SDL_RenderPresent(sdlRenderer); - Horloge = SDL_GetTicks(); // Prend l'horloge + Horloge = SDL_GetTicks(); // Clock Option = rail; - // Initialise la sourie + // Initialize the mouse m_mouse.Init(nullptr); - // Prend les evenements + // Event listener do { SDL_Event event; while (SDL_PollEvent(&event)) { @@ -112,15 +112,15 @@ eMenu Editor::SDLMain(int NumNiv) } } - // Gère l'appuis du boutton de la sourie + // Manages mouse button presses cx = m_mouse.Px / D_Case; cy = m_mouse.Py / D_Case; if (Boutton && 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) { // If it's the first time you press the key + for (i = 0; i < level.T[NumN].NDeco; i++) { // Search for decoration near 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; @@ -135,7 +135,7 @@ eMenu Editor::SDLMain(int NumNiv) level.T[NumN].Deco[(level.T[NumN].NDeco - 1)].y = m_mouse.Py; TypeB = 1; } - else { // Fait passe la selection au premier plan + else { // This brings the selection to the front 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 time 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; @@ -192,7 +192,7 @@ eMenu Editor::SDLMain(int NumNiv) } } - // Gère les Horloges et la pose + // Manages the clocks and the installation HorlogeAvant = Horloge; Horloge = SDL_GetTicks(); Sleeping(); @@ -206,20 +206,20 @@ eMenu Editor::SDLMain(int NumNiv) return mQuit; } -/*** Charge un tableau ***/ +/*** Load the table ***/ /*************************/ void Editor::Affiche() const { int i, x, y, m, cx, cy; unsigned char *T; - // Prend l'adresse du niveau + // Takes the level address T = level.T[NumN].T; - // Fabrique le fond du jeu + // Create the game background Sprites[fond].Affiche(400, 300, 0); - // Affiche le circuit + // Draw circuit for (i = 0; i < LT * HT; i++) { if (T[i] >= C_Rail && T[i] < C_Fin) { y = i / LT * D_Case + D_Case / 2; @@ -245,36 +245,36 @@ void Editor::Affiche() const } } - // Affiche les décorations + // Draw decorations for (i = 0; i < level.T[NumN].NDeco; i++) { Sprites[deco].Affiche(level.T[NumN].Deco[i].x, level.T[NumN].Deco[i].y, level.T[NumN].Deco[i].NumSpr); } - // Affiche numero du niveau + // Draw level number AfficheChiffre(740, 130, NumN + 1); // Affiche les options for (i = 0; i < LT * HT; i++) { switch (T[i]) { - case C_Wagon: // Si un loco + case C_Wagon: // If wagon Sprites[wagon].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; - case C_Allonge: // Si plus long + case C_Allonge: // If long bonus Sprites[pluslong].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; - case C_Reduit: // Si plus court + case C_Reduit: // If short bonus Sprites[pluscourt].Affiche(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: // If speed bonus Sprites[vitesse].Affiche(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: // If live bonus Sprites[vie].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25); break; } } - // Affiche le départ de la locomotive + // Display locomotive direction switch (level.T[NumN].DepDir) { case D_Top: Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 0); @@ -290,7 +290,7 @@ void Editor::Affiche() const break; } - // Affiche l'option choisi dans le menu + // Displays the option selected in the menu switch (Option) { case rail: case wagon: @@ -319,7 +319,7 @@ void Editor::Affiche() const break; } - // Affiche le curseur + // Show cursor if (Option != deco) { Sprites[curseur].Affiche(m_mouse.Px, m_mouse.Py, 0); } @@ -328,7 +328,7 @@ void Editor::Affiche() const } } -/*** Prend les touches enfoncées ***/ +/*** Keyboard callback ***/ /***********************************/ void Editor::PrendTouche(int Tou) { @@ -392,23 +392,23 @@ void Editor::PrendTouche(int Tou) level.Clear(NumN); break; case '$': - // test si le dernier niveau est vide + // test 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--; //If empty, don't count it. } } - // Sauve le niveau + // Save the level if (level.Save() == false) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error while saving levels"); exit(-1); } - // test le niveau + // Test the level Pref.Niveau = NumN; m_game.SDLMain(); m_mouse.Init(nullptr); diff --git a/src/editor.h b/src/editor.h index 7b260bf..360ddb2 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 define ***/ /******************************/ 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 Affiche() const; // Charge un tableau - void PrendTouche(int Touche); // Prend les touches enfoncées + eMenu SDLMain(int NumNiveau); // Mainloop + void Affiche() const; // Load a table + void PrendTouche(int Touche); // Takes pressed keys private: /*** Variables ***/ - int N { 0 }; // Numero du tableau à éditer + int N { 0 }; // Table number to be edited e_Sprite Option { locomotive }; int NumDeco { 0 }; int NumN { 0 }; diff --git a/src/game.cc b/src/game.cc index 273a27b..1598269 100644 --- a/src/game.cc +++ b/src/game.cc @@ -37,7 +37,7 @@ #include "utils.h" #include "audio.h" -/*** Variables globales ***/ +/*** Global varibles ***/ /**************************/ extern SDL_Renderer *sdlRenderer; @@ -53,9 +53,9 @@ 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 MasqueK; // Mask for the movement keys -/*** Constructeur et Destructeur ***/ +/*** Constuctor and destructor ***/ /***********************************/ Game::Game(Audio &sounds, Gamepad &gamepad) : m_sounds(sounds), m_gamepad(gamepad), Lo(m_sounds) @@ -74,20 +74,20 @@ eMenu Game::SDLMain() int NumN = Pref.Niveau; Help = true; - Load(NumN); // Charge le tableau + Load(NumN); // Load the table SDL_RenderPresent(sdlRenderer); Ec.CleanSpriteAndScreen(fjeu); Pause = true; - Horloge = SDL_GetTicks(); // Prend l'horloge + Horloge = SDL_GetTicks(); // Clock DureeJeu = 0; Key = 0; - // Met le options de départ du joueur + // Set the player's starting options Pref.NVie = N_VIES_DEP; Pref.Score = 0; - // Prend les evenements + // Event listener 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 you turn off the screen + Pause = true; // Enable pause } break; case SDL_MOUSEBUTTONDOWN: @@ -218,7 +218,7 @@ eMenu Game::SDLMain() } } - // Gère les Horloges et la pose + // Manages the clocks and the installation HorlogeAvant = Horloge; Horloge = SDL_GetTicks(); Sleeping(); @@ -227,7 +227,7 @@ eMenu Game::SDLMain() } DureeJeu += Horloge - HorlogeAvant; - // Fait l'affichage + // Display DrawLevel(NumN); AfficheEcran(); SDL_RenderPresent(sdlRenderer); @@ -236,15 +236,15 @@ eMenu Game::SDLMain() Utils::doScreenshot(sdlRenderer); } - // Fait avancer la loco + // Move the locomotive forward if (Lo.Mort == -1 && Pause == false) { Lo.Avance(Horloge - HorlogeAvant, DureeJeu, Touche, T); } - // Test la fin d'une partie - if (Lo.Mort > -1 && Lo.Mort < Horloge) { // Si est Mort test si doit continuer ou quitter + // Test the end of a game + if (Lo.Mort > -1 && Lo.Mort < Horloge) { // If it's dead, test to see if it should continue or quit. if (Pref.NVie < 0) { - return mScoreEdit; // Si mort fini + return mScoreEdit; // If death ends } if (Lo.Gagne) { #ifndef DCHILDREN @@ -273,7 +273,7 @@ eMenu Game::SDLMain() return mQuit; } -/*** Charge un tableau ***/ +/*** Load a table ***/ /*************************/ bool Game::Load(int NivN) { @@ -281,12 +281,12 @@ bool Game::Load(int NivN) Pref.Niveau = NivN; - // Recopie le tableau + // Copy the table for (i = 0; i < LT * HT; i++) { T[i] = (int)level.T[NivN].T[i]; } - // Laisse ou efface la vie suivant le niveau + // Leave or erase life depending on the level switch (Pref.Difficulte) { case Easy: i = 5; @@ -305,12 +305,12 @@ bool Game::Load(int NivN) } } - // Initialise la locomotive + // Initialisate locomotive Lo.Init(level.T[NivN].DepX + level.T[NivN].DepY * LT, level.T[NivN].DepDir); BufTouche(level.T[NivN].DepDir); MasqueK = 0; - // Met la vitesse suivant difficulté + // Set the speed according to difficulty switch (Pref.Difficulte) { case Easy: Pref.Vitesse = Pref.VitesseMoy = VITESSE_MIN; @@ -325,16 +325,16 @@ bool Game::Load(int NivN) return DrawLevel(NivN); } -/*** Dessine le fond de l'ecran de jeu ***/ +/*** Draw background of game ***/ /*****************************************/ bool Game::DrawLevel(int NivN) { int i, x, y, m, cx, cy; - // Fabrique le fond du jeu + // Create the game's background Sprites[fond].Affiche(400, 300, 0, Sprites[fjeu].Image[0]); - // Affiche le circuit + // Draw the circuit for (i = 0; i < LT * HT; i++) { if (T[i] >= C_Rail && T[i] < C_Fin) { y = i / LT * D_Case + D_Case / 2; @@ -360,7 +360,7 @@ bool Game::DrawLevel(int NivN) } } - // Affiche les décorations + // Draw decorations #ifndef DCHILDREN for (i = 0; i < level.T[NivN].NDeco; i++) { Sprites[deco].Affiche(level.T[NivN].Deco[i].x, level.T[NivN].Deco[i].y, level.T[NivN].Deco[i].NumSpr, @@ -368,7 +368,7 @@ bool Game::DrawLevel(int NivN) } #endif - // Affiche les textes suivant la langue + // Displays texts according to language AfficheText(740, 110, T_level, Sprites[fjeu].Image[0]); AfficheText(740, 180, T_score, Sprites[fjeu].Image[0]); AfficheText(740, 260, T_options, Sprites[fjeu].Image[0]); @@ -379,8 +379,8 @@ bool Game::DrawLevel(int NivN) return true; } -/*** Fait tourner la fleche d'une simple touche ***/ -/**************************************************/ +/*** Rotates the arrow with a single touch ***/ +/*********************************************/ void Game::TourneFleche() { int To = Touche[0]; @@ -389,8 +389,8 @@ void Game::TourneFleche() int const y = Lo.PInter / LT; do { - // Fait toucher la direction dans le sens des aiguilles d'une montre - // et test si la nouvelle direction est possible + // Makes the direction touch in a clockwise direction + // and test if the new direction is possible switch (To) { case D_Top: To = D_Right; @@ -419,29 +419,29 @@ void Game::TourneFleche() } } while (Cherche == false); - BufTouche(To); // Mémorise la nouvelle touche par defaut. + BufTouche(To); // Remembers the new default key. } -/*** Mémorise une touche dans le buffet des touches ***/ +/*** Stores a key in the keypad ***/ /******************************************************/ void Game::BufTouche(int Tou) { int n = 0; - // Favorise la touche + // Promotes the touch while (Touche[n] != Tou) { - n++; // Prend position de la touche + n++; // Takes position of the key } - if (n) { // Si changement doit faire un décalage + if (n) { // If change is going to cause a shift while (n) { Touche[n] = Touche[n - 1]; n--; } - Touche[0] = Tou; // Mémorise la touche + Touche[0] = Tou; // Remember key } - // Cherche son oposé + // Looking for its opposite switch (Tou) { case D_Top: Tou = D_Bottom; @@ -457,22 +457,22 @@ void Game::BufTouche(int Tou) break; } - // Défavorise son oposé. + // Disadvantages its opposite. n = 3; while (Touche[n] != Tou) { - n--; // Prend position de la touche + n--; // Takes position of the key } - if (n < 3) { // Si changement doit faire un décalage + if (n < 3) { // If change is going to cause a shift while (n < 3) { Touche[n] = Touche[n + 1]; n++; } - Touche[3] = Tou; // Mémorise la touche + Touche[3] = Tou; // Remember key } } -/*** Test les directions possibles pour les fleches ***/ +/*** Test the possible directions for the arrows ***/ /******************************************************/ int Game::TestFleche(int Haut, int Bas, int Gauche, int Droite) { @@ -507,20 +507,19 @@ int Game::TestFleche(int Haut, int Bas, int Gauche, int Droite) return 0; } -/*** Affiche un ecran du jeu ***/ -/*******************************/ +/*** Render a screenshot of the game ***/ +/***************************************/ void Game::AfficheEcran() { int i; int ndir = 0; - // Prépare pour nouvelle Affichage + // Prepare for new display Ec.ClearSprite(fjeu); - // Fait nouvelle Affichage - Lo.Display(Ec); // Affiche la loco + Lo.Display(Ec); // Render locomotive - if (Lo.PInter != -1 && Help) { // Affiche la fleche sur la futur intersection + if (Lo.PInter != -1 && Help) { // Displays the arrow on the future intersection switch (Lo.PEntree) { case D_Left: ndir = TestFleche(0, 2, -1, 1); @@ -539,33 +538,32 @@ void Game::AfficheEcran() Ec.PrintSprite(dir, ndir, (Lo.PInter % LT) * D_Case + D_Case / 2, (Lo.PInter / LT) * D_Case + D_Case / 2); } - // Affiche les options + // Render options section for (i = 0; i < LT * HT; i++) { switch (T[i]) { - case C_Wagon: // Si un loco + case C_Wagon: // If wagon Ec.PrintSprite(wagon, (DureeJeu * 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 + case C_Allonge: // If long bonus Ec.PrintSprite(pluslong, (DureeJeu * 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 + case C_Reduit: // If short bonus Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; - case C_Speed: // Si plus vite + case C_Speed: // If speed bonus Ec.PrintSprite(vitesse, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2); break; - case C_Live: // Si une vie + case C_Live: // If live bonus Ec.PrintSprite(vie, (DureeJeu * 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 if (Pause) { Ec.PrintText(T_press_any_key, LT * D_Case / 2, 300); } - // Affiche tableau de bord + // Render bonuses on board Ec.PrintOptions(Pref.NVie, Pref.Score); if (Pref.EcartWagon < ECARTWAGON_MOY) { Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000) % 50, 715, 295); diff --git a/src/game.h b/src/game.h index 3fdaa5a..0250dc6 100644 --- a/src/game.h +++ b/src/game.h @@ -31,7 +31,7 @@ class Audio; class Menu; class Gamepad; -/*** Définition de la class ***/ +/*** Game class define ***/ /******************************/ class Game { @@ -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(); // SDL Main + bool Load(int NivN); // Load a table + bool DrawLevel(int NivN); // Draw background of game - 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 TourneFleche(); // Rotates the arrow with a single touch. + void BufTouche(int Touche); // Stores a key in the keypad + int TestFleche(int Haut, int Bas, int Gauche, int Droite); // Test the possible directions for the arrows + void AfficheEcran(); // Render a screenshot of the game private: /*** Variables ***/ bool Pause { false }; // Si en pose - long DureeJeu { 0 }; // Horloge de durée du jeu + long DureeJeu { 0 }; // Game duration 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 }; // Key buffer + int Touche[4]; // Direction requested + int T[LT * HT]; // Table pointer - bool Help { true }; // Si doit affiche les fleches d'aide + bool Help { true }; // If it enabled should display the help arrows Audio &m_sounds; Gamepad &m_gamepad; Menu *m_menu { nullptr }; - Loco Lo; // Gère la locomotive + Loco Lo; // Locomotive object }; #endif diff --git a/src/level.cc b/src/level.cc index 2a64f36..dc103b1 100644 --- a/src/level.cc +++ b/src/level.cc @@ -25,7 +25,7 @@ #include "utils.h" #include "level.h" -/*** Constructeurs ***/ +/*** Contructor ***/ /*********************/ Level::Level() { @@ -35,7 +35,7 @@ Level::Level() } } -/*** Charge les tableaux ***/ +/*** Load the table ***/ /***************************/ bool Level::Load() { @@ -50,7 +50,7 @@ bool Level::Load() return false; } - // Charge les tableaux + // Load the table N = (int)(Buf[0]) * 256 + (int)(Buf[1]); for (i = 0; i < N; i++) { @@ -75,7 +75,7 @@ bool Level::Load() return true; } -/*** Sauve les tableaux ***/ +/*** Save the table ***/ /**************************/ bool Level::Save() { @@ -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 the table Buf[0] = N / 256; Buf[1] = N % 256; @@ -119,7 +119,7 @@ bool Level::Save() } } - // Sauve les tableaux + // Save the table Utils::GetPath(NameLevelFile); if (Utils::SaveFile(NameLevelFile, (char *)Buf, P) == false) { delete[] Buf; @@ -130,7 +130,7 @@ bool Level::Save() return true; } -/*** Efface un Tableau ***/ +/*** Clear the table ***/ /*************************/ void Level::Del(int Num) { @@ -155,7 +155,7 @@ void Level::Del(int Num) } } -/*** Insert un Tableau ***/ +/*** Insert a Table ***/ /*************************/ void Level::Ins(int Num) { @@ -182,7 +182,7 @@ void Level::Ins(int Num) } } -/*** Vide un tableau ***/ +/*** Clear a table ***/ /***********************/ void Level::Clear(int Num) { diff --git a/src/level.h b/src/level.h index a4f0576..809328d 100644 --- a/src/level.h +++ b/src/level.h @@ -26,43 +26,43 @@ #include "preference.h" -/*** Définition de la structure d'un tableau ***/ -/***********************************************/ +/*** Table/level structure define ***/ +/***************************************/ struct s_Deco { - int NumSpr; // Numéro et position du sprite décoratif + int NumSpr; // Number and position of the 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 + unsigned char T[LT * HT]; // Circuit definition and options + int DepX; // Departure of the locomotive int DepY; - int DepDir; // Direction du départ - int NDeco; // Nombre d'éléments décoratifs + int DepDir; // Direction + int NDeco; // Number of decorative elements struct s_Deco Deco[32]; }; -/*** Définition de la classe ***/ -/*******************************/ +/*** Table/level class define ***/ +/********************************/ class Level { public: 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(); // Load the table + bool Save(); // Save the table + void Del(int Num); // Clear the table + void Ins(int Num); // Insert a Table + void Clear(int Num); // Clear a table /*** 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]; // Table pointer }; #endif diff --git a/src/loco.cc b/src/loco.cc index 1889a76..8c17f26 100644 --- a/src/loco.cc +++ b/src/loco.cc @@ -33,7 +33,7 @@ #define M_PI 3.141592654 #endif -/*** Variables globales ***/ +/*** Global varibles ***/ /**************************/ extern sNewPreference Pref; extern int Horloge; @@ -41,7 +41,7 @@ extern int MasqueK; 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 ***/ -/********************************/ +/*** Locomotive initialisation ***/ +/*********************************/ void Loco::Init(int Pos, int Direction) { int i; unsigned char Ar = 0; - PLoco = 0; // Pointe sur la première case + PLoco = 0; PInter = -1; - Vitesse = Reduit = Alonge = 0; // Pas d'alongement + Vitesse = Reduit = Alonge = 0; Mort = -1; Gagne = false; Pref.EcartWagon = ECARTWAGON_MOY; - // Initialise les variables + // Varibles initilization for (i = 0; i < 256; i++) { PosWagon[i].SprStart = 0; } - // Cherche le case Avant + // Look at direction switch (Direction) { case D_Top: Pos += LT; @@ -88,19 +88,18 @@ 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 + D = D_Case * 1.99; T[PLoco].P = Pos; T[PLoco].Arrive = Ar; T[PLoco].Sortie = Direction; T[PLoco].D = D_Case; - // Fait avancer d'une case + // Moves forward one space Go(Direction); Go(Direction); - // Initialise la loco et son wagon à charbon + // Initialize the locomotive and its coal wagon NWagon = 2; Wagon[0] = locomotive; Wagon[1] = charbon; @@ -113,20 +112,20 @@ void Loco::Init(int Pos, int Direction) MemoDuree = 0; } -/*** Affiche la locomotive ***/ -/*****************************/ +/*** Render locomotive ***/ +/*************************/ void Loco::Display(Screen &Ec) { 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; // Cable attachment points float lv; - // Affiche tous les wagons + // Render wagons for (i = 0; i < NWagon; i++) { - // Cherche les points du wagons + // Find the points on the wagons switch (Wagon[i]) { case charbon: p1 = ltrain + 11; @@ -141,17 +140,17 @@ void Loco::Display(Screen &Ec) lv = 20; } - // Calcule la position des points + // Calculate the position of the points 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; // Saves the position of the points for future collision testing 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 locomotive rotation angle and sprite number + if (x1 <= x2) { // Angle 0 - 180 vy = (float)(x2 - x1); vx = (float)(y2 - y1); if (vx != 0) { @@ -164,7 +163,7 @@ void Loco::Display(Screen &Ec) a = 180.0 + a; } } - else { // Angle 180.001 à 359.999 + else { // Angle 180 - 359 vy = (float)(x1 - x2); vx = (float)(y1 - y2); if (vx != 0) { @@ -179,35 +178,35 @@ void Loco::Display(Screen &Ec) } ar = a * M_PI / 180.0; - // Prend le centre du sprite + // Take 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 + // Render cable + if (i > 0) { // If it should render cable + // Calculate the attachment point cdx = x1 - (int)(sin(ar) * lv); cdy = y1 - (int)(cos(ar) * lv); - // Affiche le cable + // Render cable Ec.PrintCable(cdx, cdy, cfx, cfy); } // Calcule le crocher de fin pour le prochaine wagon cfx = x1 - (int)(sin(ar + M_PI) * lv); cfy = y1 - (int)(cos(ar + M_PI) * lv); - // Cherche le N° du Sprite + // Find sprite 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: @@ -220,7 +219,6 @@ void Loco::Display(Screen &Ec) Ec.PrintSprite(Wagon[i], ns, x1, y1); - // Si pas fini la sequence d'affiche de départ du wagon if (PosWagon[i].SprStart < N_SPR_START) { PosWagon[i].SprStart += MemoDuree * N_SPR_START / 750.0; if (PosWagon[i].SprStart < N_SPR_START) { @@ -228,31 +226,31 @@ void Loco::Display(Screen &Ec) } } - // Met l'ecart entre les wagons + // Place the gap between the wagons ltrain += Pref.EcartWagon; } } -/*** Test les options sur une case ***/ -/*************************************/ +/*** Colision test ***/ +/*********************/ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) { int i; float DMoy; float Ec1, vx, vy, Ec2; - // test si depasse milieu d'une case pour teste de colision + // Test if it crosses the middle of a cell for collision testing DMoy = (T[PLoco].D + T[PLoco - 1].D) / 2.0; if (D <= DMoy && D + Dist >= DMoy) { - // Test si sur une option + // Test if on an option switch (Tableau[T[PLoco].P]) { - case C_Wagon: // Une nouvelle loco + case C_Wagon: // A new wagon m_audio.Play(sWagon); - Tableau[T[PLoco].P] = 1; // efface l'option + Tableau[T[PLoco].P] = 1; Pref.Score += 5; - AddLoco(); // Ajoute une loco au azard + AddLoco(); // Add random wagon - Gagne = true; // Test si la dernière loco + Gagne = true; // Test if the last wagon for (i = 0; i < LT * HT; i++) { if (Tableau[i] == C_Wagon) { Gagne = false; @@ -263,9 +261,9 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) m_audio.Play(sEnd); } break; - case C_Allonge: // Alonge la loco + case C_Allonge: // Allonge locomotive m_audio.Play(sEtire); - Tableau[T[PLoco].P] = 1; // efface l'option + Tableau[T[PLoco].P] = 1; Pref.Score += 20; if (Reduit > DureeJeu) { Reduit = DureeJeu - 1; @@ -274,9 +272,9 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) Alonge = DureeJeu + DUREE_ALONGE; } break; - case C_Reduit: // Si réduit la loco + case C_Reduit: // Reduit locomotive m_audio.Play(sReduit); - Tableau[T[PLoco].P] = 1; // efface l'option + Tableau[T[PLoco].P] = 1; if (Alonge > DureeJeu) { Alonge = DureeJeu - 1; } @@ -284,9 +282,9 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) Reduit = DureeJeu + DUREE_REDUIT; } break; - case C_Speed: // Si Vitesse + case C_Speed: // Speed up locomotive m_audio.Play(sSpeed); - Tableau[T[PLoco].P] = 1; // efface l'option + Tableau[T[PLoco].P] = 1; Pref.Score += 30; Vitesse = DureeJeu + DUREE_VITESSE; break; @@ -297,7 +295,7 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) break; } - // Test de colision avec un autre Wagon + // Test colision with other wagon for (i = 1; i < NWagon; i++) { vx = (float)(PosWagon[i].dx - PosWagon[0].dx); vy = (float)(PosWagon[i].dy - PosWagon[0].dy); @@ -306,7 +304,7 @@ 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 signal if (Mort < Horloge && (Ec1 < RAYON_TOUCHE || Ec2 <= RAYON_TOUCHE)) { m_audio.Play(sCrash); Pref.NVie--; @@ -316,8 +314,8 @@ void Loco::TestCase(float Dist, long DureeJeu, int *Tableau) } } -/*** Fait Avancer la locomotive ***/ -/**********************************/ +/*** Move the locomotive forward ***/ +/***********************************/ void Loco::Avance(int Duree, long DureeJeu, int *Touche, int *Tableau) { int i; @@ -327,17 +325,17 @@ void Loco::Avance(int Duree, long DureeJeu, int *Touche, int *Tableau) TestCase(Dist, DureeJeu, Tableau); - // Test si doit Réduire le wagon + // Test if it needs to reduce the wagon if (Reduit > DureeJeu) { - if (Pref.EcartWagon > ECARTWAGON_MIN) { // Si doit réduire + if (Pref.EcartWagon > ECARTWAGON_MIN) { // If must reduce Pref.EcartWagon -= (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon - 1)) / 1000.0; if (Pref.EcartWagon < ECARTWAGON_MIN) { Pref.EcartWagon = ECARTWAGON_MIN; } } } - else { // Si temps est passé - if (Pref.EcartWagon < ECARTWAGON_MOY) { // Si doit ralonger le wagon + else { // If time has passed + if (Pref.EcartWagon < ECARTWAGON_MOY) { // If the wagon needs to be lengthened Pref.EcartWagon += (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon)) / 1000.0; if (Pref.EcartWagon > ECARTWAGON_MOY) { Pref.EcartWagon = ECARTWAGON_MOY; @@ -345,17 +343,17 @@ void Loco::Avance(int Duree, long DureeJeu, int *Touche, int *Tableau) } } - // Test si doit Ralonger le wagon + // Test if the wagon needs to be lengthened if (Alonge > DureeJeu) { - if (Pref.EcartWagon < ECARTWAGON_MAX) { // Si doit Ralonger + if (Pref.EcartWagon < ECARTWAGON_MAX) { // If it needs to be extended Pref.EcartWagon += (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon)) / 1000.0; if (Pref.EcartWagon > ECARTWAGON_MAX) { Pref.EcartWagon = ECARTWAGON_MAX; } } } - else { // Si temps est passé - if (Pref.EcartWagon > ECARTWAGON_MOY) { // Si doit ralonger le wagon + else { // If time has passed + if (Pref.EcartWagon > ECARTWAGON_MOY) { // If the wagon needs to be lengthened Pref.EcartWagon -= (float)(Duree) * (Pref.VitesseMoy * 0.8 / (float)(NWagon - 1)) / 1000.0; if (Pref.EcartWagon < ECARTWAGON_MOY) { Pref.EcartWagon = ECARTWAGON_MOY; diff --git a/src/main.cc b/src/main.cc index 1100443..5860a42 100644 --- a/src/main.cc +++ b/src/main.cc @@ -46,27 +46,27 @@ #include "editor.h" #include "utils.h" -/*** Variables globales ***/ +/*** Global varibles ***/ /************************/ -SDL_Window *sdlWindow; // Pointe sur l'écran video -SDL_Renderer *sdlRenderer; // Pointe sur l'écran video +SDL_Window *sdlWindow; // Screen video pointer +SDL_Renderer *sdlRenderer; // Screen video pointer char Titre[] = "Li-ri V" VERSION; -Sprite *Sprites = nullptr; // Pointe sur les sprites -int NSprites = 0; // Nombre de sprites en mémoire -Screen Ec; // Pointe sur les 2 buffets vidéo -sNewPreference Pref; // Tableau des préférences. -Level level; // Gère les niveaux +Sprite *Sprites = nullptr; // Sprite pointer +int NSprites = 0; // Number of sprites in memory +Screen Ec; +sNewPreference Pref; // Preference table. +Level level; // Manages the levels -int Horloge = 0; // Horloges du jeu +int Horloge = 0; // Game clocks int HorlogeAvant = 0; #if defined(__unix__) || defined(__HAIKU__) -char DefPath[256]; // Chemin par defaut dans arg +char DefPath[256]; // Default path in arg #endif -/*** Initialise les preferences ***/ +/*** Initializate preferences ***/ /**********************************/ void InitPref() { @@ -82,14 +82,14 @@ void InitPref() Utils::LoadPref(); } -/*** Preogramme principale ***/ +/*** Main program ***/ /*****************************/ int main(int narg, char *argv[]) { int i; eMenu RetM, RetMenu = mMenu; - // Initialise les préferences + // Initializate preferences InitPref(); #if defined(__unix__) || defined(__HAIKU__) if (narg > 1) { @@ -98,15 +98,15 @@ int main(int narg, char *argv[]) #endif SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); - // Initiliase SDL + // Initializate SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s", SDL_GetError()); exit(-1); } - // Ferme le programme correctement quand quit + // Close the program properly when quitting atexit(SDL_Quit); - // Demande la resolution Video + // Set type of window int vOption = SDL_WINDOW_RESIZABLE; if (Pref.FullScreen) { vOption |= SDL_WINDOW_FULLSCREEN_DESKTOP; @@ -117,7 +117,7 @@ int main(int narg, char *argv[]) SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); SDL_RenderSetLogicalSize(sdlRenderer, 800, 600); - SDL_ShowCursor(0); // Masque le curseur + SDL_ShowCursor(0); // Hide cursor Audio audio; audio.Init();