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,38 +94,37 @@ class GameDemoApp extends App { ...@@ -93,38 +94,37 @@ 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( _app,
_app, navigator,
navigator, _loader,
_loader, _spriteSheet,
_spriteSheet, _spriteSheetUI,
_spriteSheetUI (lastScore) {
); setState(() {_lastScore = lastScore;});
navigator.pushNamed('/game'); }
}, );
texture: _spriteSheetUI["btn_play_up.png"], navigator.pushNamed('/game');
textureDown: _spriteSheetUI["btn_play_down.png"], },
width: 128.0, texture: _spriteSheetUI["btn_play_up.png"],
height: 128.0 textureDown: _spriteSheetUI["btn_play_down.png"],
), width: 128.0,
new Text( height: 128.0
"Last Score: $lastScore", ),
style: new TextStyle(fontSize:20.0) new Text(
) "Last Score: $_lastScore",
], style: new TextStyle(fontSize:20.0)
direction: FlexDirection.vertical, )
justifyContent: FlexJustifyContent.center) ],
) direction: FlexDirection.vertical,
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