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
34e0ef83
Commit
34e0ef83
authored
Aug 25, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #795 from vlidholt/master
Additions to demo game
parents
f8cad61b
af6372fd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
65 deletions
+103
-65
constraint.dart
examples/game/lib/constraint.dart
+4
-3
game_demo.dart
examples/game/lib/game_demo.dart
+0
-1
game_demo_node.dart
examples/game/lib/game_demo_node.dart
+36
-61
sprites.dart
examples/game/lib/sprites.dart
+1
-0
virtual_joystick.dart
examples/game/lib/virtual_joystick.dart
+62
-0
No files found.
examples/game/lib/constraint.dart
View file @
34e0ef83
...
...
@@ -17,8 +17,9 @@ double _dampenRotation(double src, double dst, double dampening) {
}
class
ConstraintRotationToMovement
{
ConstraintRotationToMovement
([
this
.
dampening
]);
ConstraintRotationToMovement
([
this
.
baseRotation
=
0.0
,
this
.
dampening
]);
final
double
dampening
;
final
double
baseRotation
;
Point
_lastPosition
;
...
...
@@ -27,12 +28,12 @@ class ConstraintRotationToMovement {
}
void
constrain
(
Node
node
,
double
dt
)
{
assert
(
_lastPosition
!=
null
)
;
if
(
_lastPosition
==
null
)
return
;
if
(
_lastPosition
==
node
.
position
)
return
;
// Get the target angle
Offset
offset
=
node
.
position
-
_lastPosition
;
double
target
=
degrees
(
GameMath
.
atan2
(
offset
.
dy
,
offset
.
dx
));
double
target
=
degrees
(
GameMath
.
atan2
(
offset
.
dy
,
offset
.
dx
))
+
baseRotation
;
if
(
dampening
==
null
)
node
.
rotation
=
target
;
...
...
examples/game/lib/game_demo.dart
View file @
34e0ef83
...
...
@@ -6,6 +6,5 @@ import 'sprites.dart';
import
'package:sky/rendering/object.dart'
;
import
'package:sky/widgets/framework.dart'
;
import
'package:sky/animation/curves.dart'
;
part
'game_demo_node.dart'
;
examples/game/lib/game_demo_node.dart
View file @
34e0ef83
...
...
@@ -48,7 +48,7 @@ class GameDemoNode extends NodeWithSize {
_hud
=
new
Hud
(
_spritesUI
);
addChild
(
_hud
);
// Add initial game objects
addObjects
();
}
...
...
@@ -195,6 +195,7 @@ class GameDemoNode extends NodeWithSize {
yPos
+
_chunkSpacing
*
randomDouble
());
_objectFactory
.
addGameObject
(
type
,
pos
);
}
_objectFactory
.
addGameObject
(
GameObjectType
.
movingEnemy
,
new
Point
(
0.0
,
yPos
+
160.0
));
}
void
fire
()
{
...
...
@@ -233,66 +234,6 @@ class GameDemoNode extends NodeWithSize {
}
}
class
VirtualJoystick
extends
NodeWithSize
{
VirtualJoystick
()
:
super
(
new
Size
(
160.0
,
160.0
))
{
userInteractionEnabled
=
true
;
handleMultiplePointers
=
false
;
position
=
new
Point
(
160.0
,
-
20.0
);
pivot
=
new
Point
(
0.5
,
1.0
);
_center
=
new
Point
(
size
.
width
/
2.0
,
size
.
height
/
2.0
);
_handlePos
=
_center
;
_paintHandle
=
new
Paint
()
..
color
=
new
Color
(
0xffffffff
);
_paintControl
=
new
Paint
()
..
color
=
new
Color
(
0xffffffff
)
..
strokeWidth
=
1.0
..
setStyle
(
sky
.
PaintingStyle
.
stroke
);
}
Point
value
=
Point
.
origin
;
bool
_isDown
=
false
;
bool
get
isDown
=>
_isDown
;
Point
_pointerDownAt
;
Point
_center
;
Point
_handlePos
;
Paint
_paintHandle
;
Paint
_paintControl
;
bool
handleEvent
(
SpriteBoxEvent
event
)
{
if
(
event
.
type
==
"pointerdown"
)
{
_pointerDownAt
=
event
.
boxPosition
;
actions
.
stopAll
();
_isDown
=
true
;
}
else
if
(
event
.
type
==
"pointerup"
||
event
.
type
==
"pointercancel"
)
{
_pointerDownAt
=
null
;
value
=
Point
.
origin
;
ActionTween
moveToCenter
=
new
ActionTween
((
a
)
=>
_handlePos
=
a
,
_handlePos
,
_center
,
0.4
,
elasticOut
);
actions
.
run
(
moveToCenter
);
_isDown
=
false
;
}
else
if
(
event
.
type
==
"pointermove"
)
{
Offset
movedDist
=
event
.
boxPosition
-
_pointerDownAt
;
value
=
new
Point
(
(
movedDist
.
dx
/
80.0
).
clamp
(-
1.0
,
1.0
),
(
movedDist
.
dy
/
80.0
).
clamp
(-
1.0
,
1.0
));
_handlePos
=
_center
+
new
Offset
(
value
.
x
*
40.0
,
value
.
y
*
40.0
);
}
return
true
;
}
void
paint
(
PaintingCanvas
canvas
)
{
applyTransformForPivot
(
canvas
);
canvas
.
drawCircle
(
_handlePos
,
25.0
,
_paintHandle
);
canvas
.
drawCircle
(
_center
,
40.0
,
_paintControl
);
}
}
class
Level
extends
Node
{
Level
()
{
position
=
new
Point
(
160.0
,
0.0
);
...
...
@@ -482,9 +423,41 @@ class AsteroidSmall extends Asteroid {
}
}
class
MovingEnemy
extends
Obstacle
{
MovingEnemy
(
GameObjectFactory
f
)
:
super
(
f
)
{
_sprt
=
new
Sprite
(
f
.
sheet
[
"ship.png"
]);
_sprt
.
scale
=
0.2
;
radius
=
12.0
;
maxDamage
=
2.0
;
addChild
(
_sprt
);
constraints
=
[
new
ConstraintRotationToMovement
(
0.0
,
0.5
)];
}
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
<
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
));
}
Sprite
_sprt
;
}
enum
GameObjectType
{
asteroidBig
,
asteroidSmall
,
movingEnemy
,
}
class
GameObjectFactory
{
...
...
@@ -500,6 +473,8 @@ class GameObjectFactory {
obj
=
new
AsteroidBig
(
this
);
else
if
(
type
==
GameObjectType
.
asteroidSmall
)
obj
=
new
AsteroidSmall
(
this
);
else
if
(
type
==
GameObjectType
.
movingEnemy
)
obj
=
new
MovingEnemy
(
this
);
obj
.
position
=
pos
;
obj
.
setupActions
();
...
...
examples/game/lib/sprites.dart
View file @
34e0ef83
...
...
@@ -39,3 +39,4 @@ part 'sprite_box.dart';
part
'sprite_widget.dart'
;
part
'texture.dart'
;
part
'util.dart'
;
part
'virtual_joystick.dart'
;
examples/game/lib/virtual_joystick.dart
0 → 100644
View file @
34e0ef83
part of
sprites
;
class
VirtualJoystick
extends
NodeWithSize
{
VirtualJoystick
()
:
super
(
new
Size
(
160.0
,
160.0
))
{
userInteractionEnabled
=
true
;
handleMultiplePointers
=
false
;
position
=
new
Point
(
160.0
,
-
20.0
);
pivot
=
new
Point
(
0.5
,
1.0
);
_center
=
new
Point
(
size
.
width
/
2.0
,
size
.
height
/
2.0
);
_handlePos
=
_center
;
_paintHandle
=
new
Paint
()
..
color
=
new
Color
(
0xffffffff
);
_paintControl
=
new
Paint
()
..
color
=
new
Color
(
0xffffffff
)
..
strokeWidth
=
1.0
..
setStyle
(
PaintingStyle
.
stroke
);
}
Point
_value
=
Point
.
origin
;
Point
get
value
=>
_value
;
bool
_isDown
=
false
;
bool
get
isDown
=>
_isDown
;
Point
_pointerDownAt
;
Point
_center
;
Point
_handlePos
;
Paint
_paintHandle
;
Paint
_paintControl
;
bool
handleEvent
(
SpriteBoxEvent
event
)
{
if
(
event
.
type
==
"pointerdown"
)
{
_pointerDownAt
=
event
.
boxPosition
;
actions
.
stopAll
();
_isDown
=
true
;
}
else
if
(
event
.
type
==
"pointerup"
||
event
.
type
==
"pointercancel"
)
{
_pointerDownAt
=
null
;
_value
=
Point
.
origin
;
ActionTween
moveToCenter
=
new
ActionTween
((
a
)
=>
_handlePos
=
a
,
_handlePos
,
_center
,
0.4
,
elasticOut
);
actions
.
run
(
moveToCenter
);
_isDown
=
false
;
}
else
if
(
event
.
type
==
"pointermove"
)
{
Offset
movedDist
=
event
.
boxPosition
-
_pointerDownAt
;
_value
=
new
Point
(
(
movedDist
.
dx
/
80.0
).
clamp
(-
1.0
,
1.0
),
(
movedDist
.
dy
/
80.0
).
clamp
(-
1.0
,
1.0
));
_handlePos
=
_center
+
new
Offset
(
_value
.
x
*
40.0
,
_value
.
y
*
40.0
);
}
return
true
;
}
void
paint
(
PaintingCanvas
canvas
)
{
applyTransformForPivot
(
canvas
);
canvas
.
drawCircle
(
_handlePos
,
25.0
,
_paintHandle
);
canvas
.
drawCircle
(
_center
,
40.0
,
_paintControl
);
}
}
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