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
8c958f97
Commit
8c958f97
authored
Sep 03, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactors code in demo game to make it simpler
parent
20809bc9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
35 deletions
+16
-35
game_object_factory.dart
examples/game/lib/game_object_factory.dart
+15
-32
game_objects.dart
examples/game/lib/game_objects.dart
+1
-3
No files found.
examples/game/lib/game_object_factory.dart
View file @
8c958f97
part of
game
;
enum
GameObjectType
{
asteroidBig
,
asteroidSmall
,
asteroidPowerUp
,
enemyScout
,
enemyDestroyer
,
coin
,
}
class
GameObjectFactory
{
GameObjectFactory
(
this
.
sheet
,
this
.
sounds
,
this
.
level
,
this
.
playerState
);
...
...
@@ -19,11 +10,17 @@ class GameObjectFactory {
void
addAsteroids
(
int
numAsteroids
,
double
yPos
,
double
distribution
)
{
for
(
int
i
=
0
;
i
<
numAsteroids
;
i
++)
{
GameObjectType
type
=
(
randomDouble
()
<
distribution
)
?
GameObjectType
.
asteroidBig
:
GameObjectType
.
asteroidSmall
;
if
(
i
==
0
)
type
=
GameObjectType
.
asteroidPowerUp
;
GameObject
obj
;
if
(
i
==
0
)
obj
=
new
AsteroidPowerUp
(
this
);
else
if
(
randomDouble
()
<
distribution
)
obj
=
new
AsteroidBig
(
this
);
else
obj
=
new
AsteroidSmall
(
this
);
Point
pos
=
new
Point
(
randomSignedDouble
()
*
160.0
,
yPos
+
_chunkSpacing
*
randomDouble
());
addGameObject
(
type
,
pos
);
addGameObject
(
obj
,
pos
);
}
}
...
...
@@ -31,31 +28,17 @@ class GameObjectFactory {
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
.
enemyScout
,
new
Point
(
0.0
,
y
));
addGameObject
(
new
EnemyScout
(
this
)
,
new
Point
(
0.0
,
y
));
}
}
void
addEnemyDestroyerSwarm
(
int
numEnemies
,
double
yPos
)
{
for
(
int
i
=
0
;
i
<
numEnemies
;
i
++)
{
addGameObject
(
GameObjectType
.
enemyDestroyer
,
new
Point
(
randomSignedDouble
()
*
120.0
,
yPos
+
_chunkSpacing
*
randomDouble
()));
addGameObject
(
new
EnemyDestroyer
(
this
)
,
new
Point
(
randomSignedDouble
()
*
120.0
,
yPos
+
_chunkSpacing
*
randomDouble
()));
}
}
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
.
asteroidPowerUp
)
obj
=
new
AsteroidPowerUp
(
this
);
else
if
(
type
==
GameObjectType
.
enemyScout
)
obj
=
new
EnemyScout
(
this
);
else
if
(
type
==
GameObjectType
.
enemyDestroyer
)
obj
=
new
EnemyDestroyer
(
this
);
else
if
(
type
==
GameObjectType
.
coin
)
obj
=
new
Coin
(
this
);
void
addGameObject
(
GameObject
obj
,
Point
pos
)
{
obj
.
position
=
pos
;
obj
.
setupActions
();
...
...
@@ -64,10 +47,10 @@ class GameObjectFactory {
void
addBossFight
(
int
l
,
double
yPos
)
{
EnemyBoss
boss
=
new
EnemyBoss
(
this
);
boss
.
position
=
new
Point
(
0.0
,
yPos
+
_chunkSpacing
/
2.0
);
boss
.
setupActions
();
Point
pos
=
new
Point
(
0.0
,
yPos
+
_chunkSpacing
/
2.0
);
addGameObject
(
boss
,
pos
);
level
.
addChild
(
boss
);
playerState
.
boss
=
boss
;
}
}
examples/game/lib/game_objects.dart
View file @
8c958f97
...
...
@@ -44,9 +44,7 @@ abstract class GameObject extends Node {
Collectable
powerUp
=
createPowerUp
();
if
(
powerUp
!=
null
)
{
powerUp
.
position
=
position
;
powerUp
.
setupActions
();
parent
.
addChild
(
powerUp
);
f
.
addGameObject
(
powerUp
,
position
);
}
removeFromParent
();
...
...
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