Spaghetti engine is an open source personal project 2D game framework, and its main purpose is wrapping the low level libraries used into a more human friendly programming environment
Its dependencies are:
Every dependency is included in the pom.xml file
Spaghetti engine features:
- Asset import system (models, textures, shaders, and custom asset types too)
- Multithreaded asset manager and loader~~~~
- Levels, game components and game objects framework
- Highly customizable and easy to use networking support
And you can do the following with it
- Render 3d models with materials
- Use the input system to control a player
- Use the event system to easily dispatch custom events across the level and network
- Easily manage networking for multiplayer
- (WIP) Switch between TCP and UDP protocols without changing a line of code
- Run servers
- Physics
- Play sounds and music
- Microphone input
Requires the following commands installed on your system:
- javac (Windows: Website - Linux:
sudo apt install openjdk-8-jdk
) - git (Windows: Website - Linux:
sudo apt install git
) - mvn (Windows: Website - Linux
sudo apt install maven
)
First clone this repository to a folder of your choice
cd MyFolder
git clone https://github.com/bohdloss/SpaghettiEngine.git
Then cd into the project directory
cd SpaghettiEngine/SpaghettiEngine
Compilation:
mvn clean compile
To compile only the source filesmvn clean package
To compile the source files to a jar filemvn clean compile assembly:single
To compile the source files to an executable jar file with dependencies included
This will create a new folder called target
which contains the compiled files
Alternatively you can:
- Compile and run directly with the
make-and-run
script - Compile only with the
make
script - Run only with the
run
script
First step necessary to do anything else
The code is:
// Initialize Game
Game.initialize();
// Initialize an instance
GameBuilder builder = new GameBuilder();
builder.enableRenderer();
builder.enableUpdater();
Game myGame = builder.build();
// Set the gamemode to the demo mode (or your own one)
GameState state = game.getGameState();
state.setGameMode(new DemoMode(state));
// Start game threads (will initialize the provided components)
myGame.beginAsync();
Game.idle();
You will need to create a new GameMode
class and put your initialization code inside
public class MyGameMode {
private Level myLevel;
private Mesh myMesh;
protected void initialize0() {
// Abort the initialization in multiplayer unless we are the server
if (!getGame().hasAuthority()) {
return;
}
// Create a new Level
myLevel = getGame().addLevel("myLevel");
// Set the level as the active one
getGame().activateLevel("myLevel");
/*
* You will need a Camera to render the scene
*/
Camera camera = new Camera();
/*
* Create a mesh to place in the level
* You will have to provide a Model and a Material too
*/
myMesh = new RotatingMesh(Model.get("apple_model"), Material.get("apple_mat"));
// Add our objects to the level
myLevel.addObject(camera);
myLevel.addObject(mesh);
// Now the Renderer will use this camera to render the scene
getGame().setLocalCamera(camera);
}
}
This will create a Camera to render your scene and a Mesh to be rendered
To rotate the mesh, write the following class to extends the Mesh class:
public class RotatingMesh {
// Store the rotation
private float i;
@Override
public void commonUpdate(float delta) {
super.commonUpdate(delta);
// Multiply by delta to rotate at a constant speed
i += 0.05 * delta;
// Change the rotation
setPitch(i);
}
}
All the following code can be found in the demo package of this repository (com.spaghetti.demo
)
To understand how to actually import your assets read the next example
Spaghetti engine offers a dynamic asset import system: all you have to do is specify the assets to import in a .txt
file!
By default, the file /res/main.txt
will be searched for asset import
Each line in the file indicates a different asset
Lines that are empty or start with // will be ignored
Each word in a line, separated by 1 space, indicates the following:
- First word: asset type (choose between - VertexShader / FragmentShader / ShaderProgram / Material / Texture / Model / Sound / Music)
- Second word: asset name
- All the other words are arguments
Here is the full documentation for the arguments that are needed for each asset type:
- VertexShader / FragmentShader
- Shader location
- ShaderProgram
- List of names of Shader-assets
- Material
- Name of a Texture-asset
- Name of a ShaderProgram-asset
- Texture
- Texture location
- (Optional) Texture filtering mode (linear / nearest)
- Model
- Model location
- Operation type (find to search for a specific model in the specified file / unify to merge all models found into one)
- (Optional) If operation type is 'find' specify the mesh to search for
- Sound
- Sound location
- Music
- Music location
The difference between sound and music is that when played music is being streamed, while a sound is fully loaded into memory beforehand. Use Sound for relatively short audio files and Music for long ones. Please note that streaming from disk might have a performance impact.
This .txt
file type is referred to as the "Asset Sheet" inside the AssetManager