The gamnit framework is split in two main API, each with their specialty but both are fully compatible.
Import gamnit::flat
to create a 2D game or app.
It provides a simple API centered on Sprite
and Texture
.
Setup the game in create_scene
and update the game logic in update(dt)
.
import gamnit::flat
redef class App
# Load a texture from the assets folder
var texture = new Texture("fighter.png")
redef fun create_scene do
# Add a sprite to the visible world
var sprite = new Sprite(texture, new Point3d[Float])
sprite.scale = 2.0
sprites.add sprite
end
redef fun update(dt) do
# Rotate all sprites at 180° per second
for sprite in sprites do
sprite.rotation += dt * pi
end
end
end
Go beyond the flat API by importing gamnit::depth
.
It provides 3D Actor
with their shape set by a Mesh
and their color by a Material
.
You can create Material
subclasses to define your own shaders.
# Load a 3D model from the assets folder
var tree = new Model("tree.obj")
# Or create a simple blue cube
var cube = new LeafModel(new Cube, new Material)
# Create a 3D actor
var actor = new Actor(tree, new Point3d[Float])
app.actors.add actor
Sound
, Music
and BMFont
.gamnit::virtual_gamepad
.gamnit::network
.android::vibration
.serialization
, json
and msgpack
.gamnit is a work in progress, there are still bugs and missings features. Currently, there is a known bug preventing the draw of 3D objects on iOS and Windows, a fix is on the way.
Already a few games show off what gamnit can do!
Simple version of a classic, with a clean separation of the game and display logic using Nit's class refinement.
Rocket jump from tower to tower in this first person shooter, with multiplayer support and custom OpenGL ES calls.
Display 3D models from local assets or from a path passed as command line argument, useful to debug model loading.
Puzzle platformer with four levels, a nice story, nacho chip enemies and avocado throwing physics.
Ridiculous platformer action shooter game with some 3D elements and moving platforms.
We document here how to target GNU/Linux, Android and iOS. The macOS desktop is not supported as a target at this time.
Windows desktop is supported using msys2, follow the Windows guide, then install required packages.
To compile Nit tools and gamnit apps, install all the required packages with the following command (for Debian and Ubuntu):
sudo apt-get install build-essential ccache libgc-dev \
graphviz libunwind-dev pkg-config libgles2-mesa-dev \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev inkscape
Clone the Nit repo, compile the Nit tools and configure your environment:
git clone https://github.com/nitlang/nit.git
cd nit
make
. misc/nit_env.sh install
Test your installation with Asteronits for the desktop:
cd contrib/asteronits
make
bin/asteronits
To compile for Android, you will need to install the SDK and NDK, set the
ANDROID_HOME
environment variable and install OpenJDK 8. See the detailed host system setup guide for Android targets.
Make sure to install Xcode and launch it once to accept the license agreement.
Then install brew
and use it to install the required packages with the following command:
brew install ccache bdw-gc libunwind-headers pkgconfig \
graphviz ios-sim
Clone the Nit repo, compile the Nit tools and configure your environment:
git clone https://github.com/nitlang/nit.git
cd nit
make
. misc/nit_env.sh install
Test your installation by compiling Asteronits for iOS:
cd contrib/asteronits
make ios
ios-sim launch --devicetypeid "iPhone-8, 11.2" \
bin/asteronits.app
To create your own project, copy and rename the template project:
cp -r lib/gamnit/examples/template my_game
cd my_game
mv src/template.nit src/my_game.nit
find -type f -exec sed -i -e s/template/my_game/g {} \;
On GNU/Linux, compile and run for the desktop:
nitc src/my_game.nit -m linux
./my_game
Compile for Android and install on a device:
nitc src/my_game.nit -m android -o my_game.apk adb install my_game.apk
Compile for iOS from macOS and launch in the simulator:
nitc src/my_game.nit -m ios -o my_game.app --compile-dir out ios-sim launch --devicetypeid "iPhone-8, 11.2" my_game.app
To run on a physical device, compile the generated C code with Xcode:
open -a xcode out/ios/my_game_m_ios.xcodeproj
Modify this project and build upon it!
App
.update
.depth
API.package.ini
before publishing.The development of gamnit is guided by a philosophy placing coding and efficiency first.
Start coding using the flat 2D API to create a prototype and gradually introduce advanced features with the depth 3D API. Additional modules offer solutions to common needs.
The underlying OpenGL ES 2.0 can be accessed by writing shaders in custom materials, or by refining drawing methods and adding custom Nit or C code.
Built on OpenGL ES 2.0, apps are portable to GNU/Linux, Android and Windows. Beyond the prototype, apps can be adapted to each platform using their native languages nested within Nit modules.
The gamnit project and Nit language are free software published under Apache 2.0. We encourage you to read the source code, modify it and share your improvements.