/
StatusComponent.dart
63 lines (53 loc) · 1.45 KB
/
StatusComponent.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
import 'dart:ui';
import 'package:flame/animation.dart';
import 'package:flame/components/animation_component.dart';
import 'package:flame/components/component.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
class StatusComponent extends BaseGame with TapDetector{
Size size;
CodyBoy codyBoy;
StatusComponent(this.size){
codyBoy=CodyBoy(size);
add(codyBoy);
}
@override
void update(double t) {
codyBoy.update(t);
super.update(t);
}
@override
void onTap() {
codyBoy.status=Status.crashed;
}
}
enum Status{running,crashed}
class CodyBoy extends PositionComponent{
AnimationComponent codyBoyRun;
AnimationComponent codyBoyCrash;
Status status=Status.running;
Size size;
CodyBoy(this.size):
codyBoyRun= AnimationComponent(70,80,Animation.sequenced(
"run.png", 4,amountPerRow: 4,stepTime: 0.2,textureHeight: 409,textureWidth: 294.75)),
codyBoyCrash=AnimationComponent(70,80,Animation.sequenced(
"crash.png", 2,amountPerRow: 2,stepTime: 0.2,textureHeight: 451,textureWidth: 321));
@override
void render(Canvas c) {
currentCodyBoy.render(c);
}
@override
void update(double dt) {
currentCodyBoy.y=size.height-80;
currentCodyBoy.update(dt);
super.update(dt);
}
PositionComponent get currentCodyBoy {
switch(status){
case Status.running:
return codyBoyRun;
case Status.crashed:
return codyBoyCrash;
}
}
}