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 {
// Heads up display
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
_imgNebula = images["assets/nebula.png"];
......@@ -348,7 +350,7 @@ class GameDemoWorld extends NodeWithSize {
// Set game over
_isGameOver = true;
lastScore = _hud.score;
_gameOverCallback(_hud.score);
// Remove the ship
_ship.visible = false;
......
......@@ -54,6 +54,7 @@ class GameDemoApp extends App {
NavigationState _navigationState;
GameDemoWorld _game;
int _lastScore = 0;
void initState() {
_navigationState = new NavigationState([
......@@ -93,38 +94,37 @@ class GameDemoApp extends App {
Widget _buildMainScene(navigator, route) {
return new Stack([
new SpriteWidget(new MainScreenBackground()),
new Center(
child: new Flex([
new TextureButton(
onPressed: () {
_game = new GameDemoWorld(
_app,
navigator,
_loader,
_spriteSheet,
_spriteSheetUI
);
navigator.pushNamed('/game');
},
texture: _spriteSheetUI["btn_play_up.png"],
textureDown: _spriteSheetUI["btn_play_down.png"],
width: 128.0,
height: 128.0
),
new Text(
"Last Score: $lastScore",
style: new TextStyle(fontSize:20.0)
)
],
direction: FlexDirection.vertical,
justifyContent: FlexJustifyContent.center)
)
new Flex([
new TextureButton(
onPressed: () {
_game = new GameDemoWorld(
_app,
navigator,
_loader,
_spriteSheet,
_spriteSheetUI,
(lastScore) {
setState(() {_lastScore = lastScore;});
}
);
navigator.pushNamed('/game');
},
texture: _spriteSheetUI["btn_play_up.png"],
textureDown: _spriteSheetUI["btn_play_down.png"],
width: 128.0,
height: 128.0
),
new Text(
"Last Score: $_lastScore",
style: new TextStyle(fontSize:20.0)
)
],
direction: FlexDirection.vertical,
justifyContent: FlexJustifyContent.center)
]);
}
}
int lastScore = 0;
class TextureButton extends ButtonBase {
TextureButton({
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