BIN
assets/images/overlay100.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
assets/images/overlay40.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/images/overlay50.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/images/overlay60.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/images/overlay70.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/images/overlay80.png
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
assets/images/overlay90.png
Normal file
After Width: | Height: | Size: 54 KiB |
@ -14,8 +14,27 @@ enum WindowState {
|
||||
seventh,
|
||||
}
|
||||
|
||||
enum OverlayState {
|
||||
first,
|
||||
second,
|
||||
third,
|
||||
fourth,
|
||||
fifth,
|
||||
sixth,
|
||||
seventh,
|
||||
}
|
||||
|
||||
class CircuitBackground extends MovingObject {
|
||||
late Image background;
|
||||
|
||||
late Image overlay0;
|
||||
late Image overlay1;
|
||||
late Image overlay2;
|
||||
late Image overlay3;
|
||||
late Image overlay4;
|
||||
late Image overlay5;
|
||||
late Image overlay6;
|
||||
|
||||
late Image windows0;
|
||||
late Image windows1;
|
||||
late Image windows2;
|
||||
@ -28,6 +47,8 @@ class CircuitBackground extends MovingObject {
|
||||
late Sprite background2;
|
||||
late SpriteAnimationGroupComponent windowA;
|
||||
late SpriteAnimationGroupComponent windowB;
|
||||
late SpriteAnimationGroupComponent overlayA;
|
||||
late SpriteAnimationGroupComponent overlayB;
|
||||
Vector2 background1Size = Vector2(0, 0);
|
||||
Vector2 background2Size = Vector2(0, 0);
|
||||
Vector2 background1Position = Vector2(0, 0);
|
||||
@ -40,6 +61,100 @@ class CircuitBackground extends MovingObject {
|
||||
background1 = Sprite(background);
|
||||
background2 = Sprite(background);
|
||||
|
||||
overlay0 = await Flame.images.load("overlay100.png");
|
||||
overlay1 = await Flame.images.load("overlay90.png");
|
||||
overlay2 = await Flame.images.load("overlay80.png");
|
||||
overlay3 = await Flame.images.load("overlay70.png");
|
||||
overlay4 = await Flame.images.load("overlay60.png");
|
||||
overlay5 = await Flame.images.load("overlay50.png");
|
||||
overlay6 = await Flame.images.load("overlay40.png");
|
||||
|
||||
SpriteAnimation firstOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay0,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation secondOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay1,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation thirdOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay2,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation fourthOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay3,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation fifthOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay4,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation sixthOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay5,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation seventhOverlay = SpriteAnimation.fromFrameData(
|
||||
overlay6,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
stepTime: 1,
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
overlayA = SpriteAnimationGroupComponent(
|
||||
animations: {
|
||||
OverlayState.first: firstOverlay,
|
||||
OverlayState.second: secondOverlay,
|
||||
OverlayState.third: thirdOverlay,
|
||||
OverlayState.fourth: fourthOverlay,
|
||||
OverlayState.fifth: fifthOverlay,
|
||||
OverlayState.sixth: sixthOverlay,
|
||||
OverlayState.seventh: seventhOverlay,
|
||||
},
|
||||
current: OverlayState.first,
|
||||
);
|
||||
|
||||
overlayB = SpriteAnimationGroupComponent(
|
||||
animations: {
|
||||
OverlayState.first: firstOverlay,
|
||||
OverlayState.second: secondOverlay,
|
||||
OverlayState.third: thirdOverlay,
|
||||
OverlayState.fourth: fourthOverlay,
|
||||
OverlayState.fifth: fifthOverlay,
|
||||
OverlayState.sixth: sixthOverlay,
|
||||
OverlayState.seventh: seventhOverlay,
|
||||
},
|
||||
current: OverlayState.first,
|
||||
);
|
||||
|
||||
overlayA.changePriorityWithoutResorting(WINDOW_PRIORITY - 1);
|
||||
|
||||
overlayA.changePriorityWithoutResorting(WINDOW_PRIORITY - 1);
|
||||
|
||||
windows0 = await Flame.images.load("windows-0.png");
|
||||
windows1 = await Flame.images.load("windows-1.png");
|
||||
windows2 = await Flame.images.load("windows-2.png");
|
||||
@ -48,7 +163,7 @@ class CircuitBackground extends MovingObject {
|
||||
windows5 = await Flame.images.load("windows-5.png");
|
||||
windows6 = await Flame.images.load("windows-6.png");
|
||||
|
||||
SpriteAnimation first = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation firstWindow = SpriteAnimation.fromFrameData(
|
||||
windows0,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -56,7 +171,7 @@ class CircuitBackground extends MovingObject {
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation second = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation secondWindow = SpriteAnimation.fromFrameData(
|
||||
windows1,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -64,7 +179,7 @@ class CircuitBackground extends MovingObject {
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation third = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation thirdWindow = SpriteAnimation.fromFrameData(
|
||||
windows2,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -72,7 +187,7 @@ class CircuitBackground extends MovingObject {
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation fourth = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation fourthWindow = SpriteAnimation.fromFrameData(
|
||||
windows3,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -80,7 +195,7 @@ class CircuitBackground extends MovingObject {
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation fifth = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation fifthWindow = SpriteAnimation.fromFrameData(
|
||||
windows4,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -88,7 +203,7 @@ class CircuitBackground extends MovingObject {
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation sixth = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation sixthWindow = SpriteAnimation.fromFrameData(
|
||||
windows5,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -96,7 +211,7 @@ class CircuitBackground extends MovingObject {
|
||||
textureSize: Vector2(6000, 2000),
|
||||
loop: false));
|
||||
|
||||
SpriteAnimation seventh = SpriteAnimation.fromFrameData(
|
||||
SpriteAnimation seventhWindow = SpriteAnimation.fromFrameData(
|
||||
windows6,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: 1,
|
||||
@ -106,26 +221,26 @@ class CircuitBackground extends MovingObject {
|
||||
|
||||
windowA = SpriteAnimationGroupComponent(
|
||||
animations: {
|
||||
WindowState.first: first,
|
||||
WindowState.second: second,
|
||||
WindowState.third: third,
|
||||
WindowState.fourth: fourth,
|
||||
WindowState.fifth: fifth,
|
||||
WindowState.sixth: sixth,
|
||||
WindowState.seventh: seventh,
|
||||
WindowState.first: firstWindow,
|
||||
WindowState.second: secondWindow,
|
||||
WindowState.third: thirdWindow,
|
||||
WindowState.fourth: fourthWindow,
|
||||
WindowState.fifth: fifthWindow,
|
||||
WindowState.sixth: sixthWindow,
|
||||
WindowState.seventh: seventhWindow,
|
||||
},
|
||||
current: WindowState.first,
|
||||
);
|
||||
|
||||
windowB = SpriteAnimationGroupComponent(
|
||||
animations: {
|
||||
WindowState.first: first,
|
||||
WindowState.second: second,
|
||||
WindowState.third: third,
|
||||
WindowState.fourth: fourth,
|
||||
WindowState.fifth: fifth,
|
||||
WindowState.sixth: sixth,
|
||||
WindowState.seventh: seventh,
|
||||
WindowState.first: firstWindow,
|
||||
WindowState.second: secondWindow,
|
||||
WindowState.third: thirdWindow,
|
||||
WindowState.fourth: fourthWindow,
|
||||
WindowState.fifth: fifthWindow,
|
||||
WindowState.sixth: sixthWindow,
|
||||
WindowState.seventh: seventhWindow,
|
||||
},
|
||||
current: WindowState.first,
|
||||
);
|
||||
@ -140,12 +255,16 @@ class CircuitBackground extends MovingObject {
|
||||
void setUp() {
|
||||
windowA.current = WindowState.first;
|
||||
windowB.current = WindowState.first;
|
||||
overlayA.current = OverlayState.first;
|
||||
overlayB.current = OverlayState.first;
|
||||
background1Position = Vector2(0, 0);
|
||||
background1Size = Vector2(
|
||||
gameRef.viewport.canvasSize.y * (background.width / background.height),
|
||||
gameRef.viewport.canvasSize.y);
|
||||
windowA.position = background1Position;
|
||||
windowA.size = background1Size;
|
||||
overlayA.position = background1Position;
|
||||
overlayA.size = background1Size;
|
||||
|
||||
background2Position =
|
||||
Vector2(background1Position.x + background1Size.x - 1, 0);
|
||||
@ -154,42 +273,72 @@ class CircuitBackground extends MovingObject {
|
||||
gameRef.viewport.canvasSize.y);
|
||||
windowB.position = background2Position;
|
||||
windowB.size = background2Size;
|
||||
overlayB.position = background2Position;
|
||||
overlayB.size = background2Size;
|
||||
}
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
switch (gameRef.gameState.getLevel()) {
|
||||
switch (gameRef.gameState.getScoreLevel()) {
|
||||
case 12:
|
||||
windowA.current = WindowState.seventh;
|
||||
windowB.current = WindowState.seventh;
|
||||
break;
|
||||
case 11:
|
||||
overlayA.current = OverlayState.seventh;
|
||||
overlayB.current = OverlayState.seventh;
|
||||
break;
|
||||
case 10:
|
||||
windowA.current = WindowState.sixth;
|
||||
windowB.current = WindowState.sixth;
|
||||
break;
|
||||
case 9:
|
||||
overlayA.current = OverlayState.sixth;
|
||||
overlayB.current = OverlayState.sixth;
|
||||
break;
|
||||
case 8:
|
||||
windowA.current = WindowState.fifth;
|
||||
windowB.current = WindowState.fifth;
|
||||
break;
|
||||
case 7:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.seventh;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.seventh;
|
||||
overlayA.current = OverlayState.fifth;
|
||||
overlayB.current = OverlayState.fifth;
|
||||
break;
|
||||
case 6:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.sixth;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.sixth;
|
||||
windowA.current = WindowState.fourth;
|
||||
windowB.current = WindowState.fourth;
|
||||
break;
|
||||
case 5:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.fifth;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.fifth;
|
||||
overlayA.current = OverlayState.fourth;
|
||||
overlayB.current = OverlayState.fourth;
|
||||
break;
|
||||
case 4:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.fourth;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.fourth;
|
||||
windowA.current = WindowState.third;
|
||||
windowB.current = WindowState.third;
|
||||
break;
|
||||
case 3:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.third;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.third;
|
||||
overlayA.current = OverlayState.third;
|
||||
overlayB.current = OverlayState.third;
|
||||
break;
|
||||
case 2:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.second;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.second;
|
||||
windowA.current = WindowState.second;
|
||||
windowB.current = WindowState.second;
|
||||
break;
|
||||
case 1:
|
||||
overlayA.current = OverlayState.second;
|
||||
overlayB.current = OverlayState.second;
|
||||
break;
|
||||
default:
|
||||
gameRef.circuitBackground.windowA.current = WindowState.first;
|
||||
gameRef.circuitBackground.windowB.current = WindowState.first;
|
||||
windowA.current = WindowState.first;
|
||||
windowB.current = WindowState.first;
|
||||
overlayA.current = OverlayState.first;
|
||||
overlayB.current = OverlayState.first;
|
||||
break;
|
||||
}
|
||||
windowA.update(dt);
|
||||
windowB.update(dt);
|
||||
overlayA.update(dt);
|
||||
overlayB.update(dt);
|
||||
if (background1Position.x + background1Size.x < 0) {
|
||||
double newPosition = background2Position.x + background2Size.x;
|
||||
background1Position = Vector2(newPosition - 1, 0);
|
||||
@ -201,19 +350,27 @@ class CircuitBackground extends MovingObject {
|
||||
double velocity = gameRef.gameState.getVelocity() / 10.0;
|
||||
background1Position = background1Position - Vector2(velocity * dt, 0);
|
||||
windowA.position = background1Position;
|
||||
overlayA.position = background1Position;
|
||||
background2Position = background2Position - Vector2(velocity * dt, 0);
|
||||
windowB.position = background2Position;
|
||||
overlayB.position = background2Position;
|
||||
}
|
||||
|
||||
void render(Canvas canvas) {
|
||||
background1.render(canvas,
|
||||
size: background1Size, position: background1Position);
|
||||
canvas.save();
|
||||
overlayA.render(canvas);
|
||||
canvas.restore();
|
||||
canvas.save();
|
||||
windowA.render(canvas);
|
||||
canvas.restore();
|
||||
background2.render(canvas,
|
||||
size: background2Size, position: background2Position);
|
||||
canvas.save();
|
||||
overlayB.render(canvas);
|
||||
canvas.restore();
|
||||
canvas.save();
|
||||
windowB.render(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
@ -224,6 +381,8 @@ class CircuitBackground extends MovingObject {
|
||||
Vector2(newSize.y * (background.width / background.height), newSize.y);
|
||||
windowA.position = background1Position;
|
||||
windowA.size = background1Size;
|
||||
overlayA.position = background1Position;
|
||||
overlayA.size = background1Size;
|
||||
|
||||
background2Position =
|
||||
Vector2(background1Position.x + background1Size.x - 1, 0);
|
||||
@ -231,5 +390,7 @@ class CircuitBackground extends MovingObject {
|
||||
Vector2(newSize.y * (background.width / background.height), newSize.y);
|
||||
windowB.position = background2Position;
|
||||
windowB.size = background2Size;
|
||||
overlayB.position = background2Position;
|
||||
overlayB.size = background2Size;
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,8 @@ class Firework extends Component {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
message = gameRef.gameState.numCoins.toString();
|
||||
// message = gameRef.gameState.numCoins.toString();
|
||||
message = "Speed Up!";
|
||||
sprite1.animation!.reset();
|
||||
sprite2.animation!.reset();
|
||||
}
|
||||
|
@ -7,12 +7,17 @@ class GameState extends Component {
|
||||
int numCoins = 0;
|
||||
int distance = 0;
|
||||
late MyGame gameRef;
|
||||
int previousLevel = 1;
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
super.update(dt);
|
||||
if (!isPaused) {
|
||||
distance = DateTime.now().microsecondsSinceEpoch - start;
|
||||
if (previousLevel != getLevel()) {
|
||||
previousLevel = getLevel();
|
||||
gameRef.fireworks.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +29,7 @@ class GameState extends Component {
|
||||
this.gameRef = gameRef;
|
||||
numCoins = 0;
|
||||
distance = 0;
|
||||
previousLevel = 1;
|
||||
start = DateTime.now().microsecondsSinceEpoch;
|
||||
isPaused = false;
|
||||
}
|
||||
@ -50,6 +56,41 @@ class GameState extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
int getScoreLevel() {
|
||||
int score = getScore();
|
||||
if (score > LEVEL7) {
|
||||
return 12;
|
||||
} else if (score > LEVEL6 + LEVEL6 / 2) {
|
||||
return 11;
|
||||
} else if (score > LEVEL6) {
|
||||
return 10;
|
||||
} else if (score > LEVEL5 + LEVEL5 / 2) {
|
||||
return 9;
|
||||
} else if (score > LEVEL5) {
|
||||
return 8;
|
||||
} else if (score > LEVEL4 + LEVEL4 / 2) {
|
||||
return 7;
|
||||
} else if (score > LEVEL4) {
|
||||
return 6;
|
||||
} else if (score > LEVEL3 + LEVEL3 / 2) {
|
||||
return 5;
|
||||
} else if (score > LEVEL3) {
|
||||
return 4;
|
||||
} else if (score > LEVEL2 + LEVEL2 / 2) {
|
||||
return 3;
|
||||
} else if (score > LEVEL2) {
|
||||
return 2;
|
||||
} else if (score > LEVEL2 - LEVEL2 / 2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int getScore() {
|
||||
return distance ~/ 10 + numCoins * 1000000;
|
||||
}
|
||||
|
||||
double getVelocity() {
|
||||
if (!isPaused) {
|
||||
switch (getLevel()) {
|
||||
|
@ -357,9 +357,6 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
for (int i = 0; i < coinLevel.length;) {
|
||||
if (coinLevel[i].intersect(runnerRect) != "none") {
|
||||
gameRef.gameState.numCoins++;
|
||||
if (gameRef.gameState.numCoins % 5 == 0) {
|
||||
gameRef.fireworks.reset();
|
||||
}
|
||||
gameRef.coinHolder.remove(coinLevel, i);
|
||||
continue;
|
||||
}
|
||||
|