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
27181225
Commit
27181225
authored
Jul 21, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issues in demo game and adds heads up display
parent
b26bae8a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
5 deletions
+58
-5
game_demo_world.dart
packages/flutter/example/game/lib/game_demo_world.dart
+51
-1
main.dart
packages/flutter/example/game/main.dart
+7
-4
No files found.
packages/flutter/example/game/lib/game_demo_world.dart
View file @
27181225
...
...
@@ -27,6 +27,7 @@ class GameDemoWorld extends NodeWithSize {
sky
.
Image
_imgNebula
;
SpriteSheet
_spriteSheet
;
SpriteSheet
_spriteSheetUI
;
Navigator
_navigator
;
// Inputs
...
...
@@ -46,8 +47,10 @@ class GameDemoWorld extends NodeWithSize {
int
_numFrames
=
0
;
bool
_isGameOver
=
false
;
GameDemoWorld
(
App
app
,
this
.
_navigator
,
ImageMap
images
,
this
.
_spriteSheet
)
:
super
(
new
Size
(
_gameSizeWidth
,
_gameSizeHeight
))
{
// Heads up display
Hud
_hud
;
GameDemoWorld
(
App
app
,
this
.
_navigator
,
ImageMap
images
,
this
.
_spriteSheet
,
this
.
_spriteSheetUI
)
:
super
(
new
Size
(
_gameSizeWidth
,
_gameSizeHeight
))
{
// Fetch images
_imgNebula
=
images
[
"assets/nebula.png"
];
...
...
@@ -81,6 +84,10 @@ class GameDemoWorld extends NodeWithSize {
userInteractionEnabled
=
true
;
handleMultiplePointers
=
true
;
_hud
=
new
Hud
(
_spriteSheetUI
);
_hud
.
zPosition
=
1000.0
;
addChild
(
_hud
);
}
// Methods for adding game objects
...
...
@@ -585,6 +592,49 @@ class StarField extends Node {
}
}
class
Hud
extends
NodeWithSize
{
SpriteSheet
spriteSheetUI
;
Sprite
sprtBgScore
;
Sprite
sprtBgShield
;
int
_score
=
0
;
int
get
score
=>
_score
;
set
score
(
int
score
)
{
_score
=
score
;
_updateHud
();
}
Hud
(
this
.
spriteSheetUI
)
{
pivot
=
Point
.
origin
;
sprtBgScore
=
new
Sprite
(
spriteSheetUI
[
"scoreboard.png"
]);
sprtBgScore
.
pivot
=
Point
.
origin
;
sprtBgScore
.
scale
=
0.6
;
addChild
(
sprtBgScore
);
sprtBgShield
=
new
Sprite
(
spriteSheetUI
[
"bar_shield.png"
]);
sprtBgShield
.
pivot
=
new
Point
(
1.0
,
0.0
);
sprtBgShield
.
scale
=
0.6
;
addChild
(
sprtBgShield
);
}
void
spriteBoxPerformedLayout
()
{
// Set the size and position of HUD display
position
=
spriteBox
.
visibleArea
.
topLeft
;
size
=
spriteBox
.
visibleArea
.
size
;
// Position hud objects
sprtBgScore
.
position
=
new
Point
(
20.0
,
20.0
);
sprtBgShield
.
position
=
new
Point
(
size
.
width
-
20.0
,
20.0
);
}
void
_updateHud
()
{
}
}
class
Nebula
extends
Node
{
Nebula
.
withImage
(
sky
.
Image
img
)
{
...
...
packages/flutter/example/game/main.dart
View file @
27181225
...
...
@@ -51,6 +51,7 @@ main() async {
class
GameDemoApp
extends
App
{
NavigationState
_navigationState
;
GameDemoWorld
_game
;
void
initState
()
{
_navigationState
=
new
NavigationState
([
...
...
@@ -84,16 +85,18 @@ class GameDemoApp extends App {
}
Widget
_buildGameScene
(
navigator
,
route
)
{
return
new
SpriteWidget
(
new
GameDemoWorld
(
_app
,
navigator
,
_loader
,
_spriteSheet
)
);
if
(
_game
==
null
)
_game
=
new
GameDemoWorld
(
_app
,
navigator
,
_loader
,
_spriteSheet
);
return
new
SpriteWidget
(
_game
);
}
Widget
_buildMainScene
(
navigator
,
route
)
{
return
new
Center
(
child:
new
RaisedButton
(
child:
new
Text
(
"Play"
),
onPressed:
()
=>
navigator
.
pushNamed
(
'/game'
)
onPressed:
()
{
_game
=
new
GameDemoWorld
(
_app
,
navigator
,
_loader
,
_spriteSheet
,
_spriteSheetUI
);
navigator
.
pushNamed
(
'/game'
);
}
)
);
}
...
...
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