Commit 6aa8e4bb authored by Viktor Lidholt's avatar Viktor Lidholt

Refactors setting of last score in demo game to use callback

parent 430c08f3
...@@ -51,7 +51,9 @@ class GameDemoWorld extends NodeWithSize { ...@@ -51,7 +51,9 @@ class GameDemoWorld extends NodeWithSize {
// Heads up display // Heads up display
Hud _hud; Hud _hud;
GameDemoWorld(App app, this._navigator, ImageMap images, this._spriteSheet, this._spriteSheetUI) : super(new Size(_gameSizeWidth, _gameSizeHeight)) { Function _gameOverCallback;
GameDemoWorld(App app, this._navigator, ImageMap images, this._spriteSheet, this._spriteSheetUI, this._gameOverCallback) : super(new Size(_gameSizeWidth, _gameSizeHeight)) {
// Fetch images // Fetch images
_imgNebula = images["assets/nebula.png"]; _imgNebula = images["assets/nebula.png"];
...@@ -348,7 +350,7 @@ class GameDemoWorld extends NodeWithSize { ...@@ -348,7 +350,7 @@ class GameDemoWorld extends NodeWithSize {
// Set game over // Set game over
_isGameOver = true; _isGameOver = true;
lastScore = _hud.score; _gameOverCallback(_hud.score);
// Remove the ship // Remove the ship
_ship.visible = false; _ship.visible = false;
......
...@@ -54,6 +54,7 @@ class GameDemoApp extends App { ...@@ -54,6 +54,7 @@ class GameDemoApp extends App {
NavigationState _navigationState; NavigationState _navigationState;
GameDemoWorld _game; GameDemoWorld _game;
int _lastScore = 0;
void initState() { void initState() {
_navigationState = new NavigationState([ _navigationState = new NavigationState([
...@@ -93,8 +94,7 @@ class GameDemoApp extends App { ...@@ -93,8 +94,7 @@ class GameDemoApp extends App {
Widget _buildMainScene(navigator, route) { Widget _buildMainScene(navigator, route) {
return new Stack([ return new Stack([
new SpriteWidget(new MainScreenBackground()), new SpriteWidget(new MainScreenBackground()),
new Center( new Flex([
child: new Flex([
new TextureButton( new TextureButton(
onPressed: () { onPressed: () {
_game = new GameDemoWorld( _game = new GameDemoWorld(
...@@ -102,7 +102,10 @@ class GameDemoApp extends App { ...@@ -102,7 +102,10 @@ class GameDemoApp extends App {
navigator, navigator,
_loader, _loader,
_spriteSheet, _spriteSheet,
_spriteSheetUI _spriteSheetUI,
(lastScore) {
setState(() {_lastScore = lastScore;});
}
); );
navigator.pushNamed('/game'); navigator.pushNamed('/game');
}, },
...@@ -112,19 +115,16 @@ class GameDemoApp extends App { ...@@ -112,19 +115,16 @@ class GameDemoApp extends App {
height: 128.0 height: 128.0
), ),
new Text( new Text(
"Last Score: $lastScore", "Last Score: $_lastScore",
style: new TextStyle(fontSize:20.0) style: new TextStyle(fontSize:20.0)
) )
], ],
direction: FlexDirection.vertical, direction: FlexDirection.vertical,
justifyContent: FlexJustifyContent.center) justifyContent: FlexJustifyContent.center)
)
]); ]);
} }
} }
int lastScore = 0;
class TextureButton extends ButtonBase { class TextureButton extends ButtonBase {
TextureButton({ TextureButton({
Key key, Key key,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment