Git Product home page Git Product logo

nasnas's Introduction

NasNas-logo

An intuitive and beginner friendly 2D game framework for C++.

FeaturesHow to buildGet StartedScreenshotsShowcaseSupport

NasNas is a lightweight cross platform modular 2D game framework.

It is entirely written in modern C++17, and uses SFML2 for rendering.

It provides a clean and easy to use API.

The framework is separated in multiple modules :

  • Core is the only non-optional module. It is needed to create a NasNas application. It contains core classes and data needed by the framework.
  • ECS is an efficient data driven Entity Component System. It allows you to attach components to entities and run systems on specific sets of components.
  • Reslib contains the resource manager and resource loader. It handles resource loading and accessing in an elegant way.
  • Tilemapping is a Tiled Map loader (.tmx). It seamlessly integrates with NasNas and speeds up development for tile based games.
  • Tween allows you to animate any object using the provided or custom easing functions.
  • UI contains the User Interface utilities. (WIP)
  • More modules will be developed in the future !
Click to see platforms support
Core Ecs Reslib Tilemapping Tween Ui
Windows ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Linux ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
MacOS ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Android ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
iOS

Features

Implemented :
  • Scene and Layers system
  • Cameras and Shaders
  • Application states (using StateStackApp or StateMachineApp)
  • Automatic resource loader and manager
  • Data oriented ECS inspired by entt with a bunch of provided components and defaults systems.
  • Tiled map loader (.tmx)
  • Text and bitmap fonts
  • Customizable Transitions
  • Flexible Tween and MultiTween utilities.
  • Extensible Particles system
  • Multi texture SpriteBatching
  • App configuration and settings
  • Debug text display in-game
  • Convenient console Logger
  • And more !
To do :
  • Menus and UI
Future :
  • Splash screens
  • Levels and game events management
  • In-game command line for debugging

You can find a global roadmap for the version 1.0 on the project board

Build

Desktop

Clone the repository.

git clone https://github.com/Madour/NasNas
cd NasNas

Then, you can build the static libraries with :

mkdir build && cd build
cmake ..
cmake --build . -j4

Finally, you can install those libraries using :

cmake --install .

Android

To build the framework for Android, please refer to the Android example's readme

Available CMake options :

  • -DNASNAS_BUILD_ECS=OFF to disable the ECS module

  • -DNASNAS_BUILD_RESLIB=OFF to disable the Reslib module

  • -DNASNAS_BUILD_TILEMAPPING=OFF to disable the Tilemapping module

  • -DNASNAS_BUILD_TWEEN=OFF to disable the Tween module

  • -DNASNAS_BUILD_UI=OFF to disable the UI module

  • -DNASNAS_EXAMPLES=ON to create the example applications targets

  • -DNASNAS_BUILD_SFML=ON to download and build SFML inside the project (enabled automatically if SFML package is not found)

  • -DNASNAS_STATIC_VCRT=ON to link the Visual C++ runtime statically (/MT) when using the Microsoft Visual C++ compiler

Get Started

Here is a sample code using NasNas framework, this will create a 720x480 window and log a string to the console :

#include <NasNas/Core.hpp>

class Game : public ns::App {
public:
    Game() : ns::App("My game", 720, 480) {
        ns_LOG("Created a NasNas app !");
    }
    void onEvent(const sf::Event& event) override {
        if (event.type == sf::Event::Closed)
            getWindow().close();
    }
    void update() override {}
};

int main() {
    Game g;
    g.run();
    return 0;
}

An introduction tutorial to learn how to use the framework can be found on the wiki.

Documentation can be found here.

You can also check examples source code for a small overview of what you can do with the framework.

Screenshots

All of these programs source code can be found in the examples folder.

Split View

2021-09-02_12-15-46

Line paint

2021-09-02_12-17-09

Tweening

2021-09-02_12-17-56

Animated sprites

animated_sprites-d_zZDAUUAIOb

Particles System

particles.mp4

Parallax platformer demo game

Desktop
platformer2.mp4
Android
platformer_android.mp4

Showcase

Games

The following games were created with NasNas :

  • Warp Runner on itch (Desktop)
  • History Leaks on itch and github (Desktop)
  • Cyber Slayer on github (Desktop and Android)

Other

A simple physics engine made with NasNas only
2021-07-14_21-06-10.mp4

Support

If you like the project, please consider starring this repository.

If you would like to discuss anything about the project, feel free to open a new discussion.

Author

  • Modar Nasser

nasnas's People

Contributors

madour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nasnas's Issues

ns::android::showToast crash

Calling ns::android::showToast from main will cause crash with exception : "Can't toast on a thread that has not called Looper.prepare()" (here). This happens because the main thread looper is not found (I think ?) when creating the Toast message.

Attempted to use the ALooper solution with no success because we don't have access to the main thread from the SFML Activity unfortunately.

In fact, SFML sets the looper from initializeMain which is called from the custom android main, which itself is ran in new thread.

Possible Solution : access main looper from Java's static method Looper.getMainLooper and then make the JNI showToaster call from there.

The other solution would be to completely replace sfml-activity by nasnas-activity and call ALooper_prepare from the activity main thread, and setup a pipe to communicate with it.

Error when trying to compile on raspbian...

I tried to use it on my Raspberry Pi 3B+ using Raspbian Buster, but got the following error when trying to compile:

Scanning dependencies of target NewProject
[  2%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/data/AppComponent.cpp.o
[  5%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/data/Config.cpp.o
[  8%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/data/Arial.cpp.o
[ 10%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/data/Maths.cpp.o
[ 13%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/data/Shapes.cpp.o
[ 16%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/data/ShaderHolder.cpp.o
[ 18%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/App.cpp.o
[ 21%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/Scene.cpp.o
[ 24%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/Layer.cpp.o
[ 27%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/Camera.cpp.o
[ 29%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/Window.cpp.o
[ 32%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/Anim.cpp.o
[ 35%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/Spritesheet.cpp.o
[ 37%] Building CXX object CMakeFiles/NewProject.dir/src/NasNas/core/BitmapText.cpp.o
/home/pi/MeinOrdner/c++/CppGames/NasNasGame-1/src/NasNas/core/BitmapText.cpp: In member function ‘void ns::BitmapText::processString()’:
/home/pi/MeinOrdner/c++/CppGames/NasNasGame-1/src/NasNas/core/BitmapText.cpp:168:27: error: ‘strtok’ is not a member of ‘std’
         auto* word = std::strtok(str.data(), " ");
                           ^~~~~~
/home/pi/MeinOrdner/c++/CppGames/NasNasGame-1/src/NasNas/core/BitmapText.cpp:168:27: note: suggested alternative: ‘sort’
         auto* word = std::strtok(str.data(), " ");
                           ^~~~~~
                           sort
/home/pi/MeinOrdner/c++/CppGames/NasNasGame-1/src/NasNas/core/BitmapText.cpp:171:25: error: ‘strtok’ is not a member of ‘std’
             word = std::strtok(nullptr, " ");
                         ^~~~~~
/home/pi/MeinOrdner/c++/CppGames/NasNasGame-1/src/NasNas/core/BitmapText.cpp:171:25: note: suggested alternative: ‘sort’
             word = std::strtok(nullptr, " ");
                         ^~~~~~
                         sort
make[2]: *** [CMakeFiles/NewProject.dir/build.make:232: CMakeFiles/NewProject.dir/src/NasNas/core/BitmapText.cpp.o] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/NewProject.dir/all] Fehler 2
make: *** [Makefile:84: all] Fehler 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.