A lightweight JavaScript game engine
git clone git://soophie.de/game-engine
blob: fc0c5da4ac6f92322a8e38d25986c73fab5b31dd (639 bytes)[doc][blame][raw]
1
import Shape from './shape.js';3
export default class Surface {4
constructor(x, y, shape) {5
this.x = x;6
this.y = y;7
this.shape = shape;8
}9
update() {10
// nothing11
}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
}33
}