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