Skip to content

typable/game-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

game-engine

A lightweight JavaScript Game Engine

Example


import GameEngine from '...';

const {Game, Surface, Shape} = GameEngine;

class Entity extends Surface {

    constructor(x, y) {
        super(x, y, new Shape.Rect(60, 60));
    }
    
    update() {
        // ...
    }
    
    render(g) {
        const {x, y, shape} = this;
        g.fillRect(x, y, shape.width, shape.height);
    }
    
}

class ExampleGame extends Game {

    constructor() {
        super(window.innerWidth, window.innerHeight);
        this.bindEvent(window, 'resize');
        this.entity = new Entity(100, 100);
    }
    
    onresize() {
        this.resize(window.innerWidth, window.innerHeight);
    }
    
    update() {
        this.entity.update();
    }
    
    render(g) {
        super.render(g);
        this.entity.render(g);
    }
    
}

const game = new ExampleGame();
game.start();

document.body.appendChild(game.canvas);

About

A lightweight JavaScript game engine

Topics

Resources

License

Stars

Watchers

Forks