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
a2286ee7
Commit
a2286ee7
authored
Aug 25, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #826 from vlidholt/master
Updates to demo game
parents
1813170a
59817111
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
49 deletions
+102
-49
action_spline.dart
examples/game/lib/action_spline.dart
+1
-1
constraint.dart
examples/game/lib/constraint.dart
+28
-4
game_demo.dart
examples/game/lib/game_demo.dart
+1
-0
game_demo_node.dart
examples/game/lib/game_demo_node.dart
+68
-44
util.dart
examples/game/lib/util.dart
+4
-0
No files found.
examples/game/lib/action_spline.dart
View file @
a2286ee7
...
...
@@ -24,11 +24,11 @@ class ActionSpline extends ActionInterval {
final
Function
setter
;
final
List
<
Point
>
points
;
double
tension
=
0.5
;
double
_dt
;
void
update
(
double
t
)
{
double
tension
=
0.5
;
int
p
;
double
lt
;
...
...
examples/game/lib/constraint.dart
View file @
a2286ee7
...
...
@@ -8,6 +8,9 @@ abstract class Constraint {
}
double
_dampenRotation
(
double
src
,
double
dst
,
double
dampening
)
{
if
(
dampening
==
null
)
return
dst
;
double
delta
=
dst
-
src
;
while
(
delta
>
180.0
)
delta
-=
360
;
while
(
delta
<
-
180
)
delta
+=
360
;
...
...
@@ -18,6 +21,7 @@ double _dampenRotation(double src, double dst, double dampening) {
class
ConstraintRotationToMovement
{
ConstraintRotationToMovement
([
this
.
baseRotation
=
0.0
,
this
.
dampening
]);
final
double
dampening
;
final
double
baseRotation
;
...
...
@@ -35,9 +39,29 @@ class ConstraintRotationToMovement {
Offset
offset
=
node
.
position
-
_lastPosition
;
double
target
=
degrees
(
GameMath
.
atan2
(
offset
.
dy
,
offset
.
dx
))
+
baseRotation
;
if
(
dampening
==
null
)
node
.
rotation
=
target
;
else
node
.
rotation
=
_dampenRotation
(
node
.
rotation
,
target
,
dampening
);
node
.
rotation
=
_dampenRotation
(
node
.
rotation
,
target
,
dampening
);
}
}
class
ConstraintRotationToNode
{
ConstraintRotationToNode
(
this
.
targetNode
,
[
this
.
baseRotation
,
this
.
dampening
]);
final
Node
targetNode
;
final
double
baseRotation
;
final
double
dampening
;
void
constrain
(
Node
node
,
double
dt
)
{
Offset
offset
;
if
(
targetNode
.
parent
==
node
.
parent
)
{
offset
=
targetNode
.
position
-
node
.
position
;
}
else
{
offset
=
node
.
convertPointToBoxSpace
(
Point
.
origin
)
-
targetNode
.
convertPointToBoxSpace
(
Point
.
origin
);
}
double
target
=
degrees
(
GameMath
.
atan2
(
offset
.
dy
,
offset
.
dx
))
+
baseRotation
;
node
.
rotation
=
_dampenRotation
(
node
.
rotation
,
target
,
dampening
);
}
}
examples/game/lib/game_demo.dart
View file @
a2286ee7
library
game
;
import
'dart:async'
;
import
'dart:math'
as
math
;
import
'dart:sky'
as
sky
;
import
'sprites.dart'
;
...
...
examples/game/lib/game_demo_node.dart
View file @
a2286ee7
...
...
@@ -3,6 +3,9 @@ part of game;
final
double
_gameSizeWidth
=
320.0
;
double
_gameSizeHeight
=
320.0
;
final
double
_chunkSpacing
=
640.0
;
final
int
_chunksPerLevel
=
5
;
final
bool
_drawDebug
=
false
;
class
GameDemoNode
extends
NodeWithSize
{
...
...
@@ -164,7 +167,6 @@ class GameDemoNode extends NodeWithSize {
}
int
_chunk
=
0
;
double
_chunkSpacing
=
640.0
;
void
addObjects
()
{
...
...
@@ -181,21 +183,24 @@ class GameDemoNode extends NodeWithSize {
if
(
chunk
==
0
)
{
// Leave the first chunk empty
return
;
}
else
if
(
chunk
==
1
)
{
addLevelAsteroids
(
10
,
yPos
,
0.0
);
}
else
{
addLevelAsteroids
(
9
+
chunk
,
yPos
,
0.5
);
}
}
void
addLevelAsteroids
(
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
());
_objectFactory
.
addGameObject
(
type
,
pos
);
chunk
-=
1
;
int
level
=
chunk
~/
_chunksPerLevel
;
int
part
=
chunk
%
_chunksPerLevel
;
if
(
part
==
0
)
{
_objectFactory
.
addAsteroids
(
10
+
level
*
4
,
yPos
,
0.0
+
(
level
*
0.2
).
clamp
(
0.0
,
0.7
));
}
else
if
(
part
==
1
)
{
_objectFactory
.
addSwarm
(
4
+
level
*
2
,
yPos
);
}
else
if
(
part
==
2
)
{
_objectFactory
.
addAsteroids
(
10
+
level
*
4
,
yPos
,
0.0
+
(
level
*
0.2
).
clamp
(
0.0
,
0.7
));
}
else
if
(
part
==
3
)
{
_objectFactory
.
addAsteroids
(
10
+
level
*
4
,
yPos
,
0.0
+
(
level
*
0.2
).
clamp
(
0.0
,
0.7
));
}
else
if
(
part
==
4
)
{
_objectFactory
.
addAsteroids
(
10
+
level
*
4
,
yPos
,
0.0
+
(
level
*
0.2
).
clamp
(
0.0
,
0.7
));
}
_objectFactory
.
addGameObject
(
GameObjectType
.
movingEnemy
,
new
Point
(
0.0
,
yPos
+
160.0
));
}
void
fire
()
{
...
...
@@ -389,7 +394,7 @@ abstract class Asteroid extends Obstacle {
void
setupActions
()
{
// Rotate obstacle
int
direction
=
1
;
if
(
random
Double
()
<
0.5
)
direction
=
-
1
;
if
(
random
Bool
()
)
direction
=
-
1
;
ActionTween
rotate
=
new
ActionTween
(
(
a
)
=>
_sprt
.
rotation
=
a
,
0.0
,
360.0
*
direction
,
5.0
+
5.0
*
randomDouble
());
...
...
@@ -434,20 +439,45 @@ class MovingEnemy extends Obstacle {
constraints
=
[
new
ConstraintRotationToMovement
(
0.0
,
0.5
)];
}
final
double
_swirlSpacing
=
80.0
;
_addRandomSquare
(
List
<
Offset
>
offsets
,
double
x
,
double
y
)
{
double
xMove
=
(
randomBool
())
?
_swirlSpacing
:
-
_swirlSpacing
;
double
yMove
=
(
randomBool
())
?
_swirlSpacing
:
-
_swirlSpacing
;
if
(
randomBool
())
{
offsets
.
addAll
([
new
Offset
(
x
,
y
),
new
Offset
(
xMove
+
x
,
y
),
new
Offset
(
xMove
+
x
,
yMove
+
y
),
new
Offset
(
x
,
yMove
+
y
),
new
Offset
(
x
,
y
)
]);
}
else
{
offsets
.
addAll
([
new
Offset
(
x
,
y
),
new
Offset
(
x
,
y
+
yMove
),
new
Offset
(
xMove
+
x
,
yMove
+
y
),
new
Offset
(
xMove
+
x
,
y
),
new
Offset
(
x
,
y
)
]);
}
}
void
setupActions
()
{
List
<
Offset
>
offsets
=
[
new
Offset
(-
160.0
,
160.0
),
new
Offset
(-
80.0
,
-
160.0
),
new
Offset
(
0.0
,
160.0
),
new
Offset
(
80.0
,
-
160.0
),
new
Offset
(
160.0
,
160.0
)];
List
<
Offset
>
offsets
=
[];
_addRandomSquare
(
offsets
,
-
_swirlSpacing
,
0.0
);
_addRandomSquare
(
offsets
,
_swirlSpacing
,
0.0
);
offsets
.
add
(
new
Offset
(-
_swirlSpacing
,
0.0
));
List
<
Point
>
points
=
[];
for
(
Offset
offset
in
offsets
)
{
points
.
add
(
position
+
offset
);
}
ActionSpline
spline
=
new
ActionSpline
((
a
)
=>
position
=
a
,
points
,
4.0
);
ActionSpline
spline
=
new
ActionSpline
((
a
)
=>
position
=
a
,
points
,
6.0
);
spline
.
tension
=
0.7
;
actions
.
run
(
new
ActionRepeatForever
(
spline
));
}
...
...
@@ -467,6 +497,23 @@ class GameObjectFactory {
Map
<
String
,
SoundEffect
>
sounds
;
Level
level
;
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
)
...
...
@@ -483,29 +530,6 @@ class GameObjectFactory {
}
}
// class MovingObstacle extends Obstacle {
// MovingObstacle(SpriteSheet sheet, Map<String,SoundEffect> effects, ObstacleType type) : super (sheet, effects, type);
//
// void setupAction() {
// actions.stopAll();
//
// List<Offset> offsets = [
// new Offset(-160.0, 160.0),
// new Offset(-80.0, -160.0),
// new Offset(0.0, 160.0),
// new Offset(80.0, -160.0),
// new Offset(160.0, 160.0)];
//
// List<Point> points = [];
// for (Offset offset in offsets) {
// points.add(position + offset);
// }
//
// ActionSpline spline = new ActionSpline((a) => position = a, points, 4.0);
// actions.run(new ActionRepeatForever(spline));
// }
// }
class
StarField
extends
NodeWithSize
{
sky
.
Image
_image
;
SpriteSheet
_spriteSheet
;
...
...
examples/game/lib/util.dart
View file @
a2286ee7
...
...
@@ -17,6 +17,10 @@ int randomInt(int max) {
return
_random
.
nextInt
(
max
);
}
bool
randomBool
(
)
{
return
_random
.
nextDouble
()
<
0.5
;
}
// atan2
class
_Atan2Constants
{
...
...
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