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
e239e4c9
Commit
e239e4c9
authored
Aug 26, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds counting of coins in demo game
parent
65289031
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
20 deletions
+84
-20
game_demo_node.dart
examples/game/lib/game_demo_node.dart
+2
-2
game_objects.dart
examples/game/lib/game_objects.dart
+10
-0
player_state.dart
examples/game/lib/player_state.dart
+72
-18
No files found.
examples/game/lib/game_demo_node.dart
View file @
e239e4c9
...
...
@@ -39,7 +39,7 @@ class GameDemoNode extends NodeWithSize {
_gameScreen
.
addChild
(
_level
);
// Add heads up display
_playerState
=
new
PlayerState
(
_spritesUI
);
_playerState
=
new
PlayerState
(
_spritesUI
,
_spritesGame
);
addChild
(
_playerState
);
_objectFactory
=
new
GameObjectFactory
(
_spritesGame
,
_sounds
,
_level
,
_playerState
);
...
...
@@ -165,7 +165,7 @@ class GameDemoNode extends NodeWithSize {
}
else
if
(
node
is
GameObject
&&
node
.
canBeCollected
)
{
if
(
node
.
collidingWith
(
_level
.
ship
))
{
// The ship ran over something collectable
node
.
removeFromParen
t
();
node
.
collec
t
();
}
}
}
...
...
examples/game/lib/game_objects.dart
View file @
e239e4c9
...
...
@@ -53,6 +53,10 @@ abstract class GameObject extends Node {
}
}
void
collect
()
{
removeFromParent
();
}
void
addDamage
(
double
d
)
{
if
(!
canBeDamaged
)
return
;
...
...
@@ -263,6 +267,7 @@ class Coin extends PowerUp {
_sprt
=
new
Sprite
(
f
.
sheet
[
"shield.png"
]);
_sprt
.
transferMode
=
sky
.
TransferMode
.
plus
;
_sprt
.
size
=
new
Size
(
15.0
,
15.0
);
_sprt
.
colorOverlay
=
new
Color
(
0xffffff00
);
addChild
(
_sprt
);
radius
=
7.5
;
...
...
@@ -274,4 +279,9 @@ class Coin extends PowerUp {
}
Sprite
_sprt
;
void
collect
()
{
f
.
playerState
.
addCoin
(
this
);
super
.
collect
();
}
}
examples/game/lib/player_state.dart
View file @
e239e4c9
part of
game
;
class
PlayerState
extends
Node
{
SpriteSheet
sheet
;
Sprite
sprtBgScore
;
PlayerState
(
this
.
_sheetUI
,
this
.
_sheetGame
)
{
// Score display
Sprite
sprtBgScore
=
new
Sprite
(
_sheetUI
[
"scoreboard.png"
]);
sprtBgScore
.
pivot
=
new
Point
(
1.0
,
0.0
);
sprtBgScore
.
scale
=
0.35
;
sprtBgScore
.
position
=
new
Point
(
310.0
,
10.0
);
addChild
(
sprtBgScore
);
_scoreDisplay
=
new
ScoreDisplay
(
_sheetUI
);
_scoreDisplay
.
position
=
new
Point
(-
13.0
,
49.0
);
sprtBgScore
.
addChild
(
_scoreDisplay
);
// Coin display
Sprite
sprtBgCoins
=
new
Sprite
(
_sheetUI
[
"scoreboard.png"
]);
sprtBgCoins
.
pivot
=
new
Point
(
1.0
,
0.0
);
sprtBgCoins
.
scale
=
0.35
;
sprtBgCoins
.
position
=
new
Point
(
170.0
,
10.0
);
addChild
(
sprtBgCoins
);
_coinDisplay
=
new
ScoreDisplay
(
_sheetUI
);
_coinDisplay
.
position
=
new
Point
(-
13.0
,
49.0
);
sprtBgCoins
.
addChild
(
_coinDisplay
);
}
final
SpriteSheet
_sheetUI
;
final
SpriteSheet
_sheetGame
;
ScoreDisplay
_scoreDisplay
;
ScoreDisplay
_coinDisplay
;
int
get
score
=>
_scoreDisplay
.
score
;
set
score
(
int
score
)
{
_scoreDisplay
.
score
=
score
;
}
int
get
coins
=>
_coinDisplay
.
score
;
void
addCoin
(
Coin
c
)
{
// Animate coin to the top of the screen
Point
startPos
=
convertPointFromNode
(
Point
.
origin
,
c
);
Point
finalPos
=
new
Point
(
10.0
,
10.0
);
Point
middlePos
=
new
Point
((
startPos
.
x
+
finalPos
.
x
)
/
2.0
+
50.0
,
(
startPos
.
y
+
finalPos
.
y
)
/
2.0
);
List
<
Point
>
path
=
[
startPos
,
middlePos
,
finalPos
];
Sprite
sprt
=
new
Sprite
(
_sheetGame
[
"shield.png"
]);
sprt
.
size
=
new
Size
(
15.0
,
15.0
);
sprt
.
transferMode
=
sky
.
TransferMode
.
plus
;
sprt
.
colorOverlay
=
new
Color
(
0xffffff00
);
ActionSpline
spline
=
new
ActionSpline
((
a
)
=>
sprt
.
position
=
a
,
path
,
0.5
);
spline
.
tension
=
0.25
;
sprt
.
actions
.
run
(
new
ActionSequence
([
spline
,
new
ActionRemoveNode
(
sprt
),
new
ActionCallFunction
(()
{
_coinDisplay
.
score
+=
1
;
})
]));
addChild
(
sprt
);
}
}
class
ScoreDisplay
extends
Node
{
ScoreDisplay
(
this
.
_sheetUI
);
bool
_dirtyScore
=
true
;
int
_score
=
0
;
int
get
score
=>
_score
;
...
...
@@ -14,29 +76,21 @@ class PlayerState extends Node {
_dirtyScore
=
true
;
}
PlayerState
(
this
.
sheet
)
{
position
=
new
Point
(
310.0
,
10.0
);
scale
=
0.6
;
SpriteSheet
_sheetUI
;
sprtBgScore
=
new
Sprite
(
sheet
[
"scoreboard.png"
]);
sprtBgScore
.
pivot
=
new
Point
(
1.0
,
0.0
);
sprtBgScore
.
scale
=
0.6
;
addChild
(
sprtBgScore
);
}
bool
_dirtyScore
=
true
;
void
update
(
double
dt
)
{
// Update score
if
(
_dirtyScore
)
{
sprtBgScore
.
removeAllChildren
();
removeAllChildren
();
String
scoreStr
=
_score
.
toString
();
double
xPos
=
-
50
.0
;
double
xPos
=
-
37
.0
;
for
(
int
i
=
scoreStr
.
length
-
1
;
i
>=
0
;
i
--)
{
String
numStr
=
scoreStr
.
substring
(
i
,
i
+
1
);
Sprite
numSprt
=
new
Sprite
(
sheet
[
"number_
$numStr
.png"
]);
numSprt
.
position
=
new
Point
(
xPos
,
49
.0
);
sprtBgScore
.
addChild
(
numSprt
);
Sprite
numSprt
=
new
Sprite
(
_sheetUI
[
"number_
$numStr
.png"
]);
numSprt
.
position
=
new
Point
(
xPos
,
0
.0
);
addChild
(
numSprt
);
xPos
-=
37.0
;
}
_dirtyScore
=
false
;
...
...
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