Adds display of last score to demo game

This commit is contained in:
Viktor Lidholt 2015-07-29 13:10:02 -07:00
parent f99fd192df
commit 430c08f3e6
3 changed files with 32 additions and 16 deletions

View file

@ -9,4 +9,6 @@ import 'package:sky/widgets/widget.dart';
import 'package:sky/widgets/navigator.dart';
import 'package:vector_math/vector_math_64.dart';
import '../main.dart';
part 'game_demo_world.dart';

View file

@ -348,6 +348,7 @@ class GameDemoWorld extends NodeWithSize {
// Set game over
_isGameOver = true;
lastScore = _hud.score;
// Remove the ship
_ship.visible = false;

View file

@ -5,6 +5,7 @@
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/rendering/object.dart';
import 'package:sky/painting/text_style.dart';
import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/button_base.dart';
import 'package:sky/widgets/navigator.dart';
@ -93,7 +94,8 @@ class GameDemoApp extends App {
return new Stack([
new SpriteWidget(new MainScreenBackground()),
new Center(
child: new TextureButton(
child: new Flex([
new TextureButton(
onPressed: () {
_game = new GameDemoWorld(
_app,
@ -108,12 +110,21 @@ class GameDemoApp extends App {
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,
@ -156,6 +167,7 @@ class TextureButton extends ButtonBase {
if (texture == null)
return;
canvas.save();
if (highlight && textureDown != null) {
// Draw down state
canvas.scale(size.width / textureDown.size.width, size.height / textureDown.size.height);
@ -165,6 +177,7 @@ class TextureButton extends ButtonBase {
canvas.scale(size.width / texture.size.width, size.height / texture.size.height);
texture.drawTexture(canvas, Point.origin, new Paint());
}
canvas.restore();
}
}