From cc1d3ac4daebe9619075808850baaa804beca9d7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 20 Jul 2018 16:28:12 +0200 Subject: [PATCH] Game - dartfmt --- lib/game/Game.dart | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/game/Game.dart b/lib/game/Game.dart index 1c16c5d..72c474c 100644 --- a/lib/game/Game.dart +++ b/lib/game/Game.dart @@ -16,27 +16,30 @@ class Game { bool _fwd = true; Game(CanvasElement this.canvas) { - grid = buildGrid(5, 5, new Color(255, 0, 255)); + grid = _buildGrid(5, 5, new Color(255, 0, 255)); ctx = this.canvas.getContext('2d'); } + // In-World Logic Updates void update([num dt]) { int ry = rng.nextInt(grid.length); grid[ry][rng.nextInt(grid[ry].length)] = new Color(rng.nextInt(255), rng.nextInt(255), rng.nextInt(255)); } + // Render Pipeline void draw([num interp]) { int brickW = (canvas.width ~/ grid[0].length); int brickH = (canvas.height ~/ grid.length); ctx.clearRect(0, 0, canvas.width, canvas.height); - grid_foreach((x, y) { + _grid_foreach((x, y) { Color col = _oscillate(grid[y][x]); ctx.setFillColorRgb(col.r, col.g, col.b); ctx.fillRect(x*brickW, y*brickH, brickW, brickH); }); } + // Slightly oscillating colors to highlight rendering updates Color _oscillate(Color col) { if(_oscill >= 50.0 || _oscill <= -50.0) { _oscillDir = !_oscillDir; @@ -48,7 +51,7 @@ class Game { return new Color(col.r + o, col.g + o, col.b + o); } - void grid_foreach(gridIterator fun) { + void _grid_foreach(gridIterator fun) { for (int y = 0; y < grid.length; y++) { for (int x = 0; x < grid[y].length; x++) { fun(x, y); @@ -56,7 +59,7 @@ class Game { } } - List> buildGrid(int w, int h, Color col) { + List> _buildGrid(int w, int h, Color col) { List> grid = new List(h); for (int y = 0; y < h; y++) { grid[y] = new List(w); @@ -75,8 +78,3 @@ class Color { const Color(this.r, this.g, this.b); } - -// Create 2d array -// fill with random colors -// cycle colors -// set one color to random new one