so://phie

game-engine

A lightweight JavaScript game engine
git clone git://soophie.de/game-engine

blob: 1a4dada5c6dfd7345bd4a09d766e04d3fe3f069a (1012 bytes)[doc][blame][raw]

1# game-engine

2A lightweight JavaScript Game Engine

3<br>

4<br>

5

6## Example

7<br>

8

9```javascript

10import GameEngine from '...';

11

12const {Game, Surface, Shape} = GameEngine;

13```

14<br>

15

16```javascript

17class Entity extends Surface {

18

19 constructor(x, y) {

20 super(x, y, new Shape.Rect(60, 60));

21 }

22

23 update() {

24 // ...

25 }

26

27 render(g) {

28 const {x, y, shape} = this;

29 g.fillRect(x, y, shape.width, shape.height);

30 }

31

32}

33```

34<br>

35

36```javascript

37class ExampleGame extends Game {

38

39 constructor() {

40 super(window.innerWidth, window.innerHeight);

41 this.bindEvent(window, 'resize');

42 this.entity = new Entity(100, 100);

43 }

44

45 onresize() {

46 this.resize(window.innerWidth, window.innerHeight);

47 }

48

49 update() {

50 this.entity.update();

51 }

52

53 render(g) {

54 super.render(g);

55 this.entity.render(g);

56 }

57

58}

59

60const game = new ExampleGame();

61game.start();

62

63document.body.appendChild(game.canvas);

64```