LionEngine - The Web Site

Tutorial

Introduction

This tutorial will show you how to create a prototype of Mario by using entirely the LionEngine, both its core library and the provided editor. Here are the main steps:


Project setup

To make a game, you may need some graphics resources. For this time, they are gracefully provided here: Resources. You will find the entities graphics, a level rip, music and sounds. If you don't know how to start with the LionEngine, follow the installation page:

Getting started

Once your project is ready, you should have something like this: code


Import the project in the editor and prepare game resources

Start now the editor (download the release depending of your system), and import your project with the following configuration (files/import):

Click Finish and the project tree should now display your project as root.

You can now start to extract the tiles from the level rip provided in the resources, by clicking on the top-right world view tool bar.

You will then find two generated files in resources/map/: sheets.xml and 0.png. This is our tile sheets !

You must now define tile groups. Click map/edit tiles groups. Add a group called block, select-it, and clic on tiles which should support collision with player. Click finish.

Groups

Import a map from a level rip (top-right world view tool bar), select the resources/map/level.png rip, and as you used the default name for tilesheet and groups, it should auto fill the two other fields. Accept. You should now can see the map inside the editor, and navigate with keyboard arrows keys.

World

Right click on resources/map and Add formulas (with default name). Add 4 formulas : top, bottom, right, left. Use existing models for each of them. Finally, define the constraint block for each element (top -> NORTH, bottom -> SOTH, left -> WEST, right -> EAST). This mean that top can't have a block over it...

Formulas

Right click on resources/map and Add collisions (with default name). Add a collision block pointing to 4 formulas : top, bottom, right, left.

Collisions

You can now minimize the editor, and go back to you code, in order to import you ready to use map as a level file:

private static void importAndSave()
{
    final MapTile map = new MapTileGame();
    map.create(Medias.create("map", "level.png"));
    try (FileWriting file = Stream.createFileWriting(Medias.create("map", "level.lvl")))
    {
        map.save(file);
    }
    catch (final IOException exception)
    {
        Verbose.exception(exception, "Error on saving map !");
    }
}

Add a WorldGame to handle easily the map, like this: code


Gameplay implementation

Add an ObjectGame class called Mario, with a basic implementation, such as here: code

Gameplay starts here:

@Override
protected void onPrepared()
{
    StateAnimationBased.Util.loadStates(MarioState.values(), factory, this);
    handler.start(MarioState.IDLE);
    handler.addInput(keyboard);
}

Gameplay states can be easily defined with this class: code

Their implementations must define a routine, and possible transitions betweens states.

Go back to the editor, and right click on the entity folder node in the project view, and click Add object called Mario.

Select Mario.xml, and double click on the Class property, and choose your class (Mario). Choose also SetupSurface for the Setup property. Right click in the properties view to Define surface. Select the Mario.png sprite image. Right click again to define the Frames (7 horizontals and 1 verticals).

Activate now the Animations and edit them by double clicking on the node. Add the Mario animations (idle, walk, turn, jump, die), and save.

You should now see something like this:

Gameplay

Global code: code


Finishing with music and sound

Refactor your Mario class by adding an Entity class before, so that Mario will only contains the specific player code, and you will be able to add a Goomba class. Add also its object descriptor, animations... Create its specific Die state.

Check the Collidable trait to handle collision between objects.

Add an SFX class handler to play sounds with ease: code.

Update the State implementation to play sounds at the right time (on jump...).

Start the music once level is loaded.

You should now see something like this:

Finishing

Global code: code


Go to top
LionEngine - The Web Site ©2014 - 2016
Byron 3D Games Studio