added mouse controls
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
const Environment = require('./Environment');
|
||||
const ControlPanel = require('./ControlPanel');
|
||||
|
||||
const render_speed = 60;
|
||||
|
||||
class Engine{
|
||||
constructor(){
|
||||
this.fps = 0;
|
||||
this.fps = 60;
|
||||
this.env = new Environment(5);
|
||||
this.controlpanel = new ControlPanel(this);
|
||||
this.env.OriginOfLife();
|
||||
@@ -21,7 +23,7 @@ class Engine{
|
||||
this.fps = fps;
|
||||
this.game_loop = setInterval(function(){this.update();}.bind(this), 1000/fps);
|
||||
this.running = true;
|
||||
if (this.fps >= 45) {
|
||||
if (this.fps >= render_speed) {
|
||||
if (this.render_loop != null) {
|
||||
clearInterval(this.render_loop);
|
||||
this.render_loop = null;
|
||||
@@ -39,7 +41,7 @@ class Engine{
|
||||
|
||||
setRenderLoop() {
|
||||
if (this.render_loop == null) {
|
||||
this.render_loop = setInterval(function(){this.env.render();}.bind(this), 1000/45);
|
||||
this.render_loop = setInterval(function(){this.env.render();this.controlpanel.update();}.bind(this), 1000/render_speed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +50,12 @@ class Engine{
|
||||
this.delta_time = Date.now() - this.last_update;
|
||||
this.last_update = Date.now();
|
||||
this.env.update(this.delta_time);
|
||||
this.env.render();
|
||||
this.actual_fps = 1/this.delta_time*1000;
|
||||
this.controlpanel.update();
|
||||
if(this.render_loop == null){
|
||||
this.env.render();
|
||||
this.controlpanel.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user