TerraJS uses the Entity-Component-System (ECS) pattern to create lightweight games.
Entity - This is essentially an 'object' or thing within your game's world. (Enemy, Bullets, etc)
Component - Components are attached to Entities and provide a lego-like approach to assigning behavior to an Entity. (Health, Position, etc)
System - This is where you logic will live. A System will control all Entities that pertain to itself. (BulletSystem, EnemySystem, etc)
You can find the documentation here
Include the TerraJS library script
<script src="path/to/terra.js"></script>
var Game = new Terra.Game(500, 300);
var position = new Terra.Component('Position', {x: 0, y: 0});
var attack = new Terra.Component('Attack', {damage: 50});
var monsterEntity = new Terra.Entity('Monster', [position, attack]);
var monsterSystem = new Terra.System('MonsterSystem', monsterSystemStart, monsterSystemUpdate);
function monsterSystemStart(system) {} // Happens on startup
function monsterSystemUpdate(system, time) {} // Happens every frame
Game.onStart = function() {} // Happens on game start
Game.onUpdate = function() {} // Happens every frame of the game.
Game.start();
Once you make changes to the code, you need to build
npm run webpack
Please make sure to write tests for any new functionality (test/test.js
). You can run tests with the command below.
npm test
You can run webpack, tests & documentation all together
npm run build