Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
6aa8e4bb
Commit
6aa8e4bb
authored
Jul 29, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactors setting of last score in demo game to use callback
parent
430c08f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
30 deletions
+32
-30
game_demo_world.dart
packages/flutter/example/game/lib/game_demo_world.dart
+4
-2
main.dart
packages/flutter/example/game/main.dart
+28
-28
No files found.
packages/flutter/example/game/lib/game_demo_world.dart
View file @
6aa8e4bb
...
@@ -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
;
...
...
packages/flutter/example/game/main.dart
View file @
6aa8e4bb
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment