Skip to content

Thrunium

Getting started

Getting started with Thrunium is easy. Make a project folder with an index.html file and a game.js file. Add a script tag with the link to the Thrunium file, and a script tag for your game.js file.

Your project folder will look like this:

Folder structure
my-game/
├── index.html
└── game.js

You are reading the documentation for version 1.1.0.

Two builds are published for every version:

  • thrunium.min.js is the small, minified build. Use this one in your game.
  • thrunium.js is the readable build. It is handy when you want to look at the engine code while debugging.

Both are available at https://cdn.thrungames.com/thrunium/v1.1.0/. Thrunium targets modern browsers (ES2017), so Internet Explorer is not supported.

Here is an example of the two files.

index.html

HTML
<!DOCTYPE html>
<html>
<body style="margin: 0; padding: 0;">
	<script src="https://cdn.thrungames.com/thrunium/v1.1.0/thrunium.min.js"></script>
	<script src="game.js"></script>
</body>
</html>

game.js

JavaScript
var game = new THRUNIUM.Game(800, 800);

game.startState = 'game';
game.backgroundColor = '#eee';

game.states['game'] = function () {
	game.drawRect(100, 100, 100, 100);
	game.setFillColor('#000');
	game.fill();
}

game.init();

game.start();

Now you can add your game functionality in the function that is saved under game.states['game']. Inside the function there is some premade code. It draws a black rectangle at x: 100 and y: 100 with a width of 100px and a height of 100px. You can replace this code with your own.

Classes such as Game, Vector, Sprite and Elem.Elem must be created with new, like new THRUNIUM.Game(800, 800) above.

How to

A quick tutorial on how to use JavaScript.

JavaScript
console.log('Hello world!');       // print to the console

var test = 0;                      // init a variable
console.log(test);                 // print the variable
test++;                            // add 1 to test
console.log(test);                 // print the variable again

var arrayName = [];                // init an array
arrayName.push('test');            // add a string to the array
arrayName.push(10);                // add a number to the array
for (var i = 0; i < arrayName.length; i++) {
	console.log(arrayName[i]);     // print the variable at index i from arrayName
}

arrayName.splice(0, 1);            // remove the variable at index 0

Class

Making a class.

JavaScript
function Test(argument) {               // constructor argument
	this.variable = "hello world";      // init variable for object
	this.variable2 = argument;          // init variable with an argument

	this.get_variable = function() {    // set a function for the object
		return this.variable;
	};
}

var test = new Test('my object');       // construct an object with 'my object' as argument
console.log(test.get_variable());       // call the object's get_variable function and print the result

You can read about everything the Game class offers on its reference page.