Skip to content

ewhx-dev/Lite2D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Lite2D — Simple, Beginner-Friendly C++ 2D Game Engine

License: MIT C++ Standard

Lite2D is a compact, easy-to-understand 2D game engine written in modern C++ (C++17) using SDL2.
Designed for learning and quick prototyping: no advanced IT skills required.


⚡ Quick Start (Linux / macOS / Windows)

  1. Open a terminal (or PowerShell on Windows).
  2. From the project folder:
    mkdir -p build && cd build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    cmake --build . --config Release
  3. Run the executable:
    • Linux / macOS:
      ./lite2d
    • Windows (PowerShell):
      .\Release\lite2d.exe

If you prefer a single copy-paste on Linux:

git clone <repo> && cd Lite2D && mkdir build && cd build && cmake .. && cmake --build . && ./lite2d

🧰 Prerequisites

  • C++ compiler supporting C++17 (GCC, Clang, MSVC)
  • CMake >= 3.10
  • SDL2 development libraries

Quick install examples:

  • Ubuntu / Debian:
    sudo apt update
    sudo apt install build-essential cmake libsdl2-dev
  • Fedora:
    sudo dnf install gcc-c++ cmake SDL2-devel
  • macOS (Homebrew):
    brew install cmake sdl2
  • Windows:
    • Use vcpkg: vcpkg install sdl2 and pass -DCMAKE_TOOLCHAIN_FILE=.../vcpkg.cmake to CMake.

✨ Highlights & Features

  • Minimal ECS-ish design (Entity + Components)
  • Delta-time movement for smooth, frame-rate independent motion
  • Simple rendering of colored rectangles using SDL2
  • Basic collision detection and bounce response
  • Easy configuration: background color and FPS via Engine API
  • Beginner-friendly sample entities (Player, Enemy, Obstacle)

🧭 Controls & Behavior

  • Close window or press ESC to exit.
  • Sample entities demonstrate movement, wrapping at screen edges, and collisions.

🛠 Troubleshooting (common, simple fixes)

  • CMake reports "SDL2 not found":
    • Ensure libsdl2-dev (Linux) or sdl2 (Homebrew) is installed.
    • On Windows ensure CMake can find SDL2 or use vcpkg toolchain.
  • Runtime: missing SDL2 shared library (.so/.dll):
    • Linux: install SDL2 runtime or set LD_LIBRARY_PATH to the SDL2 location.
    • Windows: place SDL2.dll next to the executable or add its folder to PATH.
  • Build errors about C++ standard:
    • Ensure your compiler supports C++17. Add -std=c++17 if needed.

🗂 Project Structure (what to look at)

  • src/main.cpp — app entry and simple config
  • src/Engine.h / src/Engine.cpp — main loop, input, update, render
  • src/Entity.h — entity container
  • src/Components.h — transform, render, velocity, collider, tag
  • CMakeLists.txt — build configuration

To add or customize content (very simple):

  • Edit Engine::CreateEntities() to add new squares, colors, velocities.
  • Change background or FPS in main.cpp using engine.SetBackgroundColor(...) and engine.SetFPS(...).

🛠 How to Use It (easy steps for everyone)

This short guide shows the simplest ways to run, play with, and lightly customize Lite2D — no deep IT skills required.

  1. Run the app (already built)

    • From the project folder:
    • Or double-click the lite2d executable in your file manager (Linux) after building.
  2. Play

    • The window shows simple colored squares.
    • Close the window or press ESC to quit.
  3. Change the background color or FPS (no strong programming needed)

    • Open src/main.cpp in a text editor (VS Code, Notepad++, gedit).
    • Find these lines and change the numbers:
      engine.SetBackgroundColor(20, 20, 40); // r, g, b (0-255)
      engine.SetFPS(60);                     // frames per second
    • Save and rebuild:
      cd build
      cmake ..
      cmake --build .
      ./lite2d
  4. Add or edit a square (super simple)

    • Open src/Engine.cpp and find Engine::CreateEntities().
    • Copy one of the example entities and tweak values:
      auto myBox = std::make_unique<Entity>();
      myBox->transform = std::make_unique<TransformComponent>(100.0f, 120.0f, 40, 40); // x, y, width, height
      myBox->render = std::make_unique<RenderComponent>(255, 200, 0); // r, g, b (0-255)
      myBox->velocity = std::make_unique<VelocityComponent>(0.0f, 0.0f); // vx, vy (pixels/sec)
      myBox->tag = std::make_unique<TagComponent>("MyBox");
      entities.push_back(std::move(myBox));
    • Save, rebuild, and run to see the new square.
  5. Tweak movement without advanced code

    • velocity vx (positive = right, negative = left), vy (positive = down, negative = up).
    • Larger absolute numbers = faster movement.
  6. Remove an object without deleting code

    • Set visibility to false:
      entity->render->visible = false;
    • Or mark for deletion at runtime:
      entity->Destroy();
  7. If something goes wrong

    • Copy any terminal error and ask for help (paste the text).
    • For SDL2 missing errors, follow the Prerequisites section to install SDL2.

🤝 Contributing & Support

Contributions and questions are welcome. Suggested workflow:

  • Open an issue to discuss larger changes
  • Submit small, focused pull requests
  • Add comments for new logic and simple examples/demos

📄 License

MIT — see LICENSE file.

About

A modular C++ 2D engine demonstrating the Entity-Component-System (ECS) pattern.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors