Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/audio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/*** Variable globales ***/
/*************************/
extern sNewPreference Pref;
extern int Horloge;
extern int currentTime;

/*** Constructeur et Destructeur ***/
/***********************************/
Expand Down Expand Up @@ -162,10 +162,10 @@ void Audio::Play(eSon So)
}

if (So == sClic) {
if (Horloge - MemoHorloge <= 120) {
if (currentTime - MemorizedTime <= 120) {
return;
}
MemoHorloge = Horloge;
MemorizedTime = currentTime;
}

Mix_PlayChannel(-1, Son[So], 0);
Expand Down
2 changes: 1 addition & 1 deletion src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Audio
/*** Variables ***/
int N { 0 }; // Nombre d'échantillon audio
int NMus { 0 }; // Numéro de la music en cours
int MemoHorloge { 0 }; // Mémorise l'horloge pour les clics
int MemorizedTime { 0 }; // Mémorise l'horloge pour les clics
Mix_Chunk **Son { nullptr }; // Pointe sur les sons
};

Expand Down
76 changes: 38 additions & 38 deletions src/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ extern SDL_Renderer *sdlRenderer;
extern Sprite *Sprites;
extern sNewPreference Pref;

extern int Horloge;
extern int HorlogeAvant;
extern int currentTime;
extern int previousTime;

extern Level level;

Expand All @@ -62,10 +62,10 @@ eMenu Editor::SDLMain(int NumNiv)

NumN = NumNiv;

Affiche(); // Charge le tableau
Draw(); // Charge le tableau
SDL_RenderPresent(sdlRenderer);

Horloge = SDL_GetTicks(); // Prend l'horloge
currentTime = SDL_GetTicks(); // Prend l'horloge

Option = rail;

Expand All @@ -82,7 +82,7 @@ eMenu Editor::SDLMain(int NumNiv)
switch (event.type) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_ENTER) {
Affiche();
Draw();
}
break;
case SDL_KEYDOWN:
Expand Down Expand Up @@ -173,10 +173,10 @@ eMenu Editor::SDLMain(int NumNiv)
case pluscourt:
level.T[NumN].T[cy * LT + cx] = C_Reduit;
break;
case vitesse:
case speed:
level.T[NumN].T[cy * LT + cx] = C_Speed;
break;
case vie:
case life:
level.T[NumN].T[cy * LT + cx] = C_Live;
break;
case (e_Sprite)(locomotive + D_Top):
Expand All @@ -193,12 +193,12 @@ eMenu Editor::SDLMain(int NumNiv)
}

// Gère les Horloges et la pose
HorlogeAvant = Horloge;
Horloge = SDL_GetTicks();
previousTime = currentTime;
currentTime = SDL_GetTicks();
Sleeping();

// Fait l'affichage
Affiche();
Draw();
SDL_RenderPresent(sdlRenderer);

} while (true);
Expand All @@ -208,7 +208,7 @@ eMenu Editor::SDLMain(int NumNiv)

/*** Charge un tableau ***/
/*************************/
void Editor::Affiche() const
void Editor::Draw() const
{
int i, x, y, m, cx, cy;
unsigned char *T;
Expand All @@ -217,7 +217,7 @@ void Editor::Affiche() const
T = level.T[NumN].T;

// Fabrique le fond du jeu
Sprites[fond].Affiche(400, 300, 0);
Sprites[fond].Draw(400, 300, 0);

// Affiche le circuit
for (i = 0; i < LT * HT; i++) {
Expand All @@ -241,52 +241,52 @@ void Editor::Affiche() const
m += 1;
}

Sprites[rail].Affiche(x, y, NumRail[m]);
Sprites[rail].Draw(x, y, NumRail[m]);
}
}

// Affiche les décorations
for (i = 0; i < level.T[NumN].NDeco; i++) {
Sprites[deco].Affiche(level.T[NumN].Deco[i].x, level.T[NumN].Deco[i].y, level.T[NumN].Deco[i].NumSpr);
Sprites[deco].Draw(level.T[NumN].Deco[i].x, level.T[NumN].Deco[i].y, level.T[NumN].Deco[i].NumSpr);
}

// Affiche numero du niveau
AfficheChiffre(740, 130, NumN + 1);
DrawNumber(740, 130, NumN + 1);

// Affiche les options
for (i = 0; i < LT * HT; i++) {
switch (T[i]) {
case C_Wagon: // Si un loco
Sprites[wagon].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
Sprites[wagon].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
break;
case C_Allonge: // Si plus long
Sprites[pluslong].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
Sprites[pluslong].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
break;
case C_Reduit: // Si plus court
Sprites[pluscourt].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
Sprites[pluscourt].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
break;
case C_Speed: // Si plus vite
Sprites[vitesse].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
Sprites[speed].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
break;
case C_Live: // Si une vie
Sprites[vie].Affiche(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
Sprites[life].Draw(i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2, 25);
break;
}
}

// Affiche le départ de la locomotive
switch (level.T[NumN].DepDir) {
case D_Top:
Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 0);
Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 0);
break;
case D_Bottom:
Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 40);
Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 40);
break;
case D_Left:
Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 80);
Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 80);
break;
case D_Right:
Sprites[locomotive].Affiche(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 120);
Sprites[locomotive].Draw(level.T[NumN].DepX * D_Case + D_Case / 2, level.T[NumN].DepY * D_Case + D_Case / 2, 120);
break;
}

Expand All @@ -296,35 +296,35 @@ void Editor::Affiche() const
case wagon:
case pluslong:
case pluscourt:
case vitesse:
case vie:
Sprites[Option].Affiche(740, 200, 0);
case speed:
case life:
Sprites[Option].Draw(740, 200, 0);
break;
case (e_Sprite)(locomotive + D_Top):
Sprites[locomotive].Affiche(740, 200, 0);
Sprites[locomotive].Draw(740, 200, 0);
break;
case (e_Sprite)(locomotive + D_Bottom):
Sprites[locomotive].Affiche(740, 200, 40);
Sprites[locomotive].Draw(740, 200, 40);
break;
case (e_Sprite)(locomotive + D_Left):
Sprites[locomotive].Affiche(740, 200, 80);
Sprites[locomotive].Draw(740, 200, 80);
break;
case (e_Sprite)(locomotive + D_Right):
Sprites[locomotive].Affiche(740, 200, 120);
Sprites[locomotive].Draw(740, 200, 120);
break;
case deco:
Sprites[deco].Affiche(740, 200, NumDeco);
Sprites[deco].Draw(740, 200, NumDeco);
break;
default:
break;
}

// Affiche le curseur
if (Option != deco) {
Sprites[curseur].Affiche(m_mouse.Px, m_mouse.Py, 0);
Sprites[cursor].Draw(m_mouse.Px, m_mouse.Py, 0);
}
else {
Sprites[deco].Affiche(m_mouse.Px, m_mouse.Py, NumDeco);
Sprites[deco].Draw(m_mouse.Px, m_mouse.Py, NumDeco);
}
}

Expand Down Expand Up @@ -409,10 +409,10 @@ void Editor::PrendTouche(int Tou)
}

// test le niveau
Pref.Niveau = NumN;
Pref.Level = NumN;
m_game.SDLMain();
m_mouse.Init(nullptr);
Affiche();
Draw();
break;
case 'a':
Option = rail;
Expand All @@ -427,10 +427,10 @@ void Editor::PrendTouche(int Tou)
Option = pluscourt;
break;
case 't':
Option = vitesse;
Option = speed;
break;
case 'y':
Option = vie;
Option = life;
break;
}
}
2 changes: 1 addition & 1 deletion src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Editor
/*** Fonctions ***/
/*****************/
eMenu SDLMain(int NumNiveau); // Boucle principale
void Affiche() const; // Charge un tableau
void Draw() const; // Charge un tableau
void PrendTouche(int Touche); // Prend les touches enfoncées

private:
Expand Down
Loading