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
d1a56611
Commit
d1a56611
authored
Sep 04, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1050 from vlidholt/master
Demo game improvements
parents
7d11cfa4
eb3f30ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
4 deletions
+61
-4
game_objects.dart
examples/game/lib/game_objects.dart
+26
-4
constraint.dart
packages/flutter_sprites/lib/constraint.dart
+31
-0
util.dart
packages/flutter_sprites/lib/util.dart
+4
-0
No files found.
examples/game/lib/game_objects.dart
View file @
d1a56611
...
...
@@ -426,9 +426,13 @@ class EnemyBoss extends Obstacle {
constraints
=
[
new
ConstraintRotationToNode
(
f
.
level
.
ship
,
dampening:
0.05
)];
_powerBar
=
new
PowerBar
(
new
Size
(
60.0
,
10.0
));
_powerBar
.
position
=
new
Point
(-
80.0
,
0.0
);
_powerBar
.
pivot
=
new
Point
(
0.5
,
0.5
);
addChild
(
_powerBar
);
f
.
level
.
addChild
(
_powerBar
);
_powerBar
.
constraints
=
[
new
ConstraintPositionToNode
(
this
,
dampening:
0.5
,
offset:
new
Offset
(
0.0
,
-
70.0
)
)];
}
Sprite
_sprt
;
...
...
@@ -446,8 +450,6 @@ class EnemyBoss extends Obstacle {
_countDown
=
60
+
randomInt
(
120
);
}
_powerBar
.
rotation
=
-
rotation
;
}
void
fire
(
double
r
)
{
...
...
@@ -468,7 +470,27 @@ class EnemyBoss extends Obstacle {
void
destroy
()
{
f
.
playerState
.
boss
=
null
;
_powerBar
.
removeFromParent
();
// Flash the screen
NodeWithSize
screen
=
f
.
playerState
.
parent
;
screen
.
addChild
(
new
Flash
(
screen
.
size
,
1.0
));
super
.
destroy
();
// Add coins
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
Coin
coin
=
new
Coin
(
f
);
Point
pos
=
new
Point
(
randomSignedDouble
()
*
160
,
position
.
y
+
randomSignedDouble
()
*
160.0
);
f
.
addGameObject
(
coin
,
pos
);
}
}
Explosion
createExplosion
()
{
ExplosionBig
explo
=
new
ExplosionBig
(
f
.
sheet
);
explo
.
scale
=
1.5
;
return
explo
;
}
set
damage
(
double
d
)
{
...
...
packages/flutter_sprites/lib/constraint.dart
View file @
d1a56611
...
...
@@ -70,3 +70,34 @@ class ConstraintRotationToNode extends Constraint {
node
.
rotation
=
_dampenRotation
(
node
.
rotation
,
target
,
dampening
);
}
}
class
ConstraintPositionToNode
extends
Constraint
{
ConstraintPositionToNode
(
this
.
targetNode
,
{
this
.
dampening
,
this
.
offset
:
Offset
.
zero
});
final
Node
targetNode
;
final
Offset
offset
;
final
double
dampening
;
void
constrain
(
Node
node
,
double
dt
)
{
Point
targetPosition
;
if
(
targetNode
.
spriteBox
!=
node
.
spriteBox
||
node
.
parent
==
null
)
{
// The target node is in another sprite box or has been removed
return
;
}
if
(
targetNode
.
parent
==
node
.
parent
)
{
targetPosition
=
targetNode
.
position
;
}
else
{
targetPosition
=
node
.
parent
.
convertPointFromNode
(
Point
.
origin
,
targetNode
);
}
if
(
offset
!=
null
)
targetPosition
+=
offset
;
if
(
dampening
==
null
)
node
.
position
=
targetPosition
;
else
node
.
position
=
GameMath
.
filterPoint
(
node
.
position
,
targetPosition
,
dampening
);
}
}
packages/flutter_sprites/lib/util.dart
View file @
d1a56611
...
...
@@ -101,4 +101,8 @@ class GameMath {
static
double
filter
(
double
a
,
double
b
,
double
filterFactor
)
{
return
(
a
*
(
1
-
filterFactor
))
+
b
*
filterFactor
;
}
static
Point
filterPoint
(
Point
a
,
Point
b
,
double
filterFactor
)
{
return
new
Point
(
filter
(
a
.
x
,
b
.
x
,
filterFactor
),
filter
(
a
.
y
,
b
.
y
,
filterFactor
));
}
}
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