forked from flame-engine/flame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
83 lines (68 loc) · 1.95 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import 'dart:math';
import 'package:pogo/game_engine.dart';
void main() async {
GestureInitializer.detectTaps = true;
await Assets.rasterCache.load('chopper.png');
runApp(Game().widget);
await Screen.waitForStartupSizing();
MainEntity();
}
class MainEntity extends GameEntity with GestureArea, TapDetector {
// Predefine some animation components.
final animation = AnimationComponent.fromRaster(
Assets.rasterCache.get('chopper.png'),
frameCount: 4,
frameWidth: 48,
frameHeight: 48,
frameDuration: 0.1,
);
final animationReversed = AnimationComponent.fromRaster(
Assets.rasterCache.get('chopper.png'),
frameCount: 4,
frameWidth: 48,
frameHeight: 48,
frameDuration: 0.1,
reverse: true,
);
// Entity constructor.
MainEntity() {
// Instantiate some animation entities.
AnimationPrefab(
animation,
position: Vector2(Screen.size.width * 0.3, 100),
rotationDeg: -90.0,
scale: Vector2(2.0, 2.0),
);
AnimationPrefab(
animationReversed,
position: Vector2(Screen.size.width * 0.7, 100),
rotationDeg: 90.0,
scale: Vector2(2.0, 2.0),
);
}
@override
void onTapDown(TapDownDetails details) {
addAnimation(details.globalPosition);
}
@override
void onTapUp(TapUpDetails details) {}
@override
void onTapCancel() {}
void addAnimation(Offset position) {
AnimationPrefab(
AnimationComponent.fromRaster(
Assets.rasterCache.get('chopper.png'),
frameCount: 4,
frameWidth: 48,
frameHeight: 48,
frameDuration: 0.2,
loop: false,
),
//position: Vector2(screenSize.width / 2, screenSize.height / 2),
position: Vector2(position.dx, position.dy),
rotation: Random().nextDouble() * 2 * pi,
scale: Vector2(3, 3) * (Random().nextDouble() + 0.1),
destroyOnFinish: true
);
}
}