From dd18fc3bc7ded19b134e26867988bdb48455d2bb Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 25 Aug 2018 17:23:06 +0200 Subject: [PATCH] Make Engine Gridsize configurable --- lib/src/Engine.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/Engine.dart b/lib/src/Engine.dart index be3f31f..b05f79c 100644 --- a/lib/src/Engine.dart +++ b/lib/src/Engine.dart @@ -1,4 +1,5 @@ import 'dart:html' as html; +import 'dart:math'; import 'package:rules_of_living/src/Grid.dart'; @@ -28,9 +29,10 @@ class Engine { // ms stuck in updateloop after which game will declare itself unresponsive final int SAFETY_TIMEOUT = 2000; - // Grid Size TODO add as configurable option - static final GRID_X = 100; - static final GRID_Y = 100; + /// Grid Size + /// + /// Number of cells on x coordinate and y coordinate. Can be set individually. + Point gridSize = Point(100, 100); num _updateLag = 0.0; num _drawLag = 0.0; @@ -41,10 +43,12 @@ class Engine { /// be used if no canvas was defined at engine creation and it should be /// rendered later. html.CanvasElement canvas; - Grid _grid = new Grid(GRID_X, GRID_Y); + Grid _grid; bool running = false; Engine([this.canvas]) { + _grid = Grid(gridSize.x, gridSize.y); + _elapsed.start(); _grid.addPattern(amount: 15, dispersal: 5); html.window.animationFrame.then(animFrame); @@ -61,7 +65,7 @@ class Engine { } void clear() { - _grid = new Grid(GRID_X, GRID_Y); + _grid = new Grid(gridSize.x, gridSize.y); running = false; }