added flow and basic game
This commit is contained in:
@@ -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
@@ -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
|
||||
Reference in New Issue
Block a user