frostney / flockn

:video_game: Leightweight declarative game engine for JavaScript
The Unlicense
16 stars 0 forks source link

flockn

flockn is a lightweight declarative game engine.

How does it work?

// Import flockn function from the flockn module
import flockn from 'flockn';

// Create a game instance, no need to store it as a variable
// Using the flockn module is a shorthand for:
//    import Game from 'flockn/game'; new Game(function() { ...
flockn(function (game) {
  // The logic for the game itself

  // Add a scene to the game
  game.addScene(function (scene) {
    // The logic for this scene

    // Give the scene a name
    scene.name = 'myscene';

    // Create a new game object inside the scene
    scene.addGameObject(function (gameObject) {
      // The logic for this game object

      // Set the position for this game object
      gameObject.position.x = 100;
      gameObject.position.y = 100;

      // This game object now holds a label with the text "Hello World"
      gameObject.texture.label.text = 'Hello World';
    });
  });

  // Start the game loop
  // Since only have one scene, we don't need to specify a scene name.
  // In any other case it would be: `game.run('myscene');`
  game.run();
});
import { Game, Scene, GameObject, Texture } from 'flockn';
const { Label } = Texture;

const hero = new GameObject();
hero.position.x = 100;
hero.position.y = 100;
hero.texture = new Label();
hero.texture.text = 'Hello World';
hero.onUpdate = function (dt) {
  hero.angle += dt * 10;
};

const scene = new Scene();
scene.addGameObject(hero);

const myGame = new Game();
myGame.addScene(scene);
myGame.run();

Putting everything in one file doesn't work for anything bigger than a small experiment, so I would recommend to to put each gameobjects, behaviors and scene in separate files. For a more real-life example, take a look at the template. There is also an online playground.

Examples

  1. Make sure all dependencies have been installed. When in doubt, run npm install
  2. Type npm run examples to start the example server
  3. Navigate to http://localhost:8080 to see all the examples.

Features

Mission statement

Philosophy

Some decisions that need to be made

Alternatives

Building for yourself

Type npm install to install all necessary dependencies.

License

This is public domain (UNLICENSE). If public domain does not work for you, you can use MIT alternatively.