so://phie

game-engine

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

blob: 1095726706071ce8437f57a47a2a1b46c6f00bc7 (634 bytes)[doc][blame][raw]

1import { Shape } from './shape.js';

2

3export class Surface {

4 constructor(x, y, shape) {

5 this.x = x;

6 this.y = y;

7 this.shape = shape;

8 }

9 update() {

10 // nothing

11 }

12 render(g) {

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

14 g.beginPath();

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

16 g.stroke();

17 }

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

19 g.beginPath();

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

21 g.stroke();

22 }

23 }

24 causeEvent(type, events) {

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

26 for(const event of events) {

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

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

29 }

30 }

31 }

32 }