This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final _game = GameOfLife(); | |
Size _cellSize; | |
@override | |
void initState() { | |
super.initState(); | |
//Fullscreen display (still including appbar) | |
SystemChrome.setEnabledSystemUIOverlays([]); | |
_game.resetWorld(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Widget build(BuildContext contGameOfLifeext) { | |
final screenSize = MediaQuery.of(context).size; | |
_cellSize = Size( | |
screenSize.width / GameOfLife.rowLength, | |
(screenSize.height - kToolbarHeight) / | |
(GameOfLife.worldSize / GameOfLife.rowLength)); | |
return Scaffold( | |
appBar: AppBar( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:math'; | |
class GameOfLife { | |
static const worldSize = 1024; | |
static const rowLength = 32; | |
static const cellMargin = 1; | |
final _world = List<bool>(worldSize); | |
final StreamController<double> _stateController = StreamController<double>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const worldSize = 1024; | |
static const rowLength = 32; | |
final _world = List<bool>(worldSize); | |
void resetWorld() { | |
final random = Random(); | |
_world.fillRange(0, worldSize, false); | |
final totalSets = random.nextInt(((worldSize / 100) * 50).round()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> _runTheGame() async { | |
while (_running) { | |
await Future.delayed(Duration(milliseconds: 350)); | |
var newWorld = List<bool>.from(_world); | |
for (var i = 0; i < worldSize; ++i) { | |
//In case x cell alive do this | |
var livingNeighbors = _countLivingCellsNearby(i); | |
if (livingNeighbors < 2 || livingNeighbors > 3) { | |
//die | |
newWorld[i] = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class CellPainter extends CustomPainter { | |
bool cellIsAlive = false; | |
double left; | |
double top; | |
final Paint paintSetting = Paint(); | |
CellPainter({this.cellIsAlive,this.left,this.top}){ | |
paintSetting.strokeWidth = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:gameoflife/cell.dart'; | |
class GameBoard extends StatelessWidget { | |
final List<bool> _world; | |
final Size cellSize; | |
final int _rowLength; | |
final int _cellMargin; | |
const GameBoard(this._cellMargin,this._world, this._rowLength, {Key key, this.cellSize}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flame/util.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:mazeball/game.dart'; | |
import 'dart:async'; | |
void main() async { | |
//Make sure flame is ready before we launch our game | |
await setupFlame(); | |
var game = new MazeBallGame(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui'; | |
import 'package:box2d_flame/box2d.dart'; | |
import 'package:flame/flame.dart'; | |
import 'package:flame/game.dart'; | |
class MazeBallGame extends Game { | |
//Needed for Box2D | |
static const int WORLD_POOL_SIZE = 100; | |
static const int WORLD_POOL_CONTAINER_SIZE = 10; | |
//Main physic object -> our game world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ui'; | |
import 'package:box2d_flame/box2d.dart'; | |
import 'package:mazeball/game.dart'; | |
import 'package:sensors/sensors.dart'; | |
class Ball { | |
final MazeBallGame game; | |
//Physic objects | |
Body body; | |
CircleShape shape; |
OlderNewer