staging #20

Merged
marco merged 52 commits from staging into master 2021-10-09 18:48:59 +00:00
10 changed files with 1811 additions and 1768 deletions
Showing only changes of commit c5f22f7f21 - Show all commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

View File

@ -1,396 +1,396 @@
import 'package:firo_runner/moving_object.dart'; import 'package:firo_runner/moving_object.dart';
import 'package:firo_runner/main.dart'; import 'package:firo_runner/main.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/flame.dart'; import 'package:flame/flame.dart';
import 'package:flame/extensions.dart'; import 'package:flame/extensions.dart';
enum WindowState { enum WindowState {
first, first,
second, second,
third, third,
fourth, fourth,
fifth, fifth,
sixth, sixth,
seventh, seventh,
} }
enum OverlayState { enum OverlayState {
first, first,
second, second,
third, third,
fourth, fourth,
fifth, fifth,
sixth, sixth,
seventh, seventh,
} }
class CircuitBackground extends MovingObject { class CircuitBackground extends MovingObject {
late Image background; late Image background;
late Image overlay0; late Image overlay0;
late Image overlay1; late Image overlay1;
late Image overlay2; late Image overlay2;
late Image overlay3; late Image overlay3;
late Image overlay4; late Image overlay4;
late Image overlay5; late Image overlay5;
late Image overlay6; late Image overlay6;
late Image windows0; late Image windows0;
late Image windows1; late Image windows1;
late Image windows2; late Image windows2;
late Image windows3; late Image windows3;
late Image windows4; late Image windows4;
late Image windows5; late Image windows5;
late Image windows6; late Image windows6;
late Sprite background1; late Sprite background1;
late Sprite background2; late Sprite background2;
late SpriteAnimationGroupComponent windowA; late SpriteAnimationGroupComponent windowA;
late SpriteAnimationGroupComponent windowB; late SpriteAnimationGroupComponent windowB;
late SpriteAnimationGroupComponent overlayA; late SpriteAnimationGroupComponent overlayA;
late SpriteAnimationGroupComponent overlayB; late SpriteAnimationGroupComponent overlayB;
Vector2 background1Size = Vector2(0, 0); Vector2 background1Size = Vector2(0, 0);
Vector2 background2Size = Vector2(0, 0); Vector2 background2Size = Vector2(0, 0);
Vector2 background1Position = Vector2(0, 0); Vector2 background1Position = Vector2(0, 0);
Vector2 background2Position = Vector2(0, 0); Vector2 background2Position = Vector2(0, 0);
CircuitBackground(MyGame gameRef) : super(gameRef); CircuitBackground(MyGame gameRef) : super(gameRef);
Future load() async { Future load() async {
background = await Flame.images.load("bg.png"); background = await Flame.images.load("bg.png");
background1 = Sprite(background); background1 = Sprite(background);
background2 = Sprite(background); background2 = Sprite(background);
overlay0 = await Flame.images.load("overlay100.png"); overlay0 = await Flame.images.load("overlay100.png");
overlay1 = await Flame.images.load("overlay90.png"); overlay1 = await Flame.images.load("overlay90.png");
overlay2 = await Flame.images.load("overlay80.png"); overlay2 = await Flame.images.load("overlay80.png");
overlay3 = await Flame.images.load("overlay70.png"); overlay3 = await Flame.images.load("overlay70.png");
overlay4 = await Flame.images.load("overlay60.png"); overlay4 = await Flame.images.load("overlay60.png");
overlay5 = await Flame.images.load("overlay50.png"); overlay5 = await Flame.images.load("overlay50.png");
overlay6 = await Flame.images.load("overlay40.png"); overlay6 = await Flame.images.load("overlay40.png");
SpriteAnimation firstOverlay = SpriteAnimation.fromFrameData( SpriteAnimation firstOverlay = SpriteAnimation.fromFrameData(
overlay0, overlay0,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation secondOverlay = SpriteAnimation.fromFrameData( SpriteAnimation secondOverlay = SpriteAnimation.fromFrameData(
overlay1, overlay1,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation thirdOverlay = SpriteAnimation.fromFrameData( SpriteAnimation thirdOverlay = SpriteAnimation.fromFrameData(
overlay2, overlay2,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation fourthOverlay = SpriteAnimation.fromFrameData( SpriteAnimation fourthOverlay = SpriteAnimation.fromFrameData(
overlay3, overlay3,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation fifthOverlay = SpriteAnimation.fromFrameData( SpriteAnimation fifthOverlay = SpriteAnimation.fromFrameData(
overlay4, overlay4,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation sixthOverlay = SpriteAnimation.fromFrameData( SpriteAnimation sixthOverlay = SpriteAnimation.fromFrameData(
overlay5, overlay5,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation seventhOverlay = SpriteAnimation.fromFrameData( SpriteAnimation seventhOverlay = SpriteAnimation.fromFrameData(
overlay6, overlay6,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
overlayA = SpriteAnimationGroupComponent( overlayA = SpriteAnimationGroupComponent(
animations: { animations: {
OverlayState.first: firstOverlay, OverlayState.first: firstOverlay,
OverlayState.second: secondOverlay, OverlayState.second: secondOverlay,
OverlayState.third: thirdOverlay, OverlayState.third: thirdOverlay,
OverlayState.fourth: fourthOverlay, OverlayState.fourth: fourthOverlay,
OverlayState.fifth: fifthOverlay, OverlayState.fifth: fifthOverlay,
OverlayState.sixth: sixthOverlay, OverlayState.sixth: sixthOverlay,
OverlayState.seventh: seventhOverlay, OverlayState.seventh: seventhOverlay,
}, },
current: OverlayState.first, current: OverlayState.first,
); );
overlayB = SpriteAnimationGroupComponent( overlayB = SpriteAnimationGroupComponent(
animations: { animations: {
OverlayState.first: firstOverlay, OverlayState.first: firstOverlay,
OverlayState.second: secondOverlay, OverlayState.second: secondOverlay,
OverlayState.third: thirdOverlay, OverlayState.third: thirdOverlay,
OverlayState.fourth: fourthOverlay, OverlayState.fourth: fourthOverlay,
OverlayState.fifth: fifthOverlay, OverlayState.fifth: fifthOverlay,
OverlayState.sixth: sixthOverlay, OverlayState.sixth: sixthOverlay,
OverlayState.seventh: seventhOverlay, OverlayState.seventh: seventhOverlay,
}, },
current: OverlayState.first, current: OverlayState.first,
); );
overlayA.changePriorityWithoutResorting(WINDOW_PRIORITY - 1); overlayA.changePriorityWithoutResorting(WINDOW_PRIORITY - 1);
overlayA.changePriorityWithoutResorting(WINDOW_PRIORITY - 1); overlayA.changePriorityWithoutResorting(WINDOW_PRIORITY - 1);
windows0 = await Flame.images.load("windows-0.png"); windows0 = await Flame.images.load("windows-0.png");
windows1 = await Flame.images.load("windows-1.png"); windows1 = await Flame.images.load("windows-1.png");
windows2 = await Flame.images.load("windows-2.png"); windows2 = await Flame.images.load("windows-2.png");
windows3 = await Flame.images.load("windows-3.png"); windows3 = await Flame.images.load("windows-3.png");
windows4 = await Flame.images.load("windows-4.png"); windows4 = await Flame.images.load("windows-4.png");
windows5 = await Flame.images.load("windows-5.png"); windows5 = await Flame.images.load("windows-5.png");
windows6 = await Flame.images.load("windows-6.png"); windows6 = await Flame.images.load("windows-6.png");
SpriteAnimation firstWindow = SpriteAnimation.fromFrameData( SpriteAnimation firstWindow = SpriteAnimation.fromFrameData(
windows0, windows0,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation secondWindow = SpriteAnimation.fromFrameData( SpriteAnimation secondWindow = SpriteAnimation.fromFrameData(
windows1, windows1,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation thirdWindow = SpriteAnimation.fromFrameData( SpriteAnimation thirdWindow = SpriteAnimation.fromFrameData(
windows2, windows2,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation fourthWindow = SpriteAnimation.fromFrameData( SpriteAnimation fourthWindow = SpriteAnimation.fromFrameData(
windows3, windows3,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation fifthWindow = SpriteAnimation.fromFrameData( SpriteAnimation fifthWindow = SpriteAnimation.fromFrameData(
windows4, windows4,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation sixthWindow = SpriteAnimation.fromFrameData( SpriteAnimation sixthWindow = SpriteAnimation.fromFrameData(
windows5, windows5,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
SpriteAnimation seventhWindow = SpriteAnimation.fromFrameData( SpriteAnimation seventhWindow = SpriteAnimation.fromFrameData(
windows6, windows6,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
stepTime: 1, stepTime: 1,
textureSize: Vector2(2048, 683), textureSize: Vector2(2048, 683),
loop: false)); loop: false));
windowA = SpriteAnimationGroupComponent( windowA = SpriteAnimationGroupComponent(
animations: { animations: {
WindowState.first: firstWindow, WindowState.first: firstWindow,
WindowState.second: secondWindow, WindowState.second: secondWindow,
WindowState.third: thirdWindow, WindowState.third: thirdWindow,
WindowState.fourth: fourthWindow, WindowState.fourth: fourthWindow,
WindowState.fifth: fifthWindow, WindowState.fifth: fifthWindow,
WindowState.sixth: sixthWindow, WindowState.sixth: sixthWindow,
WindowState.seventh: seventhWindow, WindowState.seventh: seventhWindow,
}, },
current: WindowState.first, current: WindowState.first,
); );
windowB = SpriteAnimationGroupComponent( windowB = SpriteAnimationGroupComponent(
animations: { animations: {
WindowState.first: firstWindow, WindowState.first: firstWindow,
WindowState.second: secondWindow, WindowState.second: secondWindow,
WindowState.third: thirdWindow, WindowState.third: thirdWindow,
WindowState.fourth: fourthWindow, WindowState.fourth: fourthWindow,
WindowState.fifth: fifthWindow, WindowState.fifth: fifthWindow,
WindowState.sixth: sixthWindow, WindowState.sixth: sixthWindow,
WindowState.seventh: seventhWindow, WindowState.seventh: seventhWindow,
}, },
current: WindowState.first, current: WindowState.first,
); );
windowA.changePriorityWithoutResorting(WINDOW_PRIORITY); windowA.changePriorityWithoutResorting(WINDOW_PRIORITY);
windowA.changePriorityWithoutResorting(WINDOW_PRIORITY); windowA.changePriorityWithoutResorting(WINDOW_PRIORITY);
setUp(); setUp();
} }
void setUp() { void setUp() {
windowA.current = WindowState.first; windowA.current = WindowState.first;
windowB.current = WindowState.first; windowB.current = WindowState.first;
overlayA.current = OverlayState.first; overlayA.current = OverlayState.first;
overlayB.current = OverlayState.first; overlayB.current = OverlayState.first;
background1Position = Vector2(0, 0); background1Position = Vector2(0, 0);
background1Size = Vector2( background1Size = Vector2(
gameRef.viewport.canvasSize.y * (background.width / background.height), gameRef.viewport.canvasSize.y * (background.width / background.height),
gameRef.viewport.canvasSize.y); gameRef.viewport.canvasSize.y);
windowA.position = background1Position; windowA.position = background1Position;
windowA.size = background1Size; windowA.size = background1Size;
overlayA.position = background1Position; overlayA.position = background1Position;
overlayA.size = background1Size; overlayA.size = background1Size;
background2Position = background2Position =
Vector2(background1Position.x + background1Size.x - 1, 0); Vector2(background1Position.x + background1Size.x - 1, 0);
background2Size = Vector2( background2Size = Vector2(
gameRef.viewport.canvasSize.y * (background.width / background.height), gameRef.viewport.canvasSize.y * (background.width / background.height),
gameRef.viewport.canvasSize.y); gameRef.viewport.canvasSize.y);
windowB.position = background2Position; windowB.position = background2Position;
windowB.size = background2Size; windowB.size = background2Size;
overlayB.position = background2Position; overlayB.position = background2Position;
overlayB.size = background2Size; overlayB.size = background2Size;
} }
@override @override
void update(double dt) { void update(double dt) {
switch (gameRef.gameState.getScoreLevel()) { switch (gameRef.gameState.getScoreLevel()) {
case 12: case 12:
windowA.current = WindowState.seventh; windowA.current = WindowState.seventh;
windowB.current = WindowState.seventh; windowB.current = WindowState.seventh;
break; break;
case 11: case 11:
overlayA.current = OverlayState.seventh; overlayA.current = OverlayState.seventh;
overlayB.current = OverlayState.seventh; overlayB.current = OverlayState.seventh;
break; break;
case 10: case 10:
windowA.current = WindowState.sixth; windowA.current = WindowState.sixth;
windowB.current = WindowState.sixth; windowB.current = WindowState.sixth;
break; break;
case 9: case 9:
overlayA.current = OverlayState.sixth; overlayA.current = OverlayState.sixth;
overlayB.current = OverlayState.sixth; overlayB.current = OverlayState.sixth;
break; break;
case 8: case 8:
windowA.current = WindowState.fifth; windowA.current = WindowState.fifth;
windowB.current = WindowState.fifth; windowB.current = WindowState.fifth;
break; break;
case 7: case 7:
overlayA.current = OverlayState.fifth; overlayA.current = OverlayState.fifth;
overlayB.current = OverlayState.fifth; overlayB.current = OverlayState.fifth;
break; break;
case 6: case 6:
windowA.current = WindowState.fourth; windowA.current = WindowState.fourth;
windowB.current = WindowState.fourth; windowB.current = WindowState.fourth;
break; break;
case 5: case 5:
overlayA.current = OverlayState.fourth; overlayA.current = OverlayState.fourth;
overlayB.current = OverlayState.fourth; overlayB.current = OverlayState.fourth;
break; break;
case 4: case 4:
windowA.current = WindowState.third; windowA.current = WindowState.third;
windowB.current = WindowState.third; windowB.current = WindowState.third;
break; break;
case 3: case 3:
overlayA.current = OverlayState.third; overlayA.current = OverlayState.third;
overlayB.current = OverlayState.third; overlayB.current = OverlayState.third;
break; break;
case 2: case 2:
windowA.current = WindowState.second; windowA.current = WindowState.second;
windowB.current = WindowState.second; windowB.current = WindowState.second;
break; break;
case 1: case 1:
overlayA.current = OverlayState.second; overlayA.current = OverlayState.second;
overlayB.current = OverlayState.second; overlayB.current = OverlayState.second;
break; break;
default: default:
windowA.current = WindowState.first; windowA.current = WindowState.first;
windowB.current = WindowState.first; windowB.current = WindowState.first;
overlayA.current = OverlayState.first; overlayA.current = OverlayState.first;
overlayB.current = OverlayState.first; overlayB.current = OverlayState.first;
break; break;
} }
windowA.update(dt); windowA.update(dt);
windowB.update(dt); windowB.update(dt);
overlayA.update(dt); overlayA.update(dt);
overlayB.update(dt); overlayB.update(dt);
if (background1Position.x + background1Size.x < 0) { if (background1Position.x + background1Size.x < 0) {
double newPosition = background2Position.x + background2Size.x; double newPosition = background2Position.x + background2Size.x;
background1Position = Vector2(newPosition - 1, 0); background1Position = Vector2(newPosition - 1, 0);
} else if (background2Position.x + background2Size.x < 0) { } else if (background2Position.x + background2Size.x < 0) {
double newPosition = background1Position.x + background1Size.x; double newPosition = background1Position.x + background1Size.x;
background2Position = Vector2(newPosition - 1, 0); background2Position = Vector2(newPosition - 1, 0);
} }
double velocity = gameRef.gameState.getVelocity() / 10.0; double velocity = gameRef.gameState.getVelocity() / 10.0;
background1Position = background1Position - Vector2(velocity * dt, 0); background1Position = background1Position - Vector2(velocity * dt, 0);
windowA.position = background1Position; windowA.position = background1Position;
overlayA.position = background1Position; overlayA.position = background1Position;
background2Position = background2Position - Vector2(velocity * dt, 0); background2Position = background2Position - Vector2(velocity * dt, 0);
windowB.position = background2Position; windowB.position = background2Position;
overlayB.position = background2Position; overlayB.position = background2Position;
} }
void render(Canvas canvas) { void render(Canvas canvas) {
background1.render(canvas, background1.render(canvas,
size: background1Size, position: background1Position); size: background1Size, position: background1Position);
canvas.save(); canvas.save();
overlayA.render(canvas); overlayA.render(canvas);
canvas.restore(); canvas.restore();
canvas.save(); canvas.save();
windowA.render(canvas); windowA.render(canvas);
canvas.restore(); canvas.restore();
background2.render(canvas, background2.render(canvas,
size: background2Size, position: background2Position); size: background2Size, position: background2Position);
canvas.save(); canvas.save();
overlayB.render(canvas); overlayB.render(canvas);
canvas.restore(); canvas.restore();
canvas.save(); canvas.save();
windowB.render(canvas); windowB.render(canvas);
canvas.restore(); canvas.restore();
} }
@override @override
void resize(Vector2 newSize, double xRatio, double yRatio) { void resize(Vector2 newSize, double xRatio, double yRatio) {
background1Size = background1Size =
Vector2(newSize.y * (background.width / background.height), newSize.y); Vector2(newSize.y * (background.width / background.height), newSize.y);
windowA.position = background1Position; windowA.position = background1Position;
windowA.size = background1Size; windowA.size = background1Size;
overlayA.position = background1Position; overlayA.position = background1Position;
overlayA.size = background1Size; overlayA.size = background1Size;
background2Position = background2Position =
Vector2(background1Position.x + background1Size.x - 1, 0); Vector2(background1Position.x + background1Size.x - 1, 0);
background2Size = background2Size =
Vector2(newSize.y * (background.width / background.height), newSize.y); Vector2(newSize.y * (background.width / background.height), newSize.y);
windowB.position = background2Position; windowB.position = background2Position;
windowB.size = background2Size; windowB.size = background2Size;
overlayB.position = background2Position; overlayB.position = background2Position;
overlayB.size = background2Size; overlayB.size = background2Size;
} }
} }

View File

@ -1,131 +1,131 @@
import 'dart:math'; import 'dart:math';
import 'package:firo_runner/main.dart'; import 'package:firo_runner/main.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/extensions.dart'; import 'package:flame/extensions.dart';
import 'package:flame/flame.dart'; import 'package:flame/flame.dart';
enum FireworkState { normal } enum FireworkState { normal }
class Firework extends Component { class Firework extends Component {
MyGame gameRef; MyGame gameRef;
late SpriteAnimationGroupComponent sprite1; late SpriteAnimationGroupComponent sprite1;
late SpriteAnimationGroupComponent sprite2; late SpriteAnimationGroupComponent sprite2;
Firework(this.gameRef); Firework(this.gameRef);
double timeSinceFirework = 0; double timeSinceFirework = 0;
late Random random; late Random random;
String message = ""; String message = "";
List<String> messages = [ List<String> messages = [
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
"Speed Up!", "Speed Up!",
]; ];
Future load() async { Future load() async {
random = Random(); random = Random();
Image firework = await Flame.images.load("fireworks-frames.png"); Image firework = await Flame.images.load("fireworks-frames.png");
SpriteAnimation normal = SpriteAnimation.fromFrameData( SpriteAnimation normal = SpriteAnimation.fromFrameData(
firework, firework,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 10, amount: 10,
stepTime: 0.25, stepTime: 0.25,
textureSize: Vector2(512, 512), textureSize: Vector2(512, 512),
loop: false, loop: false,
), ),
); );
sprite1 = SpriteAnimationGroupComponent( sprite1 = SpriteAnimationGroupComponent(
animations: { animations: {
FireworkState.normal: normal, FireworkState.normal: normal,
}, },
current: FireworkState.normal, current: FireworkState.normal,
); );
sprite1.changePriorityWithoutResorting(FIREWORK_PRIORITY); sprite1.changePriorityWithoutResorting(FIREWORK_PRIORITY);
sprite1.update(100); sprite1.update(100);
sprite1.size = sprite1.size =
Vector2(gameRef.viewport.canvasSize.y, gameRef.viewport.canvasSize.y); Vector2(gameRef.viewport.canvasSize.y, gameRef.viewport.canvasSize.y);
sprite1.position = Vector2(0, 0); sprite1.position = Vector2(0, 0);
sprite2 = SpriteAnimationGroupComponent( sprite2 = SpriteAnimationGroupComponent(
animations: { animations: {
FireworkState.normal: normal, FireworkState.normal: normal,
}, },
current: FireworkState.normal, current: FireworkState.normal,
); );
sprite2.changePriorityWithoutResorting(FIREWORK_PRIORITY); sprite2.changePriorityWithoutResorting(FIREWORK_PRIORITY);
sprite2.size = sprite2.size =
Vector2(gameRef.viewport.canvasSize.y, gameRef.viewport.canvasSize.y); Vector2(gameRef.viewport.canvasSize.y, gameRef.viewport.canvasSize.y);
sprite2.position = sprite2.position =
Vector2(gameRef.viewport.canvasSize.x - sprite2.size.x, 0); Vector2(gameRef.viewport.canvasSize.x - sprite2.size.x, 0);
sprite2.update(100); sprite2.update(100);
} }
void setUp() { void setUp() {
message = ""; message = "";
timeSinceFirework = 0; timeSinceFirework = 0;
gameRef.add(sprite1); gameRef.add(sprite1);
gameRef.add(sprite2); gameRef.add(sprite2);
} }
@override @override
void update(double dt) { void update(double dt) {
if (!(sprite1.animation?.done() ?? false)) { if (!(sprite1.animation?.done() ?? false)) {
timeSinceFirework = 0; timeSinceFirework = 0;
} else { } else {
timeSinceFirework += dt; timeSinceFirework += dt;
} }
sprite1.update(dt); sprite1.update(dt);
sprite2.update(dt); sprite2.update(dt);
} }
void renderText(Canvas canvas) { void renderText(Canvas canvas) {
sprite1.render(canvas); sprite1.render(canvas);
sprite1.render(canvas); sprite1.render(canvas);
if ((sprite1.animation?.done() ?? false) && if ((sprite1.animation?.done() ?? false) &&
timeSinceFirework < 1 && timeSinceFirework < 1 &&
message != "") { message != "") {
gameRef.fireworksPaint.render( gameRef.fireworksPaint.render(
canvas, canvas,
message, message,
Vector2( Vector2(
gameRef.size.x / 2 - gameRef.size.x / 2 -
gameRef.fireworksPaint.measureTextWidth(message) / 2, gameRef.fireworksPaint.measureTextWidth(message) / 2,
gameRef.size.y / 9 - gameRef.size.y / 9 -
gameRef.fireworksPaint.measureTextHeight(message) / 2), gameRef.fireworksPaint.measureTextHeight(message) / 2),
); );
} }
} }
void reset() { void reset() {
message = messages.elementAt(random.nextInt(messages.length)); message = messages.elementAt(random.nextInt(messages.length));
sprite1.animation!.reset(); sprite1.animation!.reset();
sprite2.animation!.reset(); sprite2.animation!.reset();
} }
void resize(Vector2 newSize, double xRatio, double yRatio) { void resize(Vector2 newSize, double xRatio, double yRatio) {
sprite1.x *= xRatio; sprite1.x *= xRatio;
sprite1.y *= yRatio; sprite1.y *= yRatio;
sprite1.width *= xRatio; sprite1.width *= xRatio;
sprite1.height *= yRatio; sprite1.height *= yRatio;
sprite2.x *= xRatio; sprite2.x *= xRatio;
sprite2.y *= yRatio; sprite2.y *= yRatio;
sprite2.width *= xRatio; sprite2.width *= xRatio;
sprite2.height *= yRatio; sprite2.height *= yRatio;
} }
} }

View File

@ -1,124 +1,124 @@
import 'package:firo_runner/main.dart'; import 'package:firo_runner/main.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
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 distance = 0;
late MyGame gameRef; late MyGame gameRef;
int previousLevel = 1; int previousLevel = 1;
@override @override
void update(double dt) { void update(double dt) {
super.update(dt); super.update(dt);
if (!isPaused) { if (!isPaused) {
distance = DateTime.now().microsecondsSinceEpoch - start; distance = DateTime.now().microsecondsSinceEpoch - start;
if (previousLevel != getLevel()) { if (previousLevel != getLevel()) {
previousLevel = getLevel(); previousLevel = getLevel();
gameRef.fireworks.reset(); gameRef.fireworks.reset();
} }
} }
} }
void addCoin() { void addCoin() {
numCoins++; numCoins++;
} }
void setUp(MyGame gameRef) { void setUp(MyGame gameRef) {
this.gameRef = gameRef; this.gameRef = gameRef;
numCoins = 0; numCoins = 0;
distance = 0; distance = 0;
previousLevel = 1; previousLevel = 1;
start = DateTime.now().microsecondsSinceEpoch; start = DateTime.now().microsecondsSinceEpoch;
isPaused = false; isPaused = false;
} }
void setPaused() { void setPaused() {
isPaused = true; isPaused = true;
} }
int getLevel() { int getLevel() {
if (distance > LEVEL7) { if (distance > LEVEL7) {
return 7; return 7;
} else if (distance > LEVEL6) { } else if (distance > LEVEL6) {
return 6; return 6;
} else if (distance > LEVEL5) { } else if (distance > LEVEL5) {
return 5; return 5;
} else if (distance > LEVEL4) { } else if (distance > LEVEL4) {
return 4; return 4;
} else if (distance > LEVEL3) { } else if (distance > LEVEL3) {
return 3; return 3;
} else if (distance > LEVEL2) { } else if (distance > LEVEL2) {
return 2; return 2;
} else { } else {
return 1; return 1;
} }
} }
int getScoreLevel() { int getScoreLevel() {
int score = getScore(); int score = getScore();
if (score > LEVEL7) { if (score > LEVEL7) {
return 12; return 12;
} else if (score > LEVEL6 + LEVEL6 / 2) { } else if (score > LEVEL6 + LEVEL6 / 2) {
return 11; return 11;
} else if (score > LEVEL6) { } else if (score > LEVEL6) {
return 10; return 10;
} else if (score > LEVEL5 + LEVEL5 / 2) { } else if (score > LEVEL5 + LEVEL5 / 2) {
return 9; return 9;
} else if (score > LEVEL5) { } else if (score > LEVEL5) {
return 8; return 8;
} else if (score > LEVEL4 + LEVEL4 / 2) { } else if (score > LEVEL4 + LEVEL4 / 2) {
return 7; return 7;
} else if (score > LEVEL4) { } else if (score > LEVEL4) {
return 6; return 6;
} else if (score > LEVEL3 + LEVEL3 / 2) { } else if (score > LEVEL3 + LEVEL3 / 2) {
return 5; return 5;
} else if (score > LEVEL3) { } else if (score > LEVEL3) {
return 4; return 4;
} else if (score > LEVEL2 + LEVEL2 / 2) { } else if (score > LEVEL2 + LEVEL2 / 2) {
return 3; return 3;
} else if (score > LEVEL2) { } else if (score > LEVEL2) {
return 2; return 2;
} else if (score > LEVEL2 - LEVEL2 / 2) { } else if (score > LEVEL2 - LEVEL2 / 2) {
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
int getScore() { int getScore() {
return distance ~/ 10 + numCoins * 1000000; return distance ~/ 10 + numCoins * 1000000;
} }
int getPlayerScore() { int getPlayerScore() {
return getScore() ~/ 10000; return getScore() ~/ 10000;
} }
int getPlayerDistance() { int getPlayerDistance() {
return distance ~/ 1000000; return distance ~/ 1000000;
} }
double getVelocity() { double getVelocity() {
if (!isPaused) { if (!isPaused) {
switch (getLevel()) { switch (getLevel()) {
case 7: case 7:
return gameRef.viewport.canvasSize.x * 0.25; return gameRef.viewport.canvasSize.x * 0.25;
case 6: case 6:
return gameRef.viewport.canvasSize.x * 0.20; return gameRef.viewport.canvasSize.x * 0.20;
case 5: case 5:
return gameRef.viewport.canvasSize.x * 0.18; return gameRef.viewport.canvasSize.x * 0.18;
case 4: case 4:
return gameRef.viewport.canvasSize.x * 0.16; return gameRef.viewport.canvasSize.x * 0.16;
case 3: case 3:
return gameRef.viewport.canvasSize.x * 0.14; return gameRef.viewport.canvasSize.x * 0.14;
case 2: case 2:
return gameRef.viewport.canvasSize.x * 0.12; return gameRef.viewport.canvasSize.x * 0.12;
default: default:
return gameRef.viewport.canvasSize.x * 0.1; return gameRef.viewport.canvasSize.x * 0.1;
} }
} else { } else {
return 0; return 0;
} }
} }
} }

View File

@ -1,88 +1,94 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'main.dart'; import 'main.dart';
class LoseMenuOverlay extends StatelessWidget { class LoseMenuOverlay extends StatelessWidget {
const LoseMenuOverlay({ const LoseMenuOverlay({
Key? key, Key? key,
required this.game, required this.game,
}) : super(key: key); }) : super(key: key);
final MyGame game; final MyGame game;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return Center(
child: Container( child: Container(
height: game.viewport.canvasSize.y, height: game.viewport.canvasSize.y,
width: game.viewport.canvasSize.x, width: game.viewport.canvasSize.x,
decoration: const BoxDecoration( decoration: const BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage('assets/images/overlay100.png'), image: AssetImage('assets/images/overlay100.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
), ),
), ),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Text(
'Score: ' + game.gameState.getPlayerScore().toString(), 'Score: ' + game.gameState.getPlayerScore().toString(),
style: overlayText, style: overlayText,
), ),
const SizedBox(height: 32.0), const SizedBox(height: 32.0),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
MaterialButton( MaterialButton(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
textColor: Colors.white, textColor: Colors.white,
splashColor: Colors.greenAccent, splashColor: Colors.greenAccent,
elevation: 8.0, elevation: 8.0,
child: Container( child: Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage('assets/images/button.png'), image: AssetImage('assets/images/button.png'),
fit: BoxFit.fill), fit: BoxFit.fill),
), ),
child: const Padding( child: const Padding(
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
child: Text("Main Menu"), child: Text(
), " Main Menu ",
), style: overlayText,
// ), ),
onPressed: () { ),
// Go to the Main Menu ),
}, // ),
), onPressed: () {
const SizedBox( // Go to the Main Menu
width: 32.0, },
), ),
MaterialButton( const SizedBox(
padding: const EdgeInsets.all(8.0), width: 32.0,
textColor: Colors.white, ),
splashColor: Colors.greenAccent, MaterialButton(
elevation: 8.0, padding: const EdgeInsets.all(8.0),
child: Container( textColor: Colors.white,
decoration: const BoxDecoration( splashColor: Colors.greenAccent,
image: DecorationImage( elevation: 8.0,
image: AssetImage('assets/images/button.png'), child: Container(
fit: BoxFit.fill), decoration: const BoxDecoration(
), image: DecorationImage(
child: const Padding( image: AssetImage('assets/images/button.png'),
padding: EdgeInsets.all(8.0), fit: BoxFit.fill),
child: Text("Replay"), ),
), child: const Padding(
), padding: EdgeInsets.all(8.0),
// ), child: Text(
onPressed: () { " Replay ",
game.reset(); style: overlayText,
}, ),
), ),
], ),
), // ),
], onPressed: () {
), game.reset();
), },
); ),
} ],
} ),
],
),
),
);
}
}

View File

@ -1,441 +1,441 @@
import 'dart:math'; import 'dart:math';
import 'package:firo_runner/bug_holder.dart'; import 'package:firo_runner/bug_holder.dart';
import 'package:firo_runner/circuit_background.dart'; import 'package:firo_runner/circuit_background.dart';
import 'package:firo_runner/coin_holder.dart'; import 'package:firo_runner/coin_holder.dart';
import 'package:firo_runner/debris_holder.dart'; import 'package:firo_runner/debris_holder.dart';
import 'package:firo_runner/firework.dart'; import 'package:firo_runner/firework.dart';
import 'package:firo_runner/game_state.dart'; import 'package:firo_runner/game_state.dart';
import 'package:firo_runner/moving_object.dart'; import 'package:firo_runner/moving_object.dart';
import 'package:firo_runner/platform.dart'; import 'package:firo_runner/platform.dart';
import 'package:firo_runner/platform_holder.dart'; import 'package:firo_runner/platform_holder.dart';
import 'package:firo_runner/wall_holder.dart'; import 'package:firo_runner/wall_holder.dart';
import 'package:firo_runner/wire.dart'; import 'package:firo_runner/wire.dart';
import 'package:firo_runner/wire_holder.dart'; import 'package:firo_runner/wire_holder.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/extensions.dart'; import 'package:flame/extensions.dart';
import 'package:flame/flame.dart'; import 'package:flame/flame.dart';
import 'package:flame/game.dart'; import 'package:flame/game.dart';
import 'package:flame/gestures.dart'; import 'package:flame/gestures.dart';
import 'package:flame/keyboard.dart'; import 'package:flame/keyboard.dart';
import 'package:flame_audio/flame_audio.dart'; import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:firo_runner/runner.dart'; import 'package:firo_runner/runner.dart';
import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:firo_runner/lose_menu_overlay.dart'; import 'package:firo_runner/lose_menu_overlay.dart';
const COLOR = Color(0xFFDDC0A3); const COLOR = Color(0xFFDDC0A3);
const LEVEL2 = 10000000; const LEVEL2 = 10000000;
const LEVEL3 = 20000000; const LEVEL3 = 20000000;
const LEVEL4 = 30000000; const LEVEL4 = 30000000;
const LEVEL5 = 40000000; const LEVEL5 = 40000000;
const LEVEL6 = 50000000; const LEVEL6 = 50000000;
const LEVEL7 = 60000000; const LEVEL7 = 60000000;
const OVERLAY_PRIORITY = 110; const OVERLAY_PRIORITY = 110;
const RUNNER_PRIORITY = 100; const RUNNER_PRIORITY = 100;
const BUG_PRIORITY = 75; const BUG_PRIORITY = 75;
const COIN_PRIORITY = 70; const COIN_PRIORITY = 70;
const PLATFORM_PRIORITY = 50; const PLATFORM_PRIORITY = 50;
const WALL_PRIORITY = 40; const WALL_PRIORITY = 40;
const DEBRIS_PRIORITY = 30; const DEBRIS_PRIORITY = 30;
const WIRE_PRIORITY = 25; const WIRE_PRIORITY = 25;
const FIREWORK_PRIORITY = 15; const FIREWORK_PRIORITY = 15;
const WINDOW_PRIORITY = 10; const WINDOW_PRIORITY = 10;
const overlayText = TextStyle( const overlayText = TextStyle(
fontSize: 30, fontSize: 30,
color: Colors.white, color: Colors.white,
); );
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await Flame.device.fullScreen(); await Flame.device.fullScreen();
await Flame.device.setLandscape(); await Flame.device.setLandscape();
final myGame = MyGame(); final myGame = MyGame();
runApp(GameWidget<MyGame>( runApp(GameWidget<MyGame>(
game: myGame, game: myGame,
overlayBuilderMap: { overlayBuilderMap: {
'gameOver': (_, myGame) { 'gameOver': (_, myGame) {
return LoseMenuOverlay(game: myGame); return LoseMenuOverlay(game: myGame);
}, },
}, },
)); ));
} }
int getNearestPlatform(int level) { int getNearestPlatform(int level) {
return level <= 0 return level <= 0
? 0 ? 0
: level <= 3 : level <= 3
? 2 ? 2
: level <= 6 : level <= 6
? 5 ? 5
: 8; : 8;
} }
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: COLOR),
); );
TextPaint scoresPaint = TextPaint( TextPaint scoresPaint = TextPaint(
config: const TextPaintConfig(fontSize: 16.0, color: COLOR), config: const TextPaintConfig(fontSize: 16.0, color: COLOR),
); );
late CircuitBackground circuitBackground; late CircuitBackground circuitBackground;
late PlatformHolder platformHolder; late PlatformHolder platformHolder;
late CoinHolder coinHolder; late CoinHolder coinHolder;
late WireHolder wireHolder; late WireHolder wireHolder;
late BugHolder bugHolder; late BugHolder bugHolder;
late Firework fireworks; late Firework fireworks;
late DebrisHolder debrisHolder; late DebrisHolder debrisHolder;
late WallHolder wallHolder; late WallHolder wallHolder;
Random random = Random(); Random random = Random();
bool playingMusic = false; bool playingMusic = false;
late Runner runner; late Runner runner;
late GameState gameState; late GameState gameState;
late double blockSize; late double blockSize;
bool loaded = false; bool loaded = false;
bool firstDeath = true; bool firstDeath = true;
late Wire wire; late Wire wire;
late TextComponent _distance; late TextComponent _distance;
late TextComponent _coins; late TextComponent _coins;
MyGame() : super() { MyGame() : super() {
viewport.resize(Vector2(1920, 1080)); viewport.resize(Vector2(1920, 1080));
} }
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
// debugMode = true; // debugMode = true;
FlameAudio.bgm.initialize(); FlameAudio.bgm.initialize();
circuitBackground = CircuitBackground(this); circuitBackground = CircuitBackground(this);
await circuitBackground.load(); await circuitBackground.load();
platformHolder = PlatformHolder(); platformHolder = PlatformHolder();
await platformHolder.load(); await platformHolder.load();
coinHolder = CoinHolder(); coinHolder = CoinHolder();
await coinHolder.load(); await coinHolder.load();
wireHolder = WireHolder(); wireHolder = WireHolder();
await wireHolder.load(); await wireHolder.load();
bugHolder = BugHolder(); bugHolder = BugHolder();
await bugHolder.load(); await bugHolder.load();
debrisHolder = DebrisHolder(); debrisHolder = DebrisHolder();
await debrisHolder.load(); await debrisHolder.load();
wallHolder = WallHolder(); wallHolder = WallHolder();
await wallHolder.load(); await wallHolder.load();
fireworks = Firework(this); fireworks = Firework(this);
await fireworks.load(); await fireworks.load();
gameState = GameState(); gameState = GameState();
runner = Runner(); runner = Runner();
await runner.load(loadSpriteAnimation); await runner.load(loadSpriteAnimation);
if (!kIsWeb) { if (!kIsWeb) {
playMusic(); playMusic();
} }
loaded = true; loaded = true;
_distance = TextComponent("Distance: 0", _distance = TextComponent("Distance: 0",
position: Vector2(size.x - 100, 10), textRenderer: scoresPaint) position: Vector2(size.x - 100, 10), textRenderer: scoresPaint)
..anchor = Anchor.topRight; ..anchor = Anchor.topRight;
_distance.changePriorityWithoutResorting(OVERLAY_PRIORITY); _distance.changePriorityWithoutResorting(OVERLAY_PRIORITY);
_coins = TextComponent("Coins: 0", _coins = TextComponent("Coins: 0",
position: Vector2(size.x - 10, 10), textRenderer: scoresPaint) position: Vector2(size.x - 10, 10), textRenderer: scoresPaint)
..anchor = Anchor.topRight; ..anchor = Anchor.topRight;
_coins.changePriorityWithoutResorting(OVERLAY_PRIORITY); _coins.changePriorityWithoutResorting(OVERLAY_PRIORITY);
setUp(); setUp();
} }
void playMusic() { void playMusic() {
FlameAudio.bgm.play('Infinite_Spankage_M.mp3'); FlameAudio.bgm.play('Infinite_Spankage_M.mp3');
playingMusic = true; playingMusic = true;
} }
void fillScreen() { void fillScreen() {
if (shouldReset) { if (shouldReset) {
return; return;
} }
platformHolder.generatePlatforms(this); platformHolder.generatePlatforms(this);
int wireChosenRegion = random.nextInt(9); int wireChosenRegion = random.nextInt(9);
if (wireChosenRegion % 3 != 2 && if (wireChosenRegion % 3 != 2 &&
wireChosenRegion != 6 && wireChosenRegion != 6 &&
wireChosenRegion != 7) { wireChosenRegion != 7) {
wireHolder.generateWire(this, wireChosenRegion); wireHolder.generateWire(this, wireChosenRegion);
} }
int bugChosenRegion = random.nextInt(9); int bugChosenRegion = random.nextInt(9);
if (bugChosenRegion % 3 != 2 && bugChosenRegion % 3 != 0) { if (bugChosenRegion % 3 != 2 && bugChosenRegion % 3 != 0) {
bugHolder.generateBug(this, bugChosenRegion); bugHolder.generateBug(this, bugChosenRegion);
} }
int debrisChosenRegion = random.nextInt(9); int debrisChosenRegion = random.nextInt(9);
if (debrisChosenRegion % 3 == 0 && debrisChosenRegion != 6) { if (debrisChosenRegion % 3 == 0 && debrisChosenRegion != 6) {
debrisHolder.generateDebris(this, debrisChosenRegion); debrisHolder.generateDebris(this, debrisChosenRegion);
} }
int choseCoinLevel = random.nextInt(9); int choseCoinLevel = random.nextInt(9);
if (choseCoinLevel % 3 != 2 && choseCoinLevel != 6) { if (choseCoinLevel % 3 != 2 && choseCoinLevel != 6) {
coinHolder.generateCoin(this, choseCoinLevel); coinHolder.generateCoin(this, choseCoinLevel);
} }
int wallChosenRegion = random.nextInt(9); int wallChosenRegion = random.nextInt(9);
if (wallChosenRegion % 3 == 1 && wallChosenRegion != 7) { if (wallChosenRegion % 3 == 1 && wallChosenRegion != 7) {
wallHolder.generateWall(this, wallChosenRegion); wallHolder.generateWall(this, wallChosenRegion);
} }
} }
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,
3 * rect.top - 2 * (rect.top + blockSize) - 1, 3 * rect.top - 2 * (rect.top + blockSize) - 1,
3 * (rect.left + blockSize) - 2 * rect.left + 1, 3 * (rect.left + blockSize) - 2 * rect.left + 1,
3 * (rect.top + blockSize) - 2 * rect.top + 1); 3 * (rect.top + blockSize) - 2 * rect.top + 1);
for (List<MovingObject> wireLevel in wireHolder.objects) { for (List<MovingObject> wireLevel in wireHolder.objects) {
for (MovingObject wire in wireLevel) { for (MovingObject wire in wireLevel) {
if (wire.intersect(obstacleBounds) != "none") { if (wire.intersect(obstacleBounds) != "none") {
return true; return true;
} }
} }
} }
for (List<MovingObject> coinLevel in coinHolder.objects) { for (List<MovingObject> coinLevel in coinHolder.objects) {
for (MovingObject coin in coinLevel) { for (MovingObject coin in coinLevel) {
if (coin.intersect(obstacleBounds) != "none") { if (coin.intersect(obstacleBounds) != "none") {
return true; return true;
} }
} }
} }
for (List<MovingObject> bugLevel in bugHolder.objects) { for (List<MovingObject> bugLevel in bugHolder.objects) {
for (MovingObject bug in bugLevel) { for (MovingObject bug in bugLevel) {
if (bug.intersect(obstacleBounds) != "none") { if (bug.intersect(obstacleBounds) != "none") {
return true; return true;
} }
} }
} }
for (List<MovingObject> debrisLevel in debrisHolder.objects) { for (List<MovingObject> debrisLevel in debrisHolder.objects) {
for (MovingObject debris in debrisLevel) { for (MovingObject debris in debrisLevel) {
if (debris.intersect(obstacleBounds) != "none") { if (debris.intersect(obstacleBounds) != "none") {
return true; return true;
} }
} }
} }
for (List<MovingObject> wallLevel in wallHolder.objects) { for (List<MovingObject> wallLevel in wallHolder.objects) {
for (MovingObject wall in wallLevel) { for (MovingObject wall in wallLevel) {
if (wall.intersect(obstacleBounds) != "none") { if (wall.intersect(obstacleBounds) != "none") {
return true; return true;
} }
} }
} }
return false; return false;
} }
bool shouldReset = false; bool shouldReset = false;
void displayLoss() { void displayLoss() {
if (!(runner.sprite.animation?.done() ?? false) && if (!(runner.sprite.animation?.done() ?? false) &&
runner.sprite.animation!.loop == false && runner.sprite.animation!.loop == false &&
firstDeath) { firstDeath) {
return; return;
} }
firstDeath = false; firstDeath = false;
overlays.add('gameOver'); overlays.add('gameOver');
} }
void reset() { void reset() {
runner.sprite.animation!.reset(); runner.sprite.animation!.reset();
overlays.remove('gameOver'); overlays.remove('gameOver');
shouldReset = false; shouldReset = false;
components.clear(); components.clear();
setUp(); setUp();
} }
void die() { void die() {
gameState.setPaused(); gameState.setPaused();
shouldReset = true; shouldReset = true;
} }
void setUp() { void setUp() {
add(runner); add(runner);
fireworks.setUp(); fireworks.setUp();
runner.sprite.clearEffects(); runner.sprite.clearEffects();
runner.sprite.current = RunnerState.run; runner.sprite.current = RunnerState.run;
circuitBackground.setUp(); circuitBackground.setUp();
platformHolder.setUp(); platformHolder.setUp();
coinHolder.setUp(); coinHolder.setUp();
wireHolder.setUp(); wireHolder.setUp();
bugHolder.setUp(); bugHolder.setUp();
debrisHolder.setUp(); debrisHolder.setUp();
wallHolder.setUp(); wallHolder.setUp();
gameState.setUp(this); gameState.setUp(this);
runner.setUp(); runner.setUp();
add(_coins); add(_coins);
add(_distance); add(_distance);
fillScreen(); fillScreen();
platformHolder.objects[2][0].sprite.current = PlatformState.left; platformHolder.objects[2][0].sprite.current = PlatformState.left;
platformHolder.objects[5][0].sprite.current = PlatformState.left; platformHolder.objects[5][0].sprite.current = PlatformState.left;
} }
@override @override
void render(Canvas canvas) { void render(Canvas canvas) {
circuitBackground.render(canvas); circuitBackground.render(canvas);
fireworks.renderText(canvas); fireworks.renderText(canvas);
super.render(canvas); super.render(canvas);
final fpsCount = fps(10000); final fpsCount = fps(10000);
fireworksPaint.render( fireworksPaint.render(
canvas, canvas,
fpsCount.toString(), fpsCount.toString(),
Vector2(0, 0), Vector2(0, 0),
); );
} }
@override @override
void update(double dt) { void update(double dt) {
fireworks.update(dt); fireworks.update(dt);
platformHolder.removePast(this); platformHolder.removePast(this);
coinHolder.removePast(this); coinHolder.removePast(this);
wireHolder.removePast(this); wireHolder.removePast(this);
bugHolder.removePast(this); bugHolder.removePast(this);
debrisHolder.removePast(this); debrisHolder.removePast(this);
wallHolder.removePast(this); wallHolder.removePast(this);
fillScreen(); fillScreen();
super.update(dt); super.update(dt);
circuitBackground.update(dt); circuitBackground.update(dt);
gameState.update(dt); gameState.update(dt);
platformHolder.update(dt); platformHolder.update(dt);
coinHolder.update(dt); coinHolder.update(dt);
wireHolder.update(dt); wireHolder.update(dt);
bugHolder.update(dt); bugHolder.update(dt);
debrisHolder.update(dt); debrisHolder.update(dt);
wallHolder.update(dt); wallHolder.update(dt);
_distance.text = "Distance: ${gameState.getPlayerDistance()}"; _distance.text = "Distance: ${gameState.getPlayerDistance()}";
_coins.text = "Coins: ${gameState.numCoins}"; _coins.text = "Coins: ${gameState.numCoins}";
if (shouldReset && !overlays.isActive('gameOver')) { if (shouldReset && !overlays.isActive('gameOver')) {
displayLoss(); displayLoss();
} }
} }
@override @override
void onResize(Vector2 canvasSize) { void onResize(Vector2 canvasSize) {
Vector2 oldSize = viewport.canvasSize; Vector2 oldSize = viewport.canvasSize;
super.onResize(canvasSize); super.onResize(canvasSize);
blockSize = canvasSize.y / 9; blockSize = canvasSize.y / 9;
if (loaded) { if (loaded) {
double xRatio = canvasSize.x / oldSize.x; double xRatio = canvasSize.x / oldSize.x;
double yRatio = canvasSize.y / oldSize.y; double yRatio = canvasSize.y / oldSize.y;
circuitBackground.resize(canvasSize, xRatio, yRatio); circuitBackground.resize(canvasSize, xRatio, yRatio);
runner.resize(canvasSize, xRatio, yRatio); runner.resize(canvasSize, xRatio, yRatio);
platformHolder.resize(canvasSize, xRatio, yRatio); platformHolder.resize(canvasSize, xRatio, yRatio);
coinHolder.resize(canvasSize, xRatio, yRatio); coinHolder.resize(canvasSize, xRatio, yRatio);
wireHolder.resize(canvasSize, xRatio, yRatio); wireHolder.resize(canvasSize, xRatio, yRatio);
bugHolder.resize(canvasSize, xRatio, yRatio); bugHolder.resize(canvasSize, xRatio, yRatio);
debrisHolder.resize(canvasSize, xRatio, yRatio); debrisHolder.resize(canvasSize, xRatio, yRatio);
wallHolder.resize(canvasSize, xRatio, yRatio); wallHolder.resize(canvasSize, xRatio, yRatio);
fireworks.resize(canvasSize, xRatio, yRatio); fireworks.resize(canvasSize, xRatio, yRatio);
} }
} }
// Mobile controls // Mobile controls
late List<double> xDeltas; late List<double> xDeltas;
late List<double> yDeltas; late List<double> yDeltas;
@override @override
void onPanStart(DragStartInfo info) { void onPanStart(DragStartInfo info) {
xDeltas = List.empty(growable: true); xDeltas = List.empty(growable: true);
yDeltas = List.empty(growable: true); yDeltas = List.empty(growable: true);
} }
@override @override
void onPanUpdate(DragUpdateInfo info) { void onPanUpdate(DragUpdateInfo info) {
xDeltas.add(info.delta.game.x); xDeltas.add(info.delta.game.x);
yDeltas.add(info.delta.game.y); yDeltas.add(info.delta.game.y);
} }
@override @override
void onPanEnd(DragEndInfo info) { void onPanEnd(DragEndInfo info) {
if (!playingMusic && kIsWeb) { if (!playingMusic && kIsWeb) {
playMusic(); playMusic();
} }
double xDelta = xDeltas.isEmpty double xDelta = xDeltas.isEmpty
? 0 ? 0
: xDeltas.reduce((value, element) => value + element); : xDeltas.reduce((value, element) => value + element);
double yDelta = yDeltas.isEmpty double yDelta = yDeltas.isEmpty
? 0 ? 0
: yDeltas.reduce((value, element) => value + element); : yDeltas.reduce((value, element) => value + element);
if (xDelta.abs() > yDelta.abs()) { if (xDelta.abs() > yDelta.abs()) {
if (xDelta > 0) { if (xDelta > 0) {
runner.control("right"); runner.control("right");
} else { } else {
runner.control("left"); runner.control("left");
} }
} else if (xDelta.abs() < yDelta.abs()) { } else if (xDelta.abs() < yDelta.abs()) {
if (yDelta > 0) { if (yDelta > 0) {
runner.control("down"); runner.control("down");
} else { } else {
runner.control("up"); runner.control("up");
} }
} }
} }
@override @override
void onTap() { void onTap() {
if (!playingMusic && kIsWeb) { if (!playingMusic && kIsWeb) {
playMusic(); playMusic();
} }
runner.control("center"); runner.control("center");
} }
// Keyboard controls. // Keyboard controls.
var keyboardKey; var keyboardKey;
@override @override
void onKeyEvent(RawKeyEvent event) { void onKeyEvent(RawKeyEvent event) {
if (!playingMusic && kIsWeb) { if (!playingMusic && kIsWeb) {
playMusic(); playMusic();
} }
print(event.data.logicalKey.keyId); print(event.data.logicalKey.keyId);
print(event.data.keyLabel); print(event.data.keyLabel);
if (event is RawKeyUpEvent) { if (event is RawKeyUpEvent) {
keyboardKey = null; keyboardKey = null;
switch (event.data.keyLabel) { switch (event.data.keyLabel) {
case "w": case "w":
runner.control("up"); runner.control("up");
break; break;
case "a": case "a":
runner.control("left"); runner.control("left");
break; break;
case "s": case "s":
runner.control("down"); runner.control("down");
break; break;
case "d": case "d":
runner.control("right"); runner.control("right");
break; break;
default: default:
if (event.data.logicalKey.keyId == 32) { if (event.data.logicalKey.keyId == 32) {
runner.control("down"); runner.control("down");
} }
break; break;
} }
} }
if (event is RawKeyDownEvent && event.data.logicalKey.keyId == 32) { if (event is RawKeyDownEvent && event.data.logicalKey.keyId == 32) {
if (keyboardKey == null) { if (keyboardKey == null) {
runner.control("center"); runner.control("center");
} }
keyboardKey = "spacebar"; keyboardKey = "spacebar";
} }
} }
} }

View File

@ -64,7 +64,7 @@ class Platform extends MovingObject {
PlatformState.right: right, PlatformState.right: right,
PlatformState.single: single, PlatformState.single: single,
}, },
current: PlatformState.single, current: PlatformState.mid,
); );
sprite.changePriorityWithoutResorting(PLATFORM_PRIORITY); sprite.changePriorityWithoutResorting(PLATFORM_PRIORITY);
@ -112,14 +112,19 @@ class Platform extends MovingObject {
bool hasLeft = (left.x - sprite.position.x).abs() < 1.9 * sprite.size.x; 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 hasRight = (sprite.position.x - right.x).abs() < 1.9 * sprite.size.x;
if (hasLeft && hasRight) { // If the platform cannot be seen by the player.
sprite.current = PlatformState.mid; if (!((sprite.x >= 0 && sprite.x <= gameRef.size.x) ||
} else if (hasLeft && !hasRight) { (sprite.x + sprite.width >= 0 &&
sprite.current = PlatformState.right; sprite.x + sprite.width <= gameRef.size.x))) {
} else if (!hasLeft && hasRight) { if (hasLeft && hasRight) {
sprite.current = PlatformState.left; sprite.current = PlatformState.mid;
} else { } else if (hasLeft && !hasRight) {
sprite.current = PlatformState.single; sprite.current = PlatformState.right;
} else if (!hasLeft && hasRight) {
sprite.current = PlatformState.left;
} else {
sprite.current = PlatformState.single;
}
} }
} }
} }

View File

@ -14,6 +14,8 @@ class PlatformHolder extends Holder {
late Image r2; late Image r2;
late Image o1; late Image o1;
late Image o2; late Image o2;
bool noTopObstaclesForNext = false;
bool noMiddleObstaclesForNext = false;
int timeSinceLastTopHole = 0; int timeSinceLastTopHole = 0;
int timeSinceLastBottomHole = 0; int timeSinceLastBottomHole = 0;
@ -91,6 +93,7 @@ class PlatformHolder extends Holder {
remove(objects[2], objects[2].length - 2); remove(objects[2], objects[2].length - 2);
timeSinceLastTopHole = 0; timeSinceLastTopHole = 0;
noTopObstaclesForNext = true;
} }
if (bottomChance > 30) { if (bottomChance > 30) {
Platform start = objects[5].elementAt(objects[5].length - 10) as Platform; Platform start = objects[5].elementAt(objects[5].length - 10) as Platform;
@ -112,6 +115,7 @@ class PlatformHolder extends Holder {
remove(objects[5], firstToRemove); remove(objects[5], firstToRemove);
timeSinceLastBottomHole = 0; timeSinceLastBottomHole = 0;
noMiddleObstaclesForNext = true;
} }
} }
@ -129,6 +133,13 @@ class PlatformHolder extends Holder {
platform.row = level; platform.row = level;
gameRef.add(platform.sprite); gameRef.add(platform.sprite);
objects[level].add(platform); objects[level].add(platform);
if (level == 2 && noTopObstaclesForNext) {
platform.prohibitObstacles = true;
noTopObstaclesForNext = false;
} else if (level == 5 && noMiddleObstaclesForNext) {
platform.prohibitObstacles = true;
noMiddleObstaclesForNext = false;
}
return false; return false;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ class Wall extends MovingObject {
gameRef.blockSize * gameRef.blockSize *
(gameRef.wallHolder.wall.width / gameRef.wallHolder.wall.height / 5) * (gameRef.wallHolder.wall.width / gameRef.wallHolder.wall.height / 5) *
2.0, 2.0,
gameRef.blockSize * 0.5, gameRef.blockSize * 0.35,
); );
} }