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
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ option(USE_CONAN
if(USE_CONAN)
find_package(SDL2 REQUIRED CONFIG)
find_package(SDL2_mixer REQUIRED CONFIG)
find_package(SDL2_ttf REQUIRED CONFIG)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2 SDL2_mixer)
pkg_check_modules(SDL2 REQUIRED sdl2 SDL2_mixer SDL2_ttf)
endif()

set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -80,7 +81,7 @@ if(LINUX)
endif()

if(USE_CONAN)
target_link_libraries(${LIRI_EXECUTABLE_NAME} PRIVATE SDL2::SDL2 SDL2_mixer::SDL2_mixer)
target_link_libraries(${LIRI_EXECUTABLE_NAME} PRIVATE SDL2::SDL2 SDL2_mixer::SDL2_mixer SDL2_ttf::SDL2_ttf)
else()
target_include_directories(${LIRI_EXECUTABLE_NAME} PUBLIC ${SDL2_INCLUDE_DIRS})
target_link_libraries(${LIRI_EXECUTABLE_NAME} PRIVATE ${SDL2_LINK_LIBRARIES})
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Johnny Jazeix: port to SDL2 + android + cmake
Copyright (c) 2006
Dominique Roux-Serret: design & programming & graphics & website.
Maf464: musics
Also ingame using Comic neue font: https://github.com/crozynski/comicneue

[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
alt="Get it on F-Droid"
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class LiRi(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = "sdl/[~2.28.5]", "sdl_mixer/[~2.8.0]", "openssl/1.1.1w"
requires = "sdl/[~2.28.5]", "sdl_mixer/[~2.8.0]", "sdl_ttf/[~2.24.0]", "openssl/1.1.1w"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some changes in parallel in both the main branch and in the sdl_ttf branch. Can you please rebase?
At the end, this file should be like https://github.com/petitlapin/Li-Ri/blob/work/sdl_ttf/conanfile.py

I also added the changes to compile for android in 6ecef05


def layout(self):
cmake_layout(self)
Expand Down
Empty file modified data/Li-ri-icon-64x64.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/comic.ttf
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add in the readme the link on where this font comes from + its licence

Binary file not shown.
5 changes: 4 additions & 1 deletion src/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_ENTER
#include <cstdlib>
#include <string>

#include "editor.h"
#include "menu.h"
#include "game.h"
#include "level.h"
#include "gamepad.h"
#include "mouse.h"
#include "screen.h"

/*** Variables globales ***/
/**************************/
extern SDL_Renderer *sdlRenderer;

extern Sprite *Sprites;
extern Screen *Ec;
extern sNewPreference Pref;

extern int currentTime;
Expand Down Expand Up @@ -251,7 +254,7 @@ void Editor::Draw() const
}

// Affiche numero du niveau
DrawNumber(740, 130, NumN + 1);
Ec->PrintText(std::to_string(NumN + 1), 740, 130);

// Affiche les options
for (i = 0; i < LT * HT; i++) {
Expand Down
38 changes: 20 additions & 18 deletions src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern sNewPreference Pref;
extern int currentTime;
extern int previousTime;

extern Screen Ec;
extern Screen *Ec;

extern Level level;

Expand Down Expand Up @@ -76,7 +76,7 @@ eMenu Game::SDLMain()
Help = true;
Load(NumN); // Charge le tableau
SDL_RenderPresent(sdlRenderer);
Ec.CleanSpriteAndScreen(fjeu);
Ec->CleanSpriteAndScreen(fjeu);
Pause = true;

currentTime = SDL_GetTicks(); // Prend l'horloge
Expand Down Expand Up @@ -369,12 +369,14 @@ bool Game::DrawLevel(int NivN)
#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]);
Ec->ChangeFontColor(255, 255, 0);
Ec->PrintText("Level", 740-Ec->TextLength("Level")/2, 110);
Ec->PrintText("Score", 740-Ec->TextLength("Score")/2, 180);
Ec->PrintText("Conf.", 740-Ec->TextLength("Conf.")/2, 260);
Ec->PrintText("Lives", 740-Ec->TextLength("Lives")/2, 340);
Ec->ChangeFontColor(255, 255, 255);

DrawNumber(740, 140, Pref.Level + 1, Sprites[fjeu].Image[0]);
Ec->PrintText(std::to_string(Pref.Level + 1), 740 - Ec->TextLength(std::to_string(Pref.Level + 1))/2, 140);

return true;
}
Expand Down Expand Up @@ -533,44 +535,44 @@ void Game::AfficheEcran()
break;
}

Ec.PrintSprite(dir, ndir, (Lo.PInter % LT) * D_Case + D_Case / 2, (Lo.PInter / LT) * D_Case + D_Case / 2);
Ec->PrintSprite(dir, ndir, (Lo.PInter % LT) * D_Case + D_Case / 2, (Lo.PInter / LT) * D_Case + D_Case / 2);
}

// Affiche les 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);
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
Ec.PrintSprite(pluslong, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
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
Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
Ec->PrintSprite(pluscourt, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
break;
case C_Speed: // Si plus vite
Ec.PrintSprite(speed, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
Ec->PrintSprite(speed, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
break;
case C_Live: // Si une vie
Ec.PrintSprite(life, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
Ec->PrintSprite(life, (DureeJeu * 40 / 1000 + i * 7) % 50, i % LT * D_Case + D_Case / 2, i / LT * D_Case + D_Case / 2);
break;
}
}

// Si en pose demande une touche
if (Pause) {
Ec.PrintText(T_press_any_key, LT * D_Case / 2, 300);
Ec->PrintText("Press any key", LT * D_Case / 2, 300);
}

// Affiche tableau de bord
Ec.PrintOptions(Pref.Lives, Pref.Score);
Ec->PrintOptions(Pref.Lives, Pref.Score);
if (Pref.WagonGap < WAGON_GAP_MIN) {
Ec.PrintSprite(pluscourt, (DureeJeu * 40 / 1000) % 50, 715, 295);
Ec->PrintSprite(pluscourt, (DureeJeu * 40 / 1000) % 50, 715, 295);
}
if (Pref.WagonGap > WAGON_GAP_AVERAGE) {
Ec.PrintSprite(pluslong, (DureeJeu * 40 / 1000) % 50, 715, 295);
Ec->PrintSprite(pluslong, (DureeJeu * 40 / 1000) % 50, 715, 295);
}
if (Pref.SpeedAverage > Pref.Speed) {
Ec.PrintSprite(speed, (DureeJeu * 40 / 1000 + 7) % 50, 765, 295);
Ec->PrintSprite(speed, (DureeJeu * 40 / 1000 + 7) % 50, 765, 295);
}
}
8 changes: 4 additions & 4 deletions src/loco.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void Loco::Init(int Pos, int Direction)

/*** Affiche la locomotive ***/
/*****************************/
void Loco::Display(Screen &Ec)
void Loco::Display(Screen *Ec)
{
float ltrain = 0;
float p1, p2, a, ar, vx, vy;
Expand Down Expand Up @@ -190,7 +190,7 @@ void Loco::Display(Screen &Ec)
cdy = y1 - (int)(cos(ar) * lv);

// Affiche le cable
Ec.PrintCable(cdx, cdy, cfx, cfy);
Ec->PrintCable(cdx, cdy, cfx, cfy);
}
// Calcule le crocher de fin pour le prochaine wagon
cfx = x1 - (int)(sin(ar + M_PI) * lv);
Expand Down Expand Up @@ -218,13 +218,13 @@ void Loco::Display(Screen &Ec)
ns += 160;
}

Ec.PrintSprite(Wagon[i], ns, x1, y1);
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) {
Ec.PrintSprite(new_wagon, (int)(PosWagon[i].SprStart), x1, y1);
Ec->PrintSprite(new_wagon, (int)(PosWagon[i].SprStart), x1, y1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/loco.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Loco

/*** Fonctions ***/
void Init(int Pos, int Direction); // Initialise la loco sur le tableau
void Display(Screen &Ec); // Fait l'affichage de la loco.
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
Expand Down
8 changes: 7 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <SDL2/SDL_video.h> // for SDL_CreateWindow, SDL_DestroyWindow
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>

#include "config.h"
#include "preference.h"
Expand All @@ -55,7 +56,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 *Ec; // 2 Video buffer pointer
sNewPreference Pref; // Preference table.
Level level;

Expand Down Expand Up @@ -106,6 +107,10 @@ int main(int narg, char *argv[])
// Close the program properly when quitting
atexit(SDL_Quit);

TTF_Init();

Ec = new Screen();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be deleted at the end to avoid memory leak.

(a future improvement will be to remove it as global variable, but that's outside this PR scope)


// Set resolution
int vOption = SDL_WINDOW_RESIZABLE;
if (Pref.FullScreen) {
Expand Down Expand Up @@ -201,6 +206,7 @@ int main(int narg, char *argv[])
SDL_DestroyRenderer(sdlRenderer);
SDL_DestroyWindow(sdlWindow);

TTF_Quit();
Mix_Quit();
SDL_Quit();
return 0;
Expand Down
Loading