FS-GameCreator, a JMonkeyEngine based EntitySystem

Well, I finally did it. I uploaded my code as a community plugin.
The plugin I made is sort of a game creator. It’s the toolset I use to build my own little game, but it should be flexible enough to support other games as well. It uses an Entity System, so adding different game logic to support different game types shouldn’t be that hard, just add a different Entity Control and you have a new behaviour.

At the moment, there is top-down movement. This movement is restricted to the viewport, but within that restriction you can move forward, backwards, turn left, turn right, strafe left and strafe right. This is the movement I needed for my own game, which is why it’s the first one I did.
Aside from the movement, you can shoot and there’s a rudimentary AI in there as well already.

The GameCreator currently consists of 3 different community plugins. The main one is the libraries plugin, FS-GameCreator-Libraries. This one contains both the plugin dependencies used by the other two plugins as well as a global library you’d need to add to your own game project to be able to use the GameCreator.
The second plugin is the FS-GameCreator-TemplateEditor. This plugin is used to edit the JSON formatted Entity Templates. An Entity Template is basically a blueprint for an Entity. I currently have one w hich describes a spaceship, so it contains the RenderComponent to tell me what model to load, the CanMoveComponent to tell me the movement characteristics, etc. Editing this JSON file by hand, while doable, is error prone and becomes increasingly difficult as more components come into play. So I setup a GUI for that. This plugin also contains code which ties into the JME Scene Editor. It allows for adding Entity Templates directly to a scene. When a template is added to a scene, it checks for the RenderComponent. If it can find one, it will render the model in there. If it can’t fine one, it will render a placeholder instead, making the node at least visible in the editor.

The third and final plugin is the FS-GameCreator-AiScriptEditor. This plugin is similar to the second one in that it is a GUI for editing a JSON file. This time however the JSON file is an AI script. The AI system uses a block based approach. Each AI block contains a specific set of AI logic. Each block has one entry point, one or more exit points and can be configured either from the scipt or from code. By chaining these blocks together you get the actual script. Currently there is a RangeTrigger, Spawn, Approach, Shoot, Timer and SubScript block. The SubScript block allows for running multiple scripts in parallel. I personally use this one to have the Approach and Shoot subscripts run at the same time so the NPC will follow the player and shoot at him.

Since I started with the libraries plugin, this one is in the most advanced state, call it Beta 2. The Template Editor plugin is also coming along nicely and is probably nearing Beta. The AI Script Editor however is the newest addition. As such it is still in early Alpha and as such is subject to weird behaviour, like menu items showing up in the wrong places.

Now, that’s most of the current features in there. There are loads more planned of course. But to figure out which ones I need to focus on first, I could use some input.
Personally, I was thinking on spanding more time on the AI Script Editor plugin first. Get that one at least to a stable Beta phase, along with the Template Editor Plugin. But if anyone has a a better suggestion, I’m all ears. Eventually, this thing should be able to support a few basic game types with standard configured setup with regards to which Entity Controls / Entity Components to start with. But that’s a long way off still.

Oh yeah, and I’d appreciate any and all offers of help as well, to get this thing to the point where it is actually useasble by as many as possible as soon as possible.

As I mentioned in the thread below, here’s a list of the currently planned features. As always, if you have anything to add, or any priority you would like to see them build, let me know and I’ll see what I can do

  1. Project Plugin. This plugin would have wizards for the various parts:
    1. Game Project wizard, depending on selected features, you would get a skeleton game project with all the EntityComponents and EntityControls setup for you.
    2. EntityComponent wizard, Since the EntityComponents have some meta data to make them play nice with the various plugins it would be nice to have a wizard here as well
    3. EntityControl wizard, Sets up the basic structure of an entity control.
    4. AIComponent wizard, similar to the EntityComponent wizard, but for the AI.
    5. AiControl wizard, similar to the EntityControl wizard but for the AI
  2. Particle effects, it would be nice to be able to add particle effect. For example when you blow stuff up
  3. Shaders, those are always nice.
  4. Light sources, currently light sources are added directly to the scene. I would like to have these as entities as well. This makes working with them from within the system a lot more logical
  5. AI-Editor canvas, seeing how the AI system is basically a block based system where you add logical blocks together to form the scripts this should lend itself perfectly for a canvas based editor. This would make the AI editor a lot more user friendly
  6. Tutorials explaining the various parts of the game creator
1 Like

Hey there, just a quick update, and request.
I’ve been steadily working on the plugins and library. But what I really need is a game which uses the Entity System. While I have a small test game already, I find I am hard pressed to find the time needed to get both the game and the game creator done with the speed I’d like. So, for the game, I am reaching out to you guys. Is there someone out there willing to put in a bit of time to see if they can get a game build with my game creator / entity system?

I would really appreciate someone getting in on this, since it would get me some much needed input from a new and different perspective of what is missing and needs to be added firdst to get this thing to the level is should be.

Oh, for my current test game, you can look at: http://ractoc.com/ForgottenSpace. There’s some zip files there for windows, linux and mac. I’ve only got a windows machine here, so I’ve only been able to test that one though.

For the test game, the actual code is very limited. Aside from the code for the starfield it’s just one small class, as shown in the listing below:

public class Main extends SimpleApplication {

    private static Entities entities = Entities.getInstance();

    public Main() {
        super((AppState) null);
    }

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        rootNode.addLight(new DirectionalLight());

        setupKeys();
        setupEntitySystem();
        setupAppStates();
        setupCamera();
        setupStarField();
        spawnPlayer();
    }

    private void setupStarField() {
// this function add the starfield and had nothing to do with the actual entity system
    }

    private void setupCamera() {
// this function sets up the camera and had nothing to do with the actual entity system
    }

// add the player to thge entity system as an entity based on a template
    private void spawnPlayer() {
        EntityTemplate template = (EntityTemplate) assetManager.loadAsset("/Templates/Entity/BasicShipTemplate.etpl");

        if (template.getComponents() != null && template.getComponents().size() > 0) {
            EntityComponent[] components = (EntityComponent[]) template.getComponentsAsArray();
            Entity entity = entities.createEntity(components);
            entities.addComponentsToEntity(entity, new LocationComponent(Vector3f.ZERO, new Quaternion(), new Vector3f(1, 1, 1)), new ControlledComponent(), new BoundedEntityComponent());
        } else {
            throw new ParserException("No components for template /Templates/Entity/BasicShipTemplate.etpl");
        }
    }

// register all the required components for the game.
    private void setupEntitySystem() {
        TemplateLoader.setClassLoader(this.getClass().getClassLoader());
        assetManager.registerLoader(TemplateLoader.class, "etpl", "ETPL");
        assetManager.registerLoader(AiScriptLoader.class, "ais", "AIS");

        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          AiComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          BoundedEntityComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          CanMoveComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          ControlledComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          DamageComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          HasFocusComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          LocationComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          MovementComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          RenderComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          ShootMainComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          SpeedComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          StructureComponent.class);
        Entities.getInstance().registerComponentTypesWithComponentStorage(new InMemoryComponentStorage(),
                                                                          OriginComponent.class);
    }

// attach all the entity controls. The combination of these controls determine the actual game logic in use.
    private void setupAppStates() {
        SceneAppState sceneAppState = new SceneAppState("Scenes/TriggerTest.j3o");
        sceneAppState.setPlayerCentric(false);
        stateManager.attach(sceneAppState);
        FlightControlAppState flightControlAppState = new FlightControlAppState();
        stateManager.attach(flightControlAppState);
        FlightAppState flightAppState = new FlightAppState();
        flightAppState.setBounded(true);
        stateManager.attach(flightAppState);
        AiAppState triggerAppState = new AiAppState();
        stateManager.attach(triggerAppState);
        stateManager.attach(new ShootingAppState());
        stateManager.attach(new DamageAppState());
    }

// setup the key mappings
    private void setupKeys() {
        inputManager.addMapping(Controls.MOVE_FORWARD.name(),
                                new KeyTrigger(KeyInput.KEY_W));
        inputManager.addMapping(Controls.MOVE_BACKWARDS.name(),
                                new KeyTrigger(KeyInput.KEY_S));
        inputManager.addMapping(Controls.STRAFE_LEFT.name(),
                                new KeyTrigger(KeyInput.KEY_Q));
        inputManager.addMapping(Controls.STRAFE_RIGHT.name(),
                                new KeyTrigger(KeyInput.KEY_E));
        inputManager.addMapping(Controls.ROTATE_LEFT.name(),
                                new KeyTrigger(KeyInput.KEY_A));
        inputManager.addMapping(Controls.ROTATE_RIGHT.name(),
                                new KeyTrigger(KeyInput.KEY_D));
        inputManager.addMapping(Controls.SHOOT_MAIN.name(),
                                new KeyTrigger(KeyInput.KEY_SPACE));
    }
}

As you can see it is very easy to create a game where you can have a player ship fly around. All you need to do is determine what game logic you want, in this case I chose:

  1. FlightControlAppState: This means player controlled flight controls
  2. FlightAppState: this one controls the actual flight
  3. AiAppState: this enables the Ai System
  4. SceneAppState: this one handles the rendering of all the entities in the scene

Each of these come with a list of required EntityComponents. These are added in the setupEntitySystem method.

Eventually all this should be made even simpler via wizards which will be part of the GameCreator plugins. But this is still a way off. For now, this code is still manually created. Still, it’s all simple enough.

Very cool! :slight_smile:
I’ll try to get into this if I manage to find the time…

Let me know if and when you find that time… I’ll see what I can do to help out, seeing as the documentation is sort of lacking at the moment. It should all be pretty easy to follow given the example above. But if not, you can either PM me through here or reach me on my hangout address. I’d be happy to supply you with that address via PM as well.

Currently PM doesn’t work :frowning:

It is pretty cool stuff indeed! I like the ability to load classes and passing parameter from a GUI.

I suggest you to check out MonkeyBrains. It has recently received advanced steering capabilities (see here: http://jmesteer.bdevel.org/, and Java Steer Behaviors - Javadoc), but you need to write a lot of boilerplate code (sorry Jesùs and Tihomir). Your gui editor could be a killer addition for rapid game development!

Also I’m looking forward to remove the hard-coding from my code and make it more entity-friendly :wink:

I’ve been looking into MonkeyBrains, and I will certainly try and get similar stuff in my AI system.

I’ve also been thinking of the roadmap for the next few features I would like to add. This in response to talks I had with some people on what’s in there now and the roadblocks they are finding when they try and build a game with the creator. I’ll add those to the first post and keep that one updated with the progress on all of them.

So, I’ve been hard at work updating my wiki. There’s a basic explenation of the FS-GameCreator as well as a few basic tutorials which should get you started

http://ractoc.com/ForgottenSpace/wiki

Hi,
sounds great, I want to try it, but I cant find your plugin in jMonkey SDK 3.0 Stable(alias netbeans).
What’s the name of your plugin?

Thank you.