/
main.dart
84 lines (65 loc) · 1.98 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
84
import 'package:pogo/game_engine.dart';
import 'package:pogo_rive/plugin.dart';
// Shows use of RiveComponent, RivePrefab along with single- and double-tap
// functionality.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Screen.setFullScreen();
await Screen.setPortrait();
GestureInitializer.detectSingleTaps = true;
GestureInitializer.detectDoubleTaps = true;
Game().debugMode = true; // turn off if debug visualizations not wanted
runApp(Game().widget);
await Screen.waitForStartupSizing();
MainEntity();
}
class MainEntity extends GameEntity {
final TextConfig fpsTextConfig = const TextConfig(color: const Color(0xFFFFFFFF));
TextPrefab fpsText;
MainEntity() {
Player(Vector2(Screen.size.width / 2, Screen.size.height / 2));
fpsText = TextPrefab(
TextComponent("", textConfig: fpsTextConfig, pivot: Pivot.topLeft),
position: Vector2(0, 20),
enabled: false,
);
}
@override
void update() {
fpsText.enabled = Game().debugMode;
if (fpsText.enabled) {
fpsText.textComponent.text = Game().fps(120).toStringAsFixed(1);
}
}
}
class Player extends GameEntity with SingleTapDetector, DoubleTapDetector {
Size screenSize;
final List<String> _animations = ["Stand", "Wave", "Jump", "Dance"];
int _currentAnimation = 0;
RivePrefab riveAnim;
bool loaded = false;
Player(Vector2 position) {
this.position = position;
RiveComponent.fromFile("assets/Bob_Minion.flr", "Stand", scale: 0.33)
.then((comp) => riveAnim = RivePrefab(comp, parent: this))
;
}
@override
void onSingleTap() {
cycleAnimation();
}
@override
void onDoubleTap() {
riveAnim.scale.x += 0.1;
riveAnim.scale.y += 0.1;
riveAnim.position.y += 20;
}
void cycleAnimation() {
if (_currentAnimation == _animations.length - 1) {
_currentAnimation = 0;
} else {
_currentAnimation++;
}
riveAnim.riveComponent.setAnimation(_animations[_currentAnimation]);
}
}