fixed grid sizing, added hotkey

This commit is contained in:
Max Robinson
2021-08-30 18:53:36 -05:00
parent 0854c5a561
commit 8c4723ea29
2 changed files with 27 additions and 7 deletions

View File

@@ -20,13 +20,33 @@ class ControlPanel {
} }
defineMinMaxControls(){ defineMinMaxControls(){
$('#minimize').click ( function() { this.control_panel_active = true;
this.no_hud = false;
$('#minimize').click ( () => {
$('.control-panel').css('display', 'none'); $('.control-panel').css('display', 'none');
$('.hot-controls').css('display', 'block'); $('.hot-controls').css('display', 'block');
this.control_panel_active = false;
}); });
$('#maximize').click ( function() { $('#maximize').click ( () => {
$('.control-panel').css('display', 'grid'); $('.control-panel').css('display', 'grid');
$('.hot-controls').css('display', 'none'); $('.hot-controls').css('display', 'none');
this.control_panel_active = true;
});
const V_KEY = 118;
$('body').keypress( (e) => {
if (e.which === V_KEY) {
if (this.no_hud) {
let control_panel_display = this.control_panel_active ? 'grid' : 'none';
let hot_control_display = !this.control_panel_active ? 'block' : 'none';
$('.control-panel').css('display', control_panel_display);
$('.hot-controls').css('display', hot_control_display);
}
else {
$('.control-panel').css('display', 'none');
$('.hot-controls').css('display', 'none');
}
this.no_hud = !this.no_hud;
}
}); });
} }

View File

@@ -12,8 +12,8 @@ class WorldEnvironment extends Environment{
super(); super();
this.renderer = new Renderer('env-canvas', 'env', cell_size); this.renderer = new Renderer('env-canvas', 'env', cell_size);
this.controller = new EnvironmentController(this, this.renderer.canvas); this.controller = new EnvironmentController(this, this.renderer.canvas);
var grid_rows = Math.floor(this.renderer.height / cell_size); var grid_rows = Math.ceil(this.renderer.height / cell_size);
var grid_cols = Math.floor(this.renderer.width / cell_size); var grid_cols = Math.ceil(this.renderer.width / cell_size);
this.grid_map = new GridMap(grid_cols, grid_rows, cell_size); this.grid_map = new GridMap(grid_cols, grid_rows, cell_size);
this.organisms = []; this.organisms = [];
this.walls = []; this.walls = [];
@@ -23,7 +23,7 @@ class WorldEnvironment extends Environment{
this.reset_count = 0; this.reset_count = 0;
} }
update(delta_time) { update() {
var to_remove = []; var to_remove = [];
for (var i in this.organisms) { for (var i in this.organisms) {
var org = this.organisms[i]; var org = this.organisms[i];
@@ -132,8 +132,8 @@ class WorldEnvironment extends Environment{
resizeFillWindow(cell_size) { resizeFillWindow(cell_size) {
this.renderer.cell_size = cell_size; this.renderer.cell_size = cell_size;
this.renderer.fillWindow('env'); this.renderer.fillWindow('env');
var cols = Math.floor(this.renderer.width / cell_size); var cols = Math.ceil(this.renderer.width / cell_size);
var rows = Math.floor(this.renderer.height / cell_size); var rows = Math.ceil(this.renderer.height / cell_size);
this.grid_map.resize(cols, rows, cell_size); this.grid_map.resize(cols, rows, cell_size);
this.reset(); this.reset();
} }