Skip to content

Repository files navigation

sunlight

sunlight logo

CI Latest release License: zlib

sunlight is an open source library written in C++ to make 2D games. Overall, its present main features include a manager that can deal with map, collision, sprites and graphic primitives.

raylib was used for graphic backend, but the project aims to be extended to SDL and many others. Rendering is exposed through an IEngine interface (src/engines/) so a new backend only needs its own implementation plus one line in the engine factory, without touching the rest of the codebase.

Table of Contents 📌

Requirements 📝

In order to make sunlight run as desired, it is necessary to install the dependencies listed below beforehand:

CMake 3.24

You may install the package on its official page. Higher versions are also supported.

  • For Linux

    Ubuntu/Debian users can install the package by using the command apt-get on their Linux shell.

    It is also recommended to install by using the standard package manager offered by your prefered distro.

  • For MacOS

    Mac users may obtain the package through MacPorts or Homebrew.

vcpkg (Windows only)

Use vcpkg to integrate C/C++ libraries using Visual Studio.

LibXML2

By default, the project's CMakeLists will automatically search LibXML and its dependencies (LibIconv). For those who might want to use the library installed on your system, the following parameter should be used to call CMake:

cmake -DUSE_LOCAL_LIBXML2

zlib

zlib can be installed by using your standard package manager.

The installation steps for which OS are listed below.

  • Ubuntu/Debian family
apt-get install zlib1g-dev
  • Windows (vcpkg)
.\vcpkg\vcpkg install zlib:x64-windows

PhysFS

PhysFS backs sunlight's virtual filesystem (mounting a loose directory or an archive so every resource read — textures, sound, tilemaps — goes through one path space). Like LibXML2/tmx/raylib, it is fetched and built automatically via FetchContent; no separate install is required.

raylib dependencies on Linux

You may find the detailed instructions by clicking here and following the steps regarding the operational system you're using.

HowTo 💡

Using samples

By default, sunlight doesn't build the projects' samples.

In order to make it compile with samples, it is necessary to open the CMakeLists on the project's root to change the option from OFF to ON, as shown below:

option(BUILD_LIBRARY_SAMPLES "Build SunLight library samples" ON)

Note

You may also use the following command line on your system's shell:

cmake -DBUILD_LIBRARY_SAMPLES=ON

Running tests

Unit tests are also opt-in, using doctest fetched automatically via CMake:

cmake -DBUILD_LIBRARY_TESTS=ON
cmake --build build --target sunlight_tests
./build/tests/sunlight_tests

Note

You may also run the tests through CTest:

ctest --test-dir build

Configuring VsCode

If you intend to use VsCode as your IDE, follow the instructions shown here.

Samples ☀️

Each sample takes its own directory as argv[1] and resolves its resources relative to it, e.g.:

./build/samples/sprite/sprite_test samples/sprite/
  • tilemaprenderer — the minimal setup: loads a Tiled map and drives the renderer's camera/zoom, no sprites.
  • sprite — builds on tilemaprenderer by adding an animated Sprite on top of the map.
  • collision — builds on sprite by making the sprite player-controlled and colliding it with a static obstacle via CollisionManager.
  • gamepad — builds on collision by giving two independent characters their own controller: one gamepad's left stick/DPad drives Sunny, the right stick/face buttons drive a second sprite.
  • scriptprocessor — a scripted "stage intro" cutscene demonstrating ScriptProcessor: queued commands load a stage, slide sprites on screen, and play/pause/resume a tone via SoundManager, exercising every control-flow command (WAIT_CMD, WAIT_SPRITES_QUEUE_EMPTY, LOOP_CMD/END_LOOP_CMD, LABEL_CMD/GOTO_LABEL_CMD).
  • multiview — the same map and the same character shown in three places at once (a main view, a minimap, and a zoomed close-up that follows the character), demonstrating sunlight's multiple views (TileMapRenderer::CreateView) and world-space sprites (Sprite::SetWorldSpace).

About

Sunlight is an open source multi-platform game library written in C++ ready for use to develop 2D games

Topics

Resources

Contributing

Security policy

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages