added mouse controls

This commit is contained in:
MaxRobinsonTheGreat
2020-07-10 22:05:29 -06:00
parent 949d46e7c4
commit c39ece309d
10 changed files with 162 additions and 41 deletions

View File

@@ -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();
}
}
}