added flow and basic game

This commit is contained in:
2017-05-25 21:47:54 +02:00
parent 86c3d4383d
commit 38ee7a6b65
6 changed files with 69 additions and 13 deletions
+9
View File
@@ -0,0 +1,9 @@
class Entity {
render(ctx: CanvasRenderingContext2D){
ctx.fillStyle = 'rgb(200,0,0)';
ctx.fillRect(10, 10, 55, 50);
}
}
export default Entity
+33
View File
@@ -0,0 +1,33 @@
// @flow
import type Entity from './Entities/Entity'
const fps = 30
class Game {
entities: Array<Entity>
ctx: CanvasRenderingContext2D
constructor(_ctx: CanvasRenderingContext2D){
this.entities = []
this.ctx = _ctx
}
start(){
this._draw()
}
_draw(){
setTimeout(() => {
requestAnimationFrame(() => this._draw())
this.entities.forEach(e => e.render(this.ctx))
}, 1000 / fps)
}
addEntity(e: Entity){
this.entities.push(e)
}
}
export default Game