| 1 | // (_||_/ |
| 2 | // ( ) Loco class |
| 3 | // ( o 0 ) |
| 4 | //-OOO°--(_)---°OOO--------------------------------------- |
| 5 | // Copyright (C) 2006 By Dominique Roux-Serret |
| 6 | // .OOOo oOOO. [email protected] |
| 7 | //-( )------( )--------------------------------------- |
| 8 | // ( ( ) / Copyright (C) 2023 By Johnny Jazeix |
| 9 | // (_) (_/ [email protected] |
| 10 | |
| 11 | // This program is free software; you can redistribute it and/or modify |
| 12 | // it under the terms of the GNU General Public License as published by |
| 13 | // the Free Software Foundation; either version 2 or version 3 of the License. |
| 14 | |
| 15 | // This program is distributed in the hope that it will be useful, |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | // GNU General Public License for more details. |
| 19 | |
| 20 | // You should have received a copy of the GNU General Public License along |
| 21 | // with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | |
| 24 | #ifndef LOCO_DOM_ |
| 25 | #define LOCO_DOM_ |
| 26 | |
| 27 | #include "sprite.h" |
| 28 | |
| 29 | class Screen; |
| 30 | class Audio; |
| 31 | |
| 32 | /*** Definition de la classe qui mémorise les cases ***/ |
| 33 | /******************************************************/ |
| 34 | struct s_TLoco |
| 35 | { |
| 36 | int P; // Pointe sur le N° de la case |
| 37 | float D; // Distance parcoure (case comprie) |
| 38 | unsigned char Arrive, Sortie; // Direction d'arrivée et de sortie |
| 39 | }; |
| 40 | |
| 41 | struct s_PosWagon |
| 42 | { // Mémorise la position avant et arrière des wagons pour le test de colision |
| 43 | int dx, dy; |
| 44 | int fx, fy; |
| 45 | float SprStart; // Si fini sa sequence d'affiche de départ |
| 46 | }; |
| 47 | #define N_SPR_START 50 |
| 48 | |
| 49 | /*** Définition de la class ***/ |
| 50 | /******************************/ |
| 51 | class Loco |
| 52 | { |
| 53 | public: |
| 54 | explicit Loco(Audio &audio); |
| 55 | ~Loco() = default; |
| 56 | |
| 57 | /*** Fonctions ***/ |
| 58 | void Init(int Pos, int Direction); // Initialise la loco sur le tableau |
| 59 | void Display(Screen &Ec); // Fait l'affichage de la loco. |
| 60 | void TestCase(float Dist, long DureeJeu, int *Tableau); // Test les options sur la case si passe au centre |
| 61 | void Avance(int Dureems, long DureeJeu, int *Touche, int *Tableau); // Fait avancer la locomotive |
| 62 | void DoFleche(int *Tableau, int *Touche); // Recherche la position de la futur intersection |
| 63 | bool TestDir(int FDir, int *Tableau); // Test si une direction est possible |
| 64 | void AddLoco(); // Ajoute une loco au azard |
| 65 | |
| 66 | /*** Fonctions privées ***/ |
| 67 | inline bool Go(int FuturDirection); // Fait avancer le tableau (retourne true si tourne) |
| 68 | inline void FindPoint(float Dist, int &x, int &y); // Retourne la position d'un point sur le parcour |
| 69 | |
| 70 | int Mort; // Mémorise l'heure + duree pour faire une pause aprés avoir touché un wagon |
| 71 | bool Gagne; // Si a fini le niveau |
| 72 | int PEntree; // Entrée le la loco sur une case pour la fleche |
| 73 | int PInter; // Position de la futur intersection pour afficher la fleche |
| 74 | |
| 75 | private: |
| 76 | /*** Variables ***/ |
| 77 | long Reduit, Alonge, Vitesse; // Memorise l'horloge de fin si doit réduire ou alonger le train |
| 78 | int PLoco; // Position de la tête de la loco dans le tableau |
| 79 | float D; // Distance parcourue par la loco |
| 80 | struct s_TLoco T[256]; // Mémorise le parcour de la loco maxi = 256 cases |
| 81 | int NWagon; // Mémorise le nombre de wagon |
| 82 | e_Sprite Wagon[256]; // Mémorise les wagons |
| 83 | struct s_PosWagon PosWagon[256]; // Mémorise position des wagons à l'écran pour test de colision |
| 84 | float MemoDuree; // Memorise la precedente durée pour faire avancer les explosions du depart |
| 85 | |
| 86 | Audio &m_audio; |
| 87 | }; |
| 88 | |
| 89 | #endif |