Skip to content

Latest commit

 

History

89 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Platformer 2D (SFML, C++)

Release License: MIT C++17 SFML

Version 1.0.3 · Changelog

Wersja polska poniżej


A 2D platformer in C++17 using SFML 2.x. Play an eight-level campaign (short tutorial, extended late levels, L8 boss arena), collect coins and secret stars, triple-jump, shoot, avoid lava, enemies, and a final boss with multi-phase attacks. Features checkpoints, a shield bubble, SFX, longer CC0 music loops, and per-level parallax. Main menu, pause, volume options, Top 10, and scores.json.

Screenshots

Current game state (August 2026) — lava, shields, stars, boss:

Level 1 — forest Level 2 — desert
Level 1 Level 2
Level 3 — castle Level 4 — night / boss
Level 3 Level 4
YOU WIN — name entry
YOU WIN

Requirements

  • C++17
  • CMake >= 3.20
  • SFML 2.5+ (branch 2.x — not 3.x)

Installing SFML

macOS (Homebrew)

brew install sfml

Linux (Debian/Ubuntu)

sudo apt install libsfml-dev

Windows (vcpkg) — step by step

CMakeLists.txt has hardcoded paths and expects vcpkg at exactly C:\game2d\vcpkg, with SFML in C:\game2d\vcpkg\vcpkg_installed\x64-windows. The steps below create exactly that layout, so the project builds without editing CMakeLists.txt.

1. Install the tools. Install Visual Studio 2022 with the "Desktop development with C++" workload (provides the MSVC compiler, CMake and Ninja) and Git for Windows.

2. Open the developer console. From the Start menu launch "Developer Command Prompt for VS 2022" (the compiler is already on PATH).

3. Install vcpkg and SFML exactly in C:\game2d\vcpkg:

git clone https://github.com/microsoft/vcpkg C:\game2d\vcpkg
cd C:\game2d\vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg install sfml:x64-windows

4. Create the vcpkg_installed junction required by CMakeLists.txt (classic vcpkg installs into installed\, but the project looks in vcpkg_installed\):

mklink /J C:\game2d\vcpkg\vcpkg_installed C:\game2d\vcpkg\installed

5. Build the game (from the project directory):

cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:\game2d\vcpkg\scripts\buildsystems\vcpkg.cmake
cmake --build build --config Release

After building, CMake automatically copies the assets/ folder and the required SFML DLLs next to the .exe.

6. Run the game:

cd build\Release
Platformer.exe

Building (macOS / Linux)

mkdir build
cd build
cmake ..
cmake --build .

Executable: Platformer (Windows: Platformer.exe).
The assets/ folder is copied automatically to the binary directory after each build.

Running

cd build
./Platformer        # macOS / Linux

Controls

Main menu

Key / action Description
/ Navigate menu options
Mouse move Highlight option under cursor
Enter / LMB Select option

In-game

Key Action
A / Move left
D / Move right
Jump (up to 3× in the air)
Space Shoot (horizontal projectile, cooldown)
Escape Pause (Resume / Options / Menu / Quit)

After game

Key Action
R Instant restart (Game Over)
Escape Return to menu (Game Over)
Enter Confirm name after winning → back to menu

Gameplay

  • Starts at the main menu with animated parallax.
  • Campaign: 4 levels — clear all coins to advance; after level 4, win screen.
  • 3 lives — falling off-map, lava, or enemy/projectile hits cost a life (shield absorbs one enemy/projectile hit; does not protect from lava or pits).
  • Checkpoints soft-save position (pickups and kills stay).
  • Shield bubble pickups; active shield shows around the player and as [SHIELD] in the HUD.
  • Stars — optional secrets counted in the HUD.
  • Enemies patrol and shoot only when facing you. Level 4 has a mini-boss with an HP bar.
  • No lives → GAME OVER. YOU WIN → name → scores.json. Top 10 by time.

Main menu

Option Action
Start Start the campaign from level 1
Options Music / SFX volume (settings.json)
Best scores Top 10 from scores.json
Exit Close the game

HUD (top-left corner)

  • Coins: X / Y — coins on the current level
  • Level: N / 4
  • Lives: X (+ [SHIELD] when active) and Stars: N
  • Time: MM:SS
  • Top bars: shoot cooldown / i-frames; level 4 — boss HP

Scores (scores.json)

Created or appended after a win — one JSON object per line:

{"name":"Jan","time":"1:23","coins":15}

The coins field is the total coins collected in the finished campaign. The Top 10 screen loads the file on every open, sorts by time, and shows at most 10 entries.

Assets

The game does not crash on missing files — it can run without sound or without a given texture (e.g. enemies fall back to a simple colored rectangle if sprites fail to load).

Textures

Path Description
assets/textures/player_sheet.png Player spritesheet (9 cols × 3 rows, 80×110 px frames)
assets/textures/bg_clouds.png Parallax layer — clouds
assets/textures/bg_mountains.png Parallax layer — mountains
assets/textures/bg_trees.png Parallax layer — trees
assets/textures/parallax/l1_*.pngl3_*.png Background sets for levels 2–4 (Kenney Background Elements)
assets/textures/enemies/zombie_walk1.png, zombie_walk2.png Enemy walk animation frames (Kenney Platformer Characters)

Projectiles are drawn as a small rectangle (no dedicated texture).

Sound effects

Path Event
assets/sounds/jump.ogg Player jump
assets/sounds/coin.ogg Coin collected
assets/sounds/death.ogg Life lost / respawn
assets/sounds/gameover.ogg Game over
assets/sounds/shoot.ogg Projectile fired (Kenney Interface Soundspluck_001)

Music

Path When it plays
assets/music/menu.ogg Main menu (loop)
assets/music/gameplay.ogg Level 1 gameplay (loop)
assets/music/gameplay_l2.ogg Level 2 gameplay (loop)
assets/music/gameplay_l3.ogg Level 3 gameplay (loop)
assets/music/gameplay_l4.ogg Level 4 gameplay (loop)
assets/music/gameplay_l5.ogg Level 5 cave gameplay (loop)
assets/music/gameplay_l6.ogg Level 6 hell gameplay (loop)
assets/music/gameplay_l7.ogg Level 7 pre-finale gameplay (loop)
assets/music/gameplay_l8.ogg Level 8 boss arena (loop; currently same source as L7)
assets/music/gameover.ogg Game over screen
assets/music/win.ogg Win screen
  • menu.oggFuzzy, Was He? by Kistol (CC0, OpenGameArt)
  • gameplay.oggFeel Good Island Loop (CC0, OpenGameArt; orig. Brandon Morris)
  • gameplay_l2.oggCheesy Loop 1 by Tozan (CC0)
  • gameplay_l3.oggShort Plingy Loop by Fupi (CC0)
  • gameplay_l4.oggBackfoot by Centurion_of_war (CC0)
  • gameplay_l5.oggMysterious Cave Theme Loop by beardalaxy (CC0)
  • gameplay_l6.oggdark_forest_combat from Hell's God part 2 by Centurion_of_war (CC0)
  • gameplay_l7.ogg / gameplay_l8.oggToo Strong by Centurion_of_war (CC0)
  • gameover.ogg / win.oggKenney Music Jingles (CC0)

See assets/music/CREDITS.txt.

Font

Path Description
assets/fonts/Roboto-Regular.ttf HUD and UI font (Google Fonts, OFL)

Third-party note (Kenney)

Many assets credited to Kenney are CC0 (public domain). Parallax files under assets/textures/parallax/ come from Kenney Background Elements. See each pack’s License.txt for details.

Directory structure

.
├── CMakeLists.txt
├── README.md
├── assets/
│   ├── fonts/
│   │   └── Roboto-Regular.ttf
│   ├── music/
│   │   ├── menu.ogg
│   │   ├── gameplay.ogg
│   │   ├── gameover.ogg
│   │   └── win.ogg
│   ├── sounds/
│   │   ├── jump.ogg
│   │   ├── coin.ogg
│   │   ├── death.ogg
│   │   ├── gameover.ogg
│   │   └── shoot.ogg
│   └── textures/
│       ├── player_sheet.png
│       ├── bg_clouds.png
│       ├── bg_mountains.png
│       ├── bg_trees.png
│       ├── parallax/
│       │   ├── l1_far.png … l1_near.png
│       │   ├── l2_far.png … l2_near.png
│       │   └── l3_far.png … l3_near.png
│       └── enemies/
│           ├── zombie_walk1.png
│           └── zombie_walk2.png
├── docs/
│   ├── README.md
│   ├── screenshots/    # current gameplay captures (README gallery)
│   ├── architecture.md
│   ├── CHANGELOG.md
│   ├── release_checklist.md
│   ├── specs/          # speki A+B (11–19) + CDEG (20+)
│   └── prompts/        # prompty Cursor (implement / review / batch)
└── src/
    ├── main.cpp
    ├── Game.h / Game.cpp
    ├── Player.h / Player.cpp
    ├── Platform.h / Platform.cpp
    ├── Coin.h / Coin.cpp
    ├── Level.h / Level.cpp
    ├── Enemy.h / Enemy.cpp
    ├── Projectile.h / Projectile.cpp
    ├── Animator.h / Animator.cpp
    ├── AudioManager.h / AudioManager.cpp
    └── ParallaxLayer.h / ParallaxLayer.cpp

Visual polish specs (A+B), next wave (C/D/E/G), and Cursor prompts: docs/README.md. Architecture: docs/architecture.md. Changelog: docs/CHANGELOG.md.

Class architecture

Class Responsibility
Game Game loop, states (MENU/PLAYING/GAME_OVER/WINNING/SCORES), HUD, music, parallax, level campaign, projectiles, scores
Player Physics, input, animations, sprite, lives
Level Loading platforms, coins, enemies; player collisions
Platform Platform collision rectangle
Coin Coin — position and collected state
Enemy Enemy — patrol, drawing / animation
Projectile Player projectile — horizontal motion, collisions
Animator Spritesheet — animation frame management
AudioManager Loading and playing short SFX
ParallaxLayer Single background layer with parallax effect

License

The repository mixes original code with third-party assets, so the licensing is not uniform:

Part License
Source code (src/, CMakeLists.txt) MIT — Copyright (c) 2026 Wojciech Wypych (Iakirmon)
Textures, sounds and music from Kenney packs CC0 1.0 — public domain
assets/fonts/Roboto-Regular.ttf (Roboto 3.015) SIL Open Font License 1.1 — assets/fonts/OFL.txt
SFML zlib/png — external dependency, not part of this repository

MIT covers the code, not the assets. Roboto stays under OFL 1.1 and its license text is bundled with the repository, because OFL requires it on redistribution.


Wersja polska

Gra platformowa 2D w C++17 z biblioteką SFML 2.x. Gracz przechodzi kampanię ośmiu poziomów (krótki tutorial, dłuższe L5–L7, arena bossa L8), zbiera monety i sekretne gwiazdki, skacze (triple jump), strzela pociskami, unika lawy, wrogów i finałowego bossa (12 HP, 4 fazy ataków). Są checkpointy, tarcza (bańka), animacje, SFX, muzyka per poziom oraz parallax. Menu, pauza, opcje głośności, Top 10 i scores.json.


Zrzuty ekranu

Stan gry (sierpień 2026) — lawa, tarcze, gwiazdki, boss:

Poziom 1 — las Poziom 2 — pustynia
Poziom 1 Poziom 2
Poziom 3 — zamek Poziom 4 — noc / boss
Poziom 3 Poziom 4
YOU WIN — wpis nicku
YOU WIN

Wymagania

  • C++17
  • CMake >= 3.20
  • SFML 2.5+ (gałąź 2.x — nie 3.x)

Instalacja SFML

macOS (Homebrew)

brew install sfml

Linux (Debian/Ubuntu)

sudo apt install libsfml-dev

Windows (vcpkg) — instalacja krok po kroku

CMakeLists.txt zawiera ścieżki zakodowane na sztywno i oczekuje, że vcpkg znajduje się dokładnie w C:\game2d\vcpkg, a biblioteka SFML w C:\game2d\vcpkg\vcpkg_installed\x64-windows. Poniższe kroki tworzą dokładnie taki układ, więc projekt zbuduje się bez modyfikowania CMakeLists.txt.

1. Zainstaluj narzędzia. Pobierz i zainstaluj Visual Studio 2022 z zestawem „Desktop development with C++" (zawiera kompilator MSVC, CMake i Ninja) oraz Git for Windows.

2. Otwórz konsolę dewelopera. Z menu Start uruchom „Developer Command Prompt for VS 2022" (ma już ustawiony kompilator w PATH).

3. Zainstaluj vcpkg i SFML dokładnie w C:\game2d\vcpkg:

git clone https://github.com/microsoft/vcpkg C:\game2d\vcpkg
cd C:\game2d\vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg install sfml:x64-windows

4. Utwórz dowiązanie vcpkg_installed wymagane przez CMakeLists.txt (klasyczny tryb vcpkg instaluje do installed\, a projekt szuka w vcpkg_installed\):

mklink /J C:\game2d\vcpkg\vcpkg_installed C:\game2d\vcpkg\installed

5. Zbuduj grę (z katalogu projektu):

cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:\game2d\vcpkg\scripts\buildsystems\vcpkg.cmake
cmake --build build --config Release

CMake po zbudowaniu sam kopiuje folder assets/ oraz potrzebne biblioteki DLL SFML obok pliku .exe.

6. Uruchom grę:

cd build\Release
Platformer.exe

Budowanie (macOS / Linux)

mkdir build
cd build
cmake ..
cmake --build .

Plik wykonywalny: Platformer (Windows: Platformer.exe).
Folder assets/ jest kopiowany automatycznie do katalogu z binarką po każdym buildzie.


Uruchomienie

cd build
./Platformer        # macOS / Linux

Sterowanie

Menu główne

Klawisz / akcja Opis
/ Poruszanie po opcjach
Ruch myszy Podświetlenie opcji pod kursorem
Enter / LPM Wybór opcji

W grze

Klawisz Akcja
A / Ruch w lewo
D / Ruch w prawo
Skok (do 3× w powietrzu)
Spacja Strzał (pocisk poziomy, cooldown)
Escape Pauza (Wznów / Opcje / Menu / Wyjdź)

Po grze

Klawisz Akcja
R Natychmiastowy restart (Game Over)
Escape Powrót do menu (Game Over)
Enter Zatwierdź nick po wygranej → powrót do menu

Mechanika gry

  • Gra startuje w menu głównym z animowanym tłem parallax.
  • Kampania: 8 poziomów — L1 krótki tutorial; L7 kończy się bramą → L8 arena bossa; wygrana po pokonaniu finałowego bossa (monety na L8 opcjonalne).
  • Gracz ma 3 życia — wypadnięcie poza mapę, lawa lub kontakt z wrogiem / pociskiem wroga odejmuje życie (tarcza pochłania jeden cios od wroga/pocisku, nie chroni przed lawą i upadkiem).
  • Checkpointy — po śmierci wracasz na ostatni zapisany punkt (monety / gwiazdki / zabici wrogowie zostają).
  • Tarcza (bańka) — pickupy na mapie; aktywna tarcza widać wokół gracza i jako [SHIELD] w HUD.
  • Gwiazdki — opcjonalne sekrety; licznik w HUD.
  • Wrogowie patrolują; strzelają tylko gdy patrzą w stronę gracza. L8: finałowy boss (ectoplasm, 12 HP, spread / dash / pierścień pocisków, miniony nietoperzy); platformy w powietrzu na arenie.
  • Brak żyć → GAME OVER. YOU WIN → nick → scores.json. Top 10 sortuje po czasie.

Menu główne

Opcja Akcja
Start Rozpoczyna kampanię od poziomu 1
Opcje Głośność muzyki / SFX (settings.json)
Najlepsze wyniki Ekran Top 10 z scores.json
Wyjdź Zamknięcie gry

HUD (lewy górny róg)

  • Coins: X / Y — monety na aktualnym poziomie
  • Level: N / 4
  • Lives: X (+ [SHIELD] gdy tarcza aktywna) oraz Stars: N
  • Time: MM:SS
  • Paski u góry: cooldown strzału / i-frame; na poziomie 4 — HP bossa

Wyniki (scores.json)

Plik tworzony / dopisywany po wygranej — jeden wpis na linię:

{"name":"Jan","time":"1:23","coins":15}

Pole coins to łączna liczba monet zebranych w ukończonej kampanii. Ekran Top 10 wczytuje plik przy każdym otwarciu, sortuje po czasie i wyświetla maksymalnie 10 wyników.


Assety

Gra nie crashuje przy braku plików — działa bez dźwięku lub bez tekstury (np. wrogowie mają wtedy prosty kolorowy prostokąt zamiast sprite’u).

Tekstury

Ścieżka Opis
assets/textures/player_sheet.png Spritesheet gracza (9 kolumn × 3 wiersze, klatki 80×110 px)
assets/textures/bg_clouds.png Warstwa parallax — chmury
assets/textures/bg_mountains.png Warstwa parallax — góry
assets/textures/bg_trees.png Warstwa parallax — drzewa
assets/textures/parallax/l1_*.pngl3_*.png Zestawy tła pod poziomy 2–4 (Kenney Background Elements, m.in. pustynia / zamek / noc)
assets/textures/enemies/zombie_walk1.png, zombie_walk2.png Klatki animacji chodu wroga (Kenney Platformer Characters)

Pociski są rysowane jako mały prostokąt (bez osobnej tekstury).

Dźwięki SFX

Ścieżka Zdarzenie
assets/sounds/jump.ogg Skok gracza
assets/sounds/coin.ogg Zebranie monety
assets/sounds/death.ogg Utrata życia / respawn
assets/sounds/gameover.ogg Game over
assets/sounds/shoot.ogg Wystrzelenie pocisku (Kenney Interface Soundspluck_001)

Muzyka

Ścieżka Kiedy gra
assets/music/menu.ogg Menu główne (pętla)
assets/music/gameplay.ogg Poziom 1 (pętla)
assets/music/gameplay_l2.ogg Poziom 2 (pętla)
assets/music/gameplay_l3.ogg Poziom 3 (pętla)
assets/music/gameplay_l4.ogg Poziom 4 (pętla)
assets/music/gameplay_l5.ogg Poziom 5 — jaskinia (pętla)
assets/music/gameplay_l6.ogg Poziom 6 — piekło (pętla)
assets/music/gameplay_l7.ogg Poziom 7 — przed finałem (pętla)
assets/music/gameplay_l8.ogg Poziom 8 — arena bossa (obecnie ten sam utwór co L7)
assets/music/gameover.ogg Ekran game over
assets/music/win.ogg Ekran wygranej

Pliki muzyczne:

  • menu.oggFuzzy, Was He? by Kistol (CC0, OpenGameArt)
  • gameplay.oggFeel Good Island Loop (CC0, OpenGameArt; oryg. Brandon Morris)
  • gameplay_l2.oggCheesy Loop 1 by Tozan (CC0)
  • gameplay_l3.oggShort Plingy Loop by Fupi (CC0)
  • gameplay_l4.oggBackfoot by Centurion_of_war (CC0)
  • gameplay_l5.oggMysterious Cave Theme Loop by beardalaxy (CC0)
  • gameplay_l6.oggdark_forest_combat z Hell's God part 2 by Centurion_of_war (CC0)
  • gameplay_l7.ogg / gameplay_l8.oggToo Strong by Centurion_of_war (CC0)
  • gameover.ogg / win.oggKenney Music Jingles (CC0)

Szczegóły: assets/music/CREDITS.txt.

Czcionka

Ścieżka Opis
assets/fonts/Roboto-Regular.ttf Czcionka HUD i UI (Google Fonts, OFL)

Uwaga licencyjna (Kenney)

Wiele plików graficznych i dźwiękowych oznaczonych jako pochodzące z Kenney jest na licencji CC0 (domena publiczna). Tekstury parallax w assets/textures/parallax/ pochodzą z paczki Kenney Background Elements (Flat / PNG). Szczegóły w License.txt w paczce źródłowej.


Struktura katalogów

.
├── CMakeLists.txt
├── README.md
├── assets/
│   ├── fonts/
│   │   └── Roboto-Regular.ttf
│   ├── music/
│   │   ├── menu.ogg
│   │   ├── gameplay.ogg
│   │   ├── gameover.ogg
│   │   └── win.ogg
│   ├── sounds/
│   │   ├── jump.ogg
│   │   ├── coin.ogg
│   │   ├── death.ogg
│   │   ├── gameover.ogg
│   │   └── shoot.ogg
│   └── textures/
│       ├── player_sheet.png
│       ├── bg_clouds.png
│       ├── bg_mountains.png
│       ├── bg_trees.png
│       ├── parallax/
│       │   ├── l1_far.png … l1_near.png
│       │   ├── l2_far.png … l2_near.png
│       │   └── l3_far.png … l3_near.png
│       └── enemies/
│           ├── zombie_walk1.png
│           └── zombie_walk2.png
├── docs/
│   ├── README.md
│   ├── screenshots/    # current gameplay captures (README gallery)
│   ├── architecture.md
│   ├── CHANGELOG.md
│   ├── release_checklist.md
│   ├── specs/          # speki A+B (11–19) + CDEG (20+)
│   └── prompts/        # prompty Cursor (implement / review / batch)
└── src/
    ├── main.cpp
    ├── Game.h / Game.cpp
    ├── Player.h / Player.cpp
    ├── Platform.h / Platform.cpp
    ├── Coin.h / Coin.cpp
    ├── Level.h / Level.cpp
    ├── Enemy.h / Enemy.cpp
    ├── Projectile.h / Projectile.cpp
    ├── Animator.h / Animator.cpp
    ├── AudioManager.h / AudioManager.cpp
    └── ParallaxLayer.h / ParallaxLayer.cpp

Speki polishu wizualnego (A+B) i kolejna fala (C/D/E/G) oraz prompty Cursor: docs/README.md. Architektura: docs/architecture.md. Changelog: docs/CHANGELOG.md.


Architektura klas

Klasa Odpowiedzialność
Game Pętla gry, stany (MENU/PLAYING/GAME_OVER/WINNING/SCORES), HUD, muzyka, parallax, kampania poziomów, pociski, wyniki
Player Fizyka, input, animacje, sprite, życia
Level Ładowanie platform, monet i wrogów, kolizje gracza
Platform Prostokąt kolizyjny platformy
Coin Moneta — pozycja, stan zebrania
Enemy Wróg — patrol, rysunek / animacja
Projectile Pocisk gracza — ruch poziomy, kolizje
Animator Spritesheet — zarządzanie klatkami animacji
AudioManager Ładowanie i odtwarzanie krótkich SFX
ParallaxLayer Jedna warstwa tła z efektem paralaksy

Licencja

Repozytorium łączy kod własny z zasobami z zewnątrz, więc licencja nie jest jednolita:

Część Licencja
Kod źródłowy (src/, CMakeLists.txt) MIT — Copyright (c) 2026 Wojciech Wypych (Iakirmon)
Tekstury, dźwięki i muzyka z paczek Kenney CC0 1.0 — domena publiczna
assets/fonts/Roboto-Regular.ttf (Roboto 3.015) SIL Open Font License 1.1 — assets/fonts/OFL.txt
SFML zlib/png — zależność zewnętrzna, nie jest częścią repozytorium

MIT obejmuje kod, nie zasoby. Czcionka Roboto pozostaje na OFL 1.1, a jej tekst licencji jest dołączony do repozytorium, bo OFL wymaga tego przy redystrybucji.


About

2D SFML/C++17 platformer — 4-level campaign with coins, lava, checkpoints, shield, and boss

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages