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
d90ccd3a
Commit
d90ccd3a
authored
Aug 26, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves GameObjectFactory and PlayerState to their own files in demo game
parent
d7a7a2ed
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
94 deletions
+98
-94
game_demo.dart
examples/game/lib/game_demo.dart
+2
-0
game_demo_node.dart
examples/game/lib/game_demo_node.dart
+0
-94
game_object_factory.dart
examples/game/lib/game_object_factory.dart
+51
-0
player_state.dart
examples/game/lib/player_state.dart
+45
-0
No files found.
examples/game/lib/game_demo.dart
View file @
d90ccd3a
...
...
@@ -12,5 +12,7 @@ part 'explosions.dart';
part
'flash.dart'
;
part
'game_demo_node.dart'
;
part
'game_objects.dart'
;
part
'game_object_factory.dart'
;
part
'player_state.dart'
;
part
'repeated_image.dart'
;
part
'star_field.dart'
;
examples/game/lib/game_demo_node.dart
View file @
d90ccd3a
...
...
@@ -256,97 +256,3 @@ class Level extends Node {
return
position
.
y
;
}
}
enum
GameObjectType
{
asteroidBig
,
asteroidSmall
,
movingEnemy
,
coin
,
}
class
GameObjectFactory
{
GameObjectFactory
(
this
.
sheet
,
this
.
sounds
,
this
.
level
,
this
.
playerState
);
SpriteSheet
sheet
;
Map
<
String
,
SoundEffect
>
sounds
;
Level
level
;
PlayerState
playerState
;
void
addAsteroids
(
int
numAsteroids
,
double
yPos
,
double
distribution
)
{
for
(
int
i
=
0
;
i
<
numAsteroids
;
i
++)
{
GameObjectType
type
=
(
randomDouble
()
<
distribution
)
?
GameObjectType
.
asteroidBig
:
GameObjectType
.
asteroidSmall
;
Point
pos
=
new
Point
(
randomSignedDouble
()
*
160.0
,
yPos
+
_chunkSpacing
*
randomDouble
());
addGameObject
(
type
,
pos
);
}
}
void
addSwarm
(
int
numEnemies
,
double
yPos
)
{
for
(
int
i
=
0
;
i
<
numEnemies
;
i
++)
{
double
spacing
=
math
.
max
(
_chunkSpacing
/
(
numEnemies
+
1.0
),
80.0
);
double
y
=
yPos
+
_chunkSpacing
/
2.0
-
(
numEnemies
-
1
)
*
spacing
/
2.0
+
i
*
spacing
;
addGameObject
(
GameObjectType
.
movingEnemy
,
new
Point
(
0.0
,
y
));
}
}
void
addGameObject
(
GameObjectType
type
,
Point
pos
)
{
GameObject
obj
;
if
(
type
==
GameObjectType
.
asteroidBig
)
obj
=
new
AsteroidBig
(
this
);
else
if
(
type
==
GameObjectType
.
asteroidSmall
)
obj
=
new
AsteroidSmall
(
this
);
else
if
(
type
==
GameObjectType
.
movingEnemy
)
obj
=
new
MovingEnemy
(
this
);
else
if
(
type
==
GameObjectType
.
coin
)
obj
=
new
Coin
(
this
);
obj
.
position
=
pos
;
obj
.
setupActions
();
level
.
addChild
(
obj
);
}
}
class
PlayerState
extends
Node
{
SpriteSheet
sheet
;
Sprite
sprtBgScore
;
bool
_dirtyScore
=
true
;
int
_score
=
0
;
int
get
score
=>
_score
;
set
score
(
int
score
)
{
_score
=
score
;
_dirtyScore
=
true
;
}
PlayerState
(
this
.
sheet
)
{
position
=
new
Point
(
310.0
,
10.0
);
scale
=
0.6
;
sprtBgScore
=
new
Sprite
(
sheet
[
"scoreboard.png"
]);
sprtBgScore
.
pivot
=
new
Point
(
1.0
,
0.0
);
sprtBgScore
.
scale
=
0.6
;
addChild
(
sprtBgScore
);
}
void
update
(
double
dt
)
{
// Update score
if
(
_dirtyScore
)
{
sprtBgScore
.
removeAllChildren
();
String
scoreStr
=
_score
.
toString
();
double
xPos
=
-
50.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
);
xPos
-=
37.0
;
}
_dirtyScore
=
false
;
}
}
}
examples/game/lib/game_object_factory.dart
0 → 100644
View file @
d90ccd3a
part of
game
;
enum
GameObjectType
{
asteroidBig
,
asteroidSmall
,
movingEnemy
,
coin
,
}
class
GameObjectFactory
{
GameObjectFactory
(
this
.
sheet
,
this
.
sounds
,
this
.
level
,
this
.
playerState
);
SpriteSheet
sheet
;
Map
<
String
,
SoundEffect
>
sounds
;
Level
level
;
PlayerState
playerState
;
void
addAsteroids
(
int
numAsteroids
,
double
yPos
,
double
distribution
)
{
for
(
int
i
=
0
;
i
<
numAsteroids
;
i
++)
{
GameObjectType
type
=
(
randomDouble
()
<
distribution
)
?
GameObjectType
.
asteroidBig
:
GameObjectType
.
asteroidSmall
;
Point
pos
=
new
Point
(
randomSignedDouble
()
*
160.0
,
yPos
+
_chunkSpacing
*
randomDouble
());
addGameObject
(
type
,
pos
);
}
}
void
addSwarm
(
int
numEnemies
,
double
yPos
)
{
for
(
int
i
=
0
;
i
<
numEnemies
;
i
++)
{
double
spacing
=
math
.
max
(
_chunkSpacing
/
(
numEnemies
+
1.0
),
80.0
);
double
y
=
yPos
+
_chunkSpacing
/
2.0
-
(
numEnemies
-
1
)
*
spacing
/
2.0
+
i
*
spacing
;
addGameObject
(
GameObjectType
.
movingEnemy
,
new
Point
(
0.0
,
y
));
}
}
void
addGameObject
(
GameObjectType
type
,
Point
pos
)
{
GameObject
obj
;
if
(
type
==
GameObjectType
.
asteroidBig
)
obj
=
new
AsteroidBig
(
this
);
else
if
(
type
==
GameObjectType
.
asteroidSmall
)
obj
=
new
AsteroidSmall
(
this
);
else
if
(
type
==
GameObjectType
.
movingEnemy
)
obj
=
new
MovingEnemy
(
this
);
else
if
(
type
==
GameObjectType
.
coin
)
obj
=
new
Coin
(
this
);
obj
.
position
=
pos
;
obj
.
setupActions
();
level
.
addChild
(
obj
);
}
}
examples/game/lib/player_state.dart
0 → 100644
View file @
d90ccd3a
part of
game
;
class
PlayerState
extends
Node
{
SpriteSheet
sheet
;
Sprite
sprtBgScore
;
bool
_dirtyScore
=
true
;
int
_score
=
0
;
int
get
score
=>
_score
;
set
score
(
int
score
)
{
_score
=
score
;
_dirtyScore
=
true
;
}
PlayerState
(
this
.
sheet
)
{
position
=
new
Point
(
310.0
,
10.0
);
scale
=
0.6
;
sprtBgScore
=
new
Sprite
(
sheet
[
"scoreboard.png"
]);
sprtBgScore
.
pivot
=
new
Point
(
1.0
,
0.0
);
sprtBgScore
.
scale
=
0.6
;
addChild
(
sprtBgScore
);
}
void
update
(
double
dt
)
{
// Update score
if
(
_dirtyScore
)
{
sprtBgScore
.
removeAllChildren
();
String
scoreStr
=
_score
.
toString
();
double
xPos
=
-
50.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
);
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