so://phie

game-engine

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

blob: 92d650a98eaf58b781b8b6e704c5cccb988d1b2e (597 bytes)[doc][blame][raw]

1export class Surface {

2 constructor(x, y, shape) {

3 this.x = x;

4 this.y = y;

5 this.shape = shape;

6 }

7 update() {

8 // nothing

9 }

10 render(g) {

11 if(this.shape instanceof Shape.Rect) {

12 g.beginPath();

13 g.rect(this.x, this.y, this.shape.width, this.shape.height);

14 g.stroke();

15 }

16 if(this.shape instanceof Shape.Circle) {

17 g.beginPath();

18 g.arc(this.x, this.y, this.shape.radius, 2 * Math.PI, 0);

19 g.stroke();

20 }

21 }

22 causeEvent(type, events) {

23 if(this['on' + type]) {

24 for(const event of events) {

25 if(event.type === type) {

26 this['on' + type](event);

27 }

28 }

29 }

30 }