2021-09-07 20:45:42 +00:00
|
|
|
import 'package:firo_runner/main.dart';
|
2021-09-03 23:29:18 +00:00
|
|
|
import 'package:flame/components.dart';
|
|
|
|
|
|
|
|
class GameState extends Component {
|
2021-09-05 22:36:36 +00:00
|
|
|
int start = 0;
|
|
|
|
bool isPaused = false;
|
|
|
|
int numCoins = 0;
|
|
|
|
int distance = 0;
|
2021-09-03 23:29:18 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void update(double dt) {
|
|
|
|
super.update(dt);
|
2021-09-05 22:36:36 +00:00
|
|
|
if (!isPaused) {
|
|
|
|
distance = DateTime.now().microsecondsSinceEpoch - start;
|
|
|
|
}
|
2021-09-03 23:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void addCoin() {
|
|
|
|
numCoins++;
|
|
|
|
}
|
|
|
|
|
2021-09-05 22:36:36 +00:00
|
|
|
void setUp() {
|
|
|
|
numCoins = 0;
|
|
|
|
distance = 0;
|
2021-09-03 23:29:18 +00:00
|
|
|
start = DateTime.now().microsecondsSinceEpoch;
|
2021-09-05 22:36:36 +00:00
|
|
|
isPaused = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPaused() {
|
|
|
|
isPaused = true;
|
2021-09-03 23:29:18 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 20:45:42 +00:00
|
|
|
int getLevel() {
|
|
|
|
if (distance > LEVEL7) {
|
|
|
|
return 7;
|
|
|
|
} else if (distance > LEVEL6) {
|
|
|
|
return 6;
|
|
|
|
} else if (distance > LEVEL5) {
|
|
|
|
return 5;
|
|
|
|
} else if (distance > LEVEL4) {
|
|
|
|
return 4;
|
|
|
|
} else if (distance > LEVEL3) {
|
|
|
|
return 3;
|
|
|
|
} else if (distance > LEVEL2) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 23:29:18 +00:00
|
|
|
double getVelocity() {
|
2021-09-05 22:36:36 +00:00
|
|
|
if (!isPaused) {
|
2021-09-07 20:45:42 +00:00
|
|
|
switch (getLevel()) {
|
|
|
|
case 7:
|
|
|
|
return 250.0;
|
|
|
|
case 6:
|
|
|
|
return 200.0;
|
|
|
|
case 5:
|
|
|
|
return 180.0;
|
|
|
|
case 4:
|
|
|
|
return 160.0;
|
|
|
|
case 3:
|
|
|
|
return 140.0;
|
|
|
|
case 2:
|
|
|
|
return 120.0;
|
|
|
|
default:
|
|
|
|
return 100.0;
|
2021-09-05 22:36:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
2021-09-03 23:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|