Added comments
This commit is contained in:
parent
12654cf5b0
commit
9f99a6a731
@ -9,6 +9,7 @@ import 'package:audioplayers/src/api/player_mode.dart';
|
|||||||
|
|
||||||
enum FireworkState { normal }
|
enum FireworkState { normal }
|
||||||
|
|
||||||
|
// Class that shoots off fireworks whenever the game speeds up.
|
||||||
class Firework extends Component {
|
class Firework extends Component {
|
||||||
MyGame gameRef;
|
MyGame gameRef;
|
||||||
late SpriteAnimationGroupComponent sprite1;
|
late SpriteAnimationGroupComponent sprite1;
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
|
|
||||||
|
// Class the holds the game state and several functions related to score and
|
||||||
|
// speed.
|
||||||
class GameState extends Component {
|
class GameState extends Component {
|
||||||
int start = 0;
|
int start = 0;
|
||||||
bool isPaused = false;
|
bool isPaused = false;
|
||||||
int numCoins = 0;
|
int numCoins = 0;
|
||||||
int distance = 0;
|
int time = 0;
|
||||||
late MyGame gameRef;
|
late MyGame gameRef;
|
||||||
int previousLevel = 1;
|
int previousLevel = 1;
|
||||||
|
|
||||||
@ -13,7 +15,7 @@ class GameState extends Component {
|
|||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
super.update(dt);
|
super.update(dt);
|
||||||
if (!isPaused) {
|
if (!isPaused) {
|
||||||
distance = DateTime.now().microsecondsSinceEpoch - start;
|
time = DateTime.now().microsecondsSinceEpoch - start;
|
||||||
if (previousLevel != getLevel()) {
|
if (previousLevel != getLevel()) {
|
||||||
previousLevel = getLevel();
|
previousLevel = getLevel();
|
||||||
gameRef.fireworks.reset();
|
gameRef.fireworks.reset();
|
||||||
@ -28,7 +30,7 @@ class GameState extends Component {
|
|||||||
void setUp(MyGame gameRef) {
|
void setUp(MyGame gameRef) {
|
||||||
this.gameRef = gameRef;
|
this.gameRef = gameRef;
|
||||||
numCoins = 0;
|
numCoins = 0;
|
||||||
distance = 0;
|
time = 0;
|
||||||
previousLevel = 1;
|
previousLevel = 1;
|
||||||
start = DateTime.now().microsecondsSinceEpoch;
|
start = DateTime.now().microsecondsSinceEpoch;
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
@ -38,24 +40,26 @@ class GameState extends Component {
|
|||||||
isPaused = true;
|
isPaused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the level of the game.
|
||||||
int getLevel() {
|
int getLevel() {
|
||||||
if (distance > LEVEL7) {
|
if (time > LEVEL7) {
|
||||||
return 7;
|
return 7;
|
||||||
} else if (distance > LEVEL6) {
|
} else if (time > LEVEL6) {
|
||||||
return 6;
|
return 6;
|
||||||
} else if (distance > LEVEL5) {
|
} else if (time > LEVEL5) {
|
||||||
return 5;
|
return 5;
|
||||||
} else if (distance > LEVEL4) {
|
} else if (time > LEVEL4) {
|
||||||
return 4;
|
return 4;
|
||||||
} else if (distance > LEVEL3) {
|
} else if (time > LEVEL3) {
|
||||||
return 3;
|
return 3;
|
||||||
} else if (distance > LEVEL2) {
|
} else if (time > LEVEL2) {
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This determines the stages of the games and its animations.
|
||||||
int getScoreLevel() {
|
int getScoreLevel() {
|
||||||
int score = getScore();
|
int score = getScore();
|
||||||
if (score > LEVEL7) {
|
if (score > LEVEL7) {
|
||||||
@ -87,6 +91,8 @@ class GameState extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets the danger level of the game, this determines the appearance of
|
||||||
|
// obstacles in the beginning of the game.
|
||||||
int getDangerLevel() {
|
int getDangerLevel() {
|
||||||
int score = getScore();
|
int score = getScore();
|
||||||
if (score > LEVEL2 / 2 + LEVEL2 / (2 * 4)) {
|
if (score > LEVEL2 / 2 + LEVEL2 / (2 * 4)) {
|
||||||
@ -104,18 +110,23 @@ class GameState extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This score is used to determine the danger level of the game,
|
||||||
|
// and progression.
|
||||||
int getScore() {
|
int getScore() {
|
||||||
return distance ~/ 10 + numCoins * 1000000;
|
return time ~/ 10 + numCoins * 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the real score that the player sees.
|
||||||
int getPlayerScore() {
|
int getPlayerScore() {
|
||||||
return getScore() ~/ 10000;
|
return getScore() ~/ 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPlayerDistance() {
|
// Gets how long the player has been playing the game.
|
||||||
return distance ~/ 1000000;
|
int getPlayerTime() {
|
||||||
|
return time ~/ 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the relative pixel velocity at the current moment.
|
||||||
double getVelocity() {
|
double getVelocity() {
|
||||||
if (!isPaused) {
|
if (!isPaused) {
|
||||||
switch (getLevel()) {
|
switch (getLevel()) {
|
||||||
@ -139,6 +150,7 @@ class GameState extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the level of the Robot, used to determine what animations it uses.
|
||||||
int getRobotLevel() {
|
int getRobotLevel() {
|
||||||
if (numCoins > COINS_ROBOT_UPGRADE2) {
|
if (numCoins > COINS_ROBOT_UPGRADE2) {
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -24,6 +24,7 @@ class BugHolder extends Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a bug on the indicated level if it is possible.
|
||||||
bool generateBug(MyGame gameRef, int level,
|
bool generateBug(MyGame gameRef, int level,
|
||||||
{bool force = false, double xPosition = 0}) {
|
{bool force = false, double xPosition = 0}) {
|
||||||
if (objects[level].isNotEmpty) {
|
if (objects[level].isNotEmpty) {
|
||||||
|
@ -12,8 +12,10 @@ class Holder {
|
|||||||
|
|
||||||
late List<List<MovingObject>> objects = [];
|
late List<List<MovingObject>> objects = [];
|
||||||
|
|
||||||
|
// Load method to be overridden by classes that extend this.
|
||||||
Future load() async {}
|
Future load() async {}
|
||||||
|
|
||||||
|
// Basic method to reset the state of the holder object.
|
||||||
void setUp() {
|
void setUp() {
|
||||||
for (int i = 0; i < objects.length; i++) {
|
for (int i = 0; i < objects.length; i++) {
|
||||||
for (int j = 0; j < objects[i].length; j++) {
|
for (int j = 0; j < objects[i].length; j++) {
|
||||||
@ -26,6 +28,7 @@ class Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the total amount of objects currently in the logical game.
|
||||||
int total() {
|
int total() {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (List<MovingObject> levelObjects in objects) {
|
for (List<MovingObject> levelObjects in objects) {
|
||||||
@ -34,6 +37,7 @@ class Holder {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update every object that this holder holds.
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
for (List<MovingObject> objectLevel in objects) {
|
for (List<MovingObject> objectLevel in objects) {
|
||||||
for (MovingObject p in objectLevel) {
|
for (MovingObject p in objectLevel) {
|
||||||
@ -42,11 +46,13 @@ class Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove and object from this holder.
|
||||||
void remove(List<MovingObject> levelHolder, int j) {
|
void remove(List<MovingObject> levelHolder, int j) {
|
||||||
levelHolder[j].remove();
|
levelHolder[j].remove();
|
||||||
levelHolder.removeAt(j);
|
levelHolder.removeAt(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove any object is past rendering distance.
|
||||||
void removePast(MyGame gameRef) {
|
void removePast(MyGame gameRef) {
|
||||||
for (List<MovingObject> objectLevel in objects) {
|
for (List<MovingObject> objectLevel in objects) {
|
||||||
for (int i = 0; i < objectLevel.length;) {
|
for (int i = 0; i < objectLevel.length;) {
|
||||||
@ -59,6 +65,7 @@ class Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resize this object for screen rotations or changing window size.
|
||||||
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
for (List<MovingObject> platformLevel in objects) {
|
for (List<MovingObject> platformLevel in objects) {
|
||||||
for (MovingObject p in platformLevel) {
|
for (MovingObject p in platformLevel) {
|
||||||
@ -67,6 +74,7 @@ class Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load sprites dynamically.
|
||||||
Future<List<Sprite>> loadListSprites(
|
Future<List<Sprite>> loadListSprites(
|
||||||
String folderName, String extraName, int howManyFrames) async {
|
String folderName, String extraName, int howManyFrames) async {
|
||||||
List<Sprite> sprites = [];
|
List<Sprite> sprites = [];
|
||||||
|
@ -37,10 +37,14 @@ class PlatformHolder extends Holder {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes obstacles from around openings in the floor so that the game is
|
||||||
|
// not unfair to the player.
|
||||||
void removeUnfairObstacles(
|
void removeUnfairObstacles(
|
||||||
MyGame gameRef, Platform currentPlatform, int from, int to) {
|
MyGame gameRef, Platform currentPlatform, int from, int to) {
|
||||||
for (int i = from; i <= to; i++) {
|
for (int i = from; i <= to; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
// First level has a harder difficulty curve, and no platforms are on
|
||||||
|
// level -1, so objects have to be removed differently.
|
||||||
List<MovingObject> bugLevel = gameRef.bugHolder.objects[0];
|
List<MovingObject> bugLevel = gameRef.bugHolder.objects[0];
|
||||||
for (MovingObject bug in gameRef.bugHolder.objects[0]) {
|
for (MovingObject bug in gameRef.bugHolder.objects[0]) {
|
||||||
if (bug.sprite.x >= currentPlatform.sprite.x &&
|
if (bug.sprite.x >= currentPlatform.sprite.x &&
|
||||||
@ -58,6 +62,7 @@ class PlatformHolder extends Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// All other objects on the other levels can be removed simply.
|
||||||
int nearestPlatform = getNearestPlatform(i);
|
int nearestPlatform = getNearestPlatform(i);
|
||||||
for (MovingObject platform in objects[nearestPlatform]) {
|
for (MovingObject platform in objects[nearestPlatform]) {
|
||||||
if (platform.sprite.x >= currentPlatform.sprite.x &&
|
if (platform.sprite.x >= currentPlatform.sprite.x &&
|
||||||
@ -71,6 +76,8 @@ class PlatformHolder extends Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate all the platforms in the game.
|
||||||
|
// Including top openings, and bottom structures.
|
||||||
void generatePlatforms(MyGame gameRef) {
|
void generatePlatforms(MyGame gameRef) {
|
||||||
while (!generatePlatform(gameRef, 2)) {
|
while (!generatePlatform(gameRef, 2)) {
|
||||||
timeSinceLastTopHole++;
|
timeSinceLastTopHole++;
|
||||||
@ -118,6 +125,7 @@ class PlatformHolder extends Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a platform object.
|
||||||
bool generatePlatform(MyGame gameRef, int level, {double xPosition = 0}) {
|
bool generatePlatform(MyGame gameRef, int level, {double xPosition = 0}) {
|
||||||
double xCoordinate = xPosition;
|
double xCoordinate = xPosition;
|
||||||
if (objects[level].isNotEmpty && xPosition == 0) {
|
if (objects[level].isNotEmpty && xPosition == 0) {
|
||||||
@ -143,17 +151,7 @@ class PlatformHolder extends Holder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double getFlushX() {
|
// Choose a random platform that is off screen from the player.
|
||||||
MovingObject platform =
|
|
||||||
objects[2].firstWhere((element) => element.sprite.x > 0, orElse: () {
|
|
||||||
return objects[5].firstWhere((element) => element.sprite.x > 0,
|
|
||||||
orElse: () {
|
|
||||||
return objects[8].firstWhere((element) => element.sprite.x > 0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return platform.sprite.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
Platform? getPlatformOffScreen(int level) {
|
Platform? getPlatformOffScreen(int level) {
|
||||||
for (int i = 0; i < objects[level].length; i++) {
|
for (int i = 0; i < objects[level].length; i++) {
|
||||||
Platform p = objects[level][i] as Platform;
|
Platform p = objects[level][i] as Platform;
|
||||||
|
@ -36,13 +36,13 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
// TODO Set NO_TOURNAMENT to false, and then set the SERVER and PORT for the
|
// TODO Set NO_TOURNAMENT to false, and then set the SERVER and PORT for the
|
||||||
// firo runner server instance.
|
// firo runner server instance.
|
||||||
const NO_TOURNAMENT = false;
|
const NO_TOURNAMENT = false;
|
||||||
|
|
||||||
const SERVER = "http://10.0.0.224";
|
const SERVER = "http://10.0.0.224";
|
||||||
const PORT = "50067";
|
const PORT = "50067";
|
||||||
|
|
||||||
const COLOR = Color(0xFFDDC0A3);
|
const FIREWORK_COLOR = Color(0xFFDDC0A3);
|
||||||
const int LOADING_TIME = 2000000;
|
const int LOADING_TIME = 2000000;
|
||||||
|
|
||||||
|
// Variables that determine the score cutoff when each new level starts.
|
||||||
const LEVEL2 = 25000000;
|
const LEVEL2 = 25000000;
|
||||||
const LEVEL3 = 50000000;
|
const LEVEL3 = 50000000;
|
||||||
const LEVEL4 = 75000000;
|
const LEVEL4 = 75000000;
|
||||||
@ -50,9 +50,11 @@ const LEVEL5 = 100000000;
|
|||||||
const LEVEL6 = 125000000;
|
const LEVEL6 = 125000000;
|
||||||
const LEVEL7 = 150000000;
|
const LEVEL7 = 150000000;
|
||||||
|
|
||||||
|
// Variables that determine when to use the new robot animations.
|
||||||
const COINS_ROBOT_UPGRADE1 = 50;
|
const COINS_ROBOT_UPGRADE1 = 50;
|
||||||
const COINS_ROBOT_UPGRADE2 = 100;
|
const COINS_ROBOT_UPGRADE2 = 100;
|
||||||
|
|
||||||
|
// Draw priority for objects, not meant to be changed.
|
||||||
const OVERLAY_PRIORITY = 110;
|
const OVERLAY_PRIORITY = 110;
|
||||||
const RUNNER_PRIORITY = 100;
|
const RUNNER_PRIORITY = 100;
|
||||||
const BUG_PRIORITY = 75;
|
const BUG_PRIORITY = 75;
|
||||||
@ -64,15 +66,18 @@ const WIRE_PRIORITY = 25;
|
|||||||
const FIREWORK_PRIORITY = 15;
|
const FIREWORK_PRIORITY = 15;
|
||||||
const WINDOW_PRIORITY = 10;
|
const WINDOW_PRIORITY = 10;
|
||||||
|
|
||||||
// const overlayText = TextStyle(
|
// Preloading images for the overlays.
|
||||||
// fontSize: 30,
|
|
||||||
// color: Colors.white,
|
|
||||||
// );
|
|
||||||
|
|
||||||
const AssetImage mainMenuImage = AssetImage('assets/images/mm3.gif');
|
const AssetImage mainMenuImage = AssetImage('assets/images/mm3.gif');
|
||||||
const AssetImage lossImage = AssetImage('assets/images/overlay100.png');
|
const AssetImage lossImage = AssetImage('assets/images/overlay100.png');
|
||||||
const AssetImage buttonImage = AssetImage('assets/images/button-new.png');
|
const AssetImage buttonImage = AssetImage('assets/images/button-new.png');
|
||||||
|
|
||||||
|
// Colors of the overlay Themes.
|
||||||
|
const Color textColor = Colors.cyan;
|
||||||
|
const Color cardColor = Color(0xff262b3f);
|
||||||
|
const Color borderColor = Color(0xdfd675e1);
|
||||||
|
const Color titleColor = Color(0xff68d9cc);
|
||||||
|
const Color inactiveColor = Colors.grey;
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Flame.device.fullScreen();
|
await Flame.device.fullScreen();
|
||||||
@ -116,6 +121,7 @@ void main() async {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Grab the nearest platform.
|
||||||
int getNearestPlatform(int level) {
|
int getNearestPlatform(int level) {
|
||||||
return level <= 0
|
return level <= 0
|
||||||
? 0
|
? 0
|
||||||
@ -129,11 +135,11 @@ int getNearestPlatform(int level) {
|
|||||||
class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
||||||
TextPaint fireworksPaint = TextPaint(
|
TextPaint fireworksPaint = TextPaint(
|
||||||
config: const TextPaintConfig(
|
config: const TextPaintConfig(
|
||||||
fontSize: 48.0, fontFamily: 'Codystar', color: COLOR),
|
fontSize: 48.0, fontFamily: 'Codystar', color: FIREWORK_COLOR),
|
||||||
);
|
);
|
||||||
|
|
||||||
TextPaint scoresPaint = TextPaint(
|
TextPaint scoresPaint = TextPaint(
|
||||||
config: const TextPaintConfig(fontSize: 16.0, color: COLOR),
|
config: const TextPaintConfig(fontSize: 16.0, color: FIREWORK_COLOR),
|
||||||
);
|
);
|
||||||
|
|
||||||
String leaderboard = "";
|
String leaderboard = "";
|
||||||
@ -168,8 +174,10 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
viewport.resize(Vector2(1920, 1080));
|
viewport.resize(Vector2(1920, 1080));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the game and all of its assets, may take a couple of seconds.
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
|
// If playing in tournament mode, load all information from server.
|
||||||
if (!NO_TOURNAMENT) {
|
if (!NO_TOURNAMENT) {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
username = prefs.getString('username') ?? "";
|
username = prefs.getString('username') ?? "";
|
||||||
@ -184,6 +192,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
}
|
}
|
||||||
FlameAudio.bgm.initialize();
|
FlameAudio.bgm.initialize();
|
||||||
|
|
||||||
|
// preload all audio assets.
|
||||||
await FlameAudio.audioCache.loadAll([
|
await FlameAudio.audioCache.loadAll([
|
||||||
'sfx/coin_catch.mp3',
|
'sfx/coin_catch.mp3',
|
||||||
'sfx/glitch_death.mp3',
|
'sfx/glitch_death.mp3',
|
||||||
@ -202,6 +211,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
'Infinite_Spankage_M.mp3',
|
'Infinite_Spankage_M.mp3',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Load each object.
|
||||||
circuitBackground = CircuitBackground(this);
|
circuitBackground = CircuitBackground(this);
|
||||||
await circuitBackground.load();
|
await circuitBackground.load();
|
||||||
platformHolder = PlatformHolder();
|
platformHolder = PlatformHolder();
|
||||||
@ -225,6 +235,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
runner = Runner();
|
runner = Runner();
|
||||||
await runner.load();
|
await runner.load();
|
||||||
|
|
||||||
|
// Set up game UI
|
||||||
loaded = true;
|
loaded = true;
|
||||||
_distance = TextComponent("Time: 0",
|
_distance = TextComponent("Time: 0",
|
||||||
position: Vector2(size.x - 100, 10), textRenderer: scoresPaint)
|
position: Vector2(size.x - 100, 10), textRenderer: scoresPaint)
|
||||||
@ -234,15 +245,28 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
position: Vector2(size.x - 20, 10), textRenderer: scoresPaint)
|
position: Vector2(size.x - 20, 10), textRenderer: scoresPaint)
|
||||||
..anchor = Anchor.topRight;
|
..anchor = Anchor.topRight;
|
||||||
_coins.changePriorityWithoutResorting(OVERLAY_PRIORITY);
|
_coins.changePriorityWithoutResorting(OVERLAY_PRIORITY);
|
||||||
|
|
||||||
|
// add all overlays first since the first time they are added there is a
|
||||||
|
// delay, so calling it earlier makes a smoother experience.
|
||||||
|
overlays.add("leaderboard");
|
||||||
|
overlays.remove('leaderboard');
|
||||||
|
overlays.add("deposit");
|
||||||
|
overlays.remove('deposit');
|
||||||
|
overlays.add("signin");
|
||||||
|
overlays.remove('signin');
|
||||||
overlays.add("gameOver");
|
overlays.add("gameOver");
|
||||||
overlays.remove('gameOver');
|
overlays.remove('gameOver');
|
||||||
overlays.add("mainMenu");
|
overlays.add("mainMenu");
|
||||||
overlays.add('loading');
|
overlays.add('loading');
|
||||||
|
|
||||||
|
// set up the game and pause it.
|
||||||
setUp();
|
setUp();
|
||||||
gameState.setPaused();
|
gameState.setPaused();
|
||||||
startLoading = DateTime.now().microsecondsSinceEpoch;
|
startLoading = DateTime.now().microsecondsSinceEpoch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choose which music to play. Useful since web browser does not let you play
|
||||||
|
// music until the user interacts with the website.
|
||||||
void playMusic() {
|
void playMusic() {
|
||||||
if (overlays.isActive('mainMenu')) {
|
if (overlays.isActive('mainMenu')) {
|
||||||
FlameAudio.bgm.play('Infinite_Menu.mp3');
|
FlameAudio.bgm.play('Infinite_Menu.mp3');
|
||||||
@ -252,6 +276,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
playingMusic = true;
|
playingMusic = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill the screen with platforms and all of the obstacles.
|
||||||
void fillScreen() {
|
void fillScreen() {
|
||||||
if (shouldReset) {
|
if (shouldReset) {
|
||||||
return;
|
return;
|
||||||
@ -296,6 +321,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if an obstacle is being placed too near another obstacle,
|
||||||
|
// to ensure fairness for the player.
|
||||||
bool isTooNearOtherObstacles(Rect rect) {
|
bool isTooNearOtherObstacles(Rect rect) {
|
||||||
Rect obstacleBounds = Rect.fromLTRB(
|
Rect obstacleBounds = Rect.fromLTRB(
|
||||||
3 * rect.left - 2 * (rect.left + blockSize) - 1,
|
3 * rect.left - 2 * (rect.left + blockSize) - 1,
|
||||||
@ -347,6 +374,8 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
|
|
||||||
bool shouldReset = false;
|
bool shouldReset = false;
|
||||||
|
|
||||||
|
// Connect to the server in online mode to get information and to participate
|
||||||
|
// in the weekly tournament.
|
||||||
Future<String> connectServer(String command, String arguments) async {
|
Future<String> connectServer(String command, String arguments) async {
|
||||||
try {
|
try {
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
@ -372,6 +401,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put the loss screen up.
|
||||||
Future<void> displayLoss() async {
|
Future<void> displayLoss() async {
|
||||||
if (!(runner.sprite.animation?.done() ?? false) &&
|
if (!(runner.sprite.animation?.done() ?? false) &&
|
||||||
runner.sprite.animation!.loop == false &&
|
runner.sprite.animation!.loop == false &&
|
||||||
@ -382,6 +412,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
overlays.add('gameOver');
|
overlays.add('gameOver');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put the main menu screen up.
|
||||||
void mainMenu() {
|
void mainMenu() {
|
||||||
overlays.remove('gameOver');
|
overlays.remove('gameOver');
|
||||||
overlays.add('mainMenu');
|
overlays.add('mainMenu');
|
||||||
@ -389,6 +420,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
FlameAudio.bgm.play('Infinite_Menu.mp3');
|
FlameAudio.bgm.play('Infinite_Menu.mp3');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset the game.
|
||||||
void reset() {
|
void reset() {
|
||||||
runner.sprite.animation!.reset();
|
runner.sprite.animation!.reset();
|
||||||
overlays.remove('gameOver');
|
overlays.remove('gameOver');
|
||||||
@ -398,8 +430,10 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
setUp();
|
setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process after a death.
|
||||||
Future<void> die() async {
|
Future<void> die() async {
|
||||||
gameState.setPaused();
|
gameState.setPaused();
|
||||||
|
// if in a tournament mode update information.
|
||||||
if (!NO_TOURNAMENT) {
|
if (!NO_TOURNAMENT) {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
if (username != "" && competitive) {
|
if (username != "" && competitive) {
|
||||||
@ -418,6 +452,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
shouldReset = true;
|
shouldReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set up the game for another run.
|
||||||
void setUp() {
|
void setUp() {
|
||||||
add(runner);
|
add(runner);
|
||||||
fireworks.setUp();
|
fireworks.setUp();
|
||||||
@ -479,7 +514,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
debrisHolder.update(dt);
|
debrisHolder.update(dt);
|
||||||
wallHolder.update(dt);
|
wallHolder.update(dt);
|
||||||
|
|
||||||
_distance.text = "Time: ${gameState.getPlayerDistance()}";
|
_distance.text = "Time: ${gameState.getPlayerTime()}";
|
||||||
_coins.text = " ${gameState.numCoins}";
|
_coins.text = " ${gameState.numCoins}";
|
||||||
if (shouldReset &&
|
if (shouldReset &&
|
||||||
!overlays.isActive('gameOver') &&
|
!overlays.isActive('gameOver') &&
|
||||||
|
@ -24,6 +24,7 @@ enum OverlayState {
|
|||||||
seventh,
|
seventh,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Class for the moving background.
|
||||||
class CircuitBackground extends MovingObject {
|
class CircuitBackground extends MovingObject {
|
||||||
late Image background;
|
late Image background;
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:firo_runner/main.dart';
|
import 'package:firo_runner/main.dart';
|
||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
|
|
||||||
|
// Class meant to be extended by any object that will move left on the screen.
|
||||||
|
// Ensures a relatively constant moving velocity, and takes care of sprite
|
||||||
|
// animations and positioning.
|
||||||
class MovingObject {
|
class MovingObject {
|
||||||
late SpriteAnimationGroupComponent sprite;
|
late SpriteAnimationGroupComponent sprite;
|
||||||
MyGame gameRef;
|
MyGame gameRef;
|
||||||
@ -26,6 +29,7 @@ class MovingObject {
|
|||||||
sprite.position = sprite.position - Vector2(velocity * dt, 0);
|
sprite.position = sprite.position - Vector2(velocity * dt, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the rightmost pixel position of this sprite.
|
||||||
double getRightEnd() {
|
double getRightEnd() {
|
||||||
return sprite.position.x + sprite.width;
|
return sprite.position.x + sprite.width;
|
||||||
}
|
}
|
||||||
@ -34,6 +38,7 @@ class MovingObject {
|
|||||||
sprite.remove();
|
sprite.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See where this object intersects another object if at all.
|
||||||
String intersect(Rect other) {
|
String intersect(Rect other) {
|
||||||
final collision = sprite.toRect().intersect(other);
|
final collision = sprite.toRect().intersect(other);
|
||||||
if (!collision.isEmpty) {
|
if (!collision.isEmpty) {
|
||||||
@ -56,6 +61,7 @@ class MovingObject {
|
|||||||
return "none";
|
return "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resize the object for chaning screen sizes.
|
||||||
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
void resize(Vector2 newSize, double xRatio, double yRatio) {
|
||||||
sprite.x *= xRatio;
|
sprite.x *= xRatio;
|
||||||
sprite.y *= yRatio;
|
sprite.y *= yRatio;
|
||||||
|
@ -88,8 +88,8 @@ class Platform extends MovingObject {
|
|||||||
left = platformLevel.elementAt(index - 1).sprite.position;
|
left = platformLevel.elementAt(index - 1).sprite.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasLeft = (left.x - sprite.position.x).abs() < 1.9 * sprite.size.x;
|
bool hasLeft = (left.x - sprite.position.x).abs() < 2.5 * sprite.size.x;
|
||||||
bool hasRight = (sprite.position.x - right.x).abs() < 1.9 * sprite.size.x;
|
bool hasRight = (sprite.position.x - right.x).abs() < 2.5 * sprite.size.x;
|
||||||
|
|
||||||
// If the platform cannot be seen by the player.
|
// If the platform cannot be seen by the player.
|
||||||
if (!((sprite.x >= 0 && sprite.x <= gameRef.size.x) ||
|
if (!((sprite.x >= 0 && sprite.x <= gameRef.size.x) ||
|
||||||
|
@ -29,6 +29,8 @@ class Wall extends MovingObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override the update method so that this object can also move vertically
|
||||||
|
// as an obstacle.
|
||||||
@override
|
@override
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
super.update(dt);
|
super.update(dt);
|
||||||
|
@ -25,6 +25,8 @@ class Wire extends MovingObject {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override the intersect method so that the hitbox is smaller for the wires,
|
||||||
|
// this will be more fair to the player.
|
||||||
@override
|
@override
|
||||||
String intersect(Rect other) {
|
String intersect(Rect other) {
|
||||||
Rect currentRect = sprite.toRect();
|
Rect currentRect = sprite.toRect();
|
||||||
|
@ -9,10 +9,6 @@ class DepositOverlay extends StatelessWidget {
|
|||||||
required this.game,
|
required this.game,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final Color textColor = Colors.cyan;
|
|
||||||
final Color cardColor = const Color(0xff262b3f);
|
|
||||||
final Color titleColor = const Color(0xff68d9cc);
|
|
||||||
|
|
||||||
final MyGame game;
|
final MyGame game;
|
||||||
|
|
||||||
List<Widget> getDepositAddress(double width) {
|
List<Widget> getDepositAddress(double width) {
|
||||||
@ -29,7 +25,7 @@ class DepositOverlay extends StatelessWidget {
|
|||||||
child: Card(
|
child: Card(
|
||||||
color: cardColor,
|
color: cardColor,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
side: BorderSide(color: titleColor, width: 3),
|
side: const BorderSide(color: titleColor, width: 3),
|
||||||
borderRadius: BorderRadius.circular(10.0)),
|
borderRadius: BorderRadius.circular(10.0)),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(width * 0.01),
|
padding: EdgeInsets.all(width * 0.01),
|
||||||
|
@ -8,13 +8,6 @@ class LeaderBoardOverlay extends StatelessWidget {
|
|||||||
required this.game,
|
required this.game,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final Color textColor = Colors.cyan;
|
|
||||||
final Color cardColor = const Color(0xff262b3f);
|
|
||||||
final Color borderColor = const Color(0xdfd675e1);
|
|
||||||
final Color titleColor = const Color(0xff68d9cc);
|
|
||||||
|
|
||||||
// final Color textColor = Colors.black;
|
|
||||||
|
|
||||||
final MyGame game;
|
final MyGame game;
|
||||||
|
|
||||||
List<Card> getLeaderboard(double width) {
|
List<Card> getLeaderboard(double width) {
|
||||||
|
@ -34,7 +34,7 @@ class LoseMenuOverlay extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
'Score: ${game.gameState.getPlayerScore()}',
|
'Score: ${game.gameState.getPlayerScore()}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
color: textColor,
|
||||||
fontSize: width * 0.05,
|
fontSize: width * 0.05,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -45,8 +45,6 @@ class LoseMenuOverlay extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -58,7 +56,7 @@ class LoseMenuOverlay extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
" MAIN MENU ",
|
" MAIN MENU ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.cyan,
|
color: textColor,
|
||||||
fontSize: width * 0.03,
|
fontSize: width * 0.03,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -77,8 +75,6 @@ class LoseMenuOverlay extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -91,8 +87,8 @@ class LoseMenuOverlay extends StatelessWidget {
|
|||||||
" REPLAY${game.competitive ? " ${game.tries}" : ""} ",
|
" REPLAY${game.competitive ? " ${game.tries}" : ""} ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: game.competitive && game.tries <= 0
|
color: game.competitive && game.tries <= 0
|
||||||
? Colors.grey
|
? inactiveColor
|
||||||
: Colors.cyan,
|
: textColor,
|
||||||
fontSize: width * 0.03,
|
fontSize: width * 0.03,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -2,9 +2,7 @@ import 'package:flame_audio/flame_audio.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:audioplayers/src/api/player_mode.dart';
|
import 'package:audioplayers/src/api/player_mode.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
||||||
|
|
||||||
class MainMenuOverlay extends StatelessWidget {
|
class MainMenuOverlay extends StatelessWidget {
|
||||||
const MainMenuOverlay({
|
const MainMenuOverlay({
|
||||||
@ -51,8 +49,6 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -64,7 +60,7 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
" START ",
|
" START ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.cyan,
|
color: textColor,
|
||||||
fontSize: width * 0.025,
|
fontSize: width * 0.025,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -98,8 +94,6 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -107,13 +101,13 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
image: buttonImage, fit: BoxFit.fill),
|
image: buttonImage, fit: BoxFit.fill),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
" DEPOSIT ",
|
" DEPOSIT ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: game.username == ""
|
color: game.username == ""
|
||||||
? Colors.grey
|
? inactiveColor
|
||||||
: Colors.cyan,
|
: textColor,
|
||||||
fontSize: width * 0.025,
|
fontSize: width * 0.025,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -132,8 +126,6 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -147,8 +139,8 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color:
|
color:
|
||||||
game.username == "" || game.tries == 0
|
game.username == "" || game.tries == 0
|
||||||
? Colors.grey
|
? inactiveColor
|
||||||
: Colors.cyan,
|
: textColor,
|
||||||
fontSize: width * 0.025,
|
fontSize: width * 0.025,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -187,8 +179,6 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -196,11 +186,11 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
image: buttonImage, fit: BoxFit.fill),
|
image: buttonImage, fit: BoxFit.fill),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
" ${game.username == "" ? "SIGN IN" : game.username} ",
|
" ${game.username == "" ? "SIGN IN" : game.username} ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.cyan,
|
color: textColor,
|
||||||
fontSize: width * 0.025,
|
fontSize: width * 0.025,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -214,8 +204,6 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
||||||
textColor: Colors.white,
|
|
||||||
splashColor: Colors.greenAccent,
|
|
||||||
elevation: 8.0,
|
elevation: 8.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -223,11 +211,11 @@ class MainMenuOverlay extends StatelessWidget {
|
|||||||
image: buttonImage, fit: BoxFit.fill),
|
image: buttonImage, fit: BoxFit.fill),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
" LEADER BOARD ",
|
" LEADER BOARD ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.cyan,
|
color: textColor,
|
||||||
fontSize: width * 0.025,
|
fontSize: width * 0.025,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -12,9 +12,6 @@ class SignInOverlay extends StatefulWidget {
|
|||||||
required this.game,
|
required this.game,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final Color cardColor = Colors.white;
|
|
||||||
final Color textColor = Colors.black;
|
|
||||||
|
|
||||||
final MyGame game;
|
final MyGame game;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -75,9 +72,6 @@ class _MyStatefulWidgetState extends State<SignInOverlay> {
|
|||||||
hintText: 'Enter your receiving Firo address.',
|
hintText: 'Enter your receiving Firo address.',
|
||||||
),
|
),
|
||||||
validator: (String? value) {
|
validator: (String? value) {
|
||||||
// if (value == null || value.isEmpty) {
|
|
||||||
// return 'Please enter your receiving Firo address.';
|
|
||||||
// } else
|
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
print("logging in instead of signing up.");
|
print("logging in instead of signing up.");
|
||||||
return null;
|
return null;
|
||||||
|
@ -78,10 +78,12 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
size: sprite.size * 1.6);
|
size: sprite.size * 1.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update which level the runner should be at.
|
||||||
void updateLevel() {
|
void updateLevel() {
|
||||||
level = (sprite.position.y / gameRef.blockSize).round();
|
level = (sprite.position.y / gameRef.blockSize).round();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process the event that the runner is in.
|
||||||
void event(String event) {
|
void event(String event) {
|
||||||
if (gameRef.gameState.isPaused) {
|
if (gameRef.gameState.isPaused) {
|
||||||
return;
|
return;
|
||||||
@ -194,7 +196,6 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
curve: Curves.ease,
|
curve: Curves.ease,
|
||||||
onComplete: () {
|
onComplete: () {
|
||||||
updateLevel();
|
updateLevel();
|
||||||
// boost.stop();
|
|
||||||
if (onTopOfPlatform()) {
|
if (onTopOfPlatform()) {
|
||||||
this.event("run");
|
this.event("run");
|
||||||
} else {
|
} else {
|
||||||
@ -227,7 +228,6 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
if (boost != null) {
|
if (boost != null) {
|
||||||
boost.then((value) => value.stop());
|
boost.then((value) => value.stop());
|
||||||
}
|
}
|
||||||
// boost.stop();
|
|
||||||
this.event("run");
|
this.event("run");
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
@ -281,6 +281,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the falling effect for falling and deaths.
|
||||||
MoveEffect getFallingEffect() {
|
MoveEffect getFallingEffect() {
|
||||||
for (int i = level; i < 9; i++) {
|
for (int i = level; i < 9; i++) {
|
||||||
if (i % 3 != 2) {
|
if (i % 3 != 2) {
|
||||||
@ -335,6 +336,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Platform agnostic control input to determine the runners actions.
|
||||||
void control(String input) {
|
void control(String input) {
|
||||||
if (gameRef.gameState.isPaused) {
|
if (gameRef.gameState.isPaused) {
|
||||||
return;
|
return;
|
||||||
@ -407,6 +409,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
sprite.update(dt);
|
sprite.update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether or not the runner is on top of a platform.
|
||||||
bool onTopOfPlatform() {
|
bool onTopOfPlatform() {
|
||||||
Rect runnerRect = sprite.toRect();
|
Rect runnerRect = sprite.toRect();
|
||||||
bool onTopOfPlatform = false;
|
bool onTopOfPlatform = false;
|
||||||
@ -425,6 +428,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
return onTopOfPlatform;
|
return onTopOfPlatform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the runner is directly below a platform.
|
||||||
bool belowPlatform() {
|
bool belowPlatform() {
|
||||||
Rect runnerRect = Rect.fromLTRB(
|
Rect runnerRect = Rect.fromLTRB(
|
||||||
sprite.toRect().left,
|
sprite.toRect().left,
|
||||||
@ -447,6 +451,8 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
return belowPlatform;
|
return belowPlatform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check to see if the runner is intersecting any of the game objects, and
|
||||||
|
// trigger the appropriate events.
|
||||||
void intersecting() {
|
void intersecting() {
|
||||||
if (gameRef.gameState.isPaused) {
|
if (gameRef.gameState.isPaused) {
|
||||||
return;
|
return;
|
||||||
@ -556,6 +562,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load all of the runners animations.
|
||||||
Future load() async {
|
Future load() async {
|
||||||
List<Image> satellites = [];
|
List<Image> satellites = [];
|
||||||
for (int i = 1; i <= 38; i++) {
|
for (int i = 1; i <= 38; i++) {
|
||||||
@ -662,7 +669,6 @@ class Runner extends Component with HasGameRef<MyGame> {
|
|||||||
void clearEffects({bool keepSounds = false}) {
|
void clearEffects({bool keepSounds = false}) {
|
||||||
sprite.clearEffects();
|
sprite.clearEffects();
|
||||||
if (!keepSounds && boost != null) {
|
if (!keepSounds && boost != null) {
|
||||||
// boost.stop();
|
|
||||||
boost.then((value) => value.stop());
|
boost.then((value) => value.stop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user