Added darkened overlay and visual variety as the game progresses #10. Added fireworks as well #9.

This commit is contained in:
Marco Salazar 2021-09-18 15:52:28 -06:00
parent d676116fd8
commit f7af271384
11 changed files with 240 additions and 40 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
assets/images/overlay40.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
assets/images/overlay50.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
assets/images/overlay60.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
assets/images/overlay70.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
assets/images/overlay80.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
assets/images/overlay90.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -14,8 +14,27 @@ enum WindowState {
seventh, seventh,
} }
enum OverlayState {
first,
second,
third,
fourth,
fifth,
sixth,
seventh,
}
class CircuitBackground extends MovingObject { class CircuitBackground extends MovingObject {
late Image background; 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 windows0;
late Image windows1; late Image windows1;
late Image windows2; late Image windows2;
@ -28,6 +47,8 @@ class CircuitBackground extends MovingObject {
late Sprite background2; late Sprite background2;
late SpriteAnimationGroupComponent windowA; late SpriteAnimationGroupComponent windowA;
late SpriteAnimationGroupComponent windowB; late SpriteAnimationGroupComponent windowB;
late SpriteAnimationGroupComponent overlayA;
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);
@ -40,6 +61,100 @@ class CircuitBackground extends MovingObject {
background1 = Sprite(background); background1 = Sprite(background);
background2 = 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"); 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");
@ -48,7 +163,7 @@ class CircuitBackground extends MovingObject {
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 first = SpriteAnimation.fromFrameData( SpriteAnimation firstWindow = SpriteAnimation.fromFrameData(
windows0, windows0,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -56,7 +171,7 @@ class CircuitBackground extends MovingObject {
textureSize: Vector2(6000, 2000), textureSize: Vector2(6000, 2000),
loop: false)); loop: false));
SpriteAnimation second = SpriteAnimation.fromFrameData( SpriteAnimation secondWindow = SpriteAnimation.fromFrameData(
windows1, windows1,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -64,7 +179,7 @@ class CircuitBackground extends MovingObject {
textureSize: Vector2(6000, 2000), textureSize: Vector2(6000, 2000),
loop: false)); loop: false));
SpriteAnimation third = SpriteAnimation.fromFrameData( SpriteAnimation thirdWindow = SpriteAnimation.fromFrameData(
windows2, windows2,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -72,7 +187,7 @@ class CircuitBackground extends MovingObject {
textureSize: Vector2(6000, 2000), textureSize: Vector2(6000, 2000),
loop: false)); loop: false));
SpriteAnimation fourth = SpriteAnimation.fromFrameData( SpriteAnimation fourthWindow = SpriteAnimation.fromFrameData(
windows3, windows3,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -80,7 +195,7 @@ class CircuitBackground extends MovingObject {
textureSize: Vector2(6000, 2000), textureSize: Vector2(6000, 2000),
loop: false)); loop: false));
SpriteAnimation fifth = SpriteAnimation.fromFrameData( SpriteAnimation fifthWindow = SpriteAnimation.fromFrameData(
windows4, windows4,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -88,7 +203,7 @@ class CircuitBackground extends MovingObject {
textureSize: Vector2(6000, 2000), textureSize: Vector2(6000, 2000),
loop: false)); loop: false));
SpriteAnimation sixth = SpriteAnimation.fromFrameData( SpriteAnimation sixthWindow = SpriteAnimation.fromFrameData(
windows5, windows5,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -96,7 +211,7 @@ class CircuitBackground extends MovingObject {
textureSize: Vector2(6000, 2000), textureSize: Vector2(6000, 2000),
loop: false)); loop: false));
SpriteAnimation seventh = SpriteAnimation.fromFrameData( SpriteAnimation seventhWindow = SpriteAnimation.fromFrameData(
windows6, windows6,
SpriteAnimationData.sequenced( SpriteAnimationData.sequenced(
amount: 1, amount: 1,
@ -106,26 +221,26 @@ class CircuitBackground extends MovingObject {
windowA = SpriteAnimationGroupComponent( windowA = SpriteAnimationGroupComponent(
animations: { animations: {
WindowState.first: first, WindowState.first: firstWindow,
WindowState.second: second, WindowState.second: secondWindow,
WindowState.third: third, WindowState.third: thirdWindow,
WindowState.fourth: fourth, WindowState.fourth: fourthWindow,
WindowState.fifth: fifth, WindowState.fifth: fifthWindow,
WindowState.sixth: sixth, WindowState.sixth: sixthWindow,
WindowState.seventh: seventh, WindowState.seventh: seventhWindow,
}, },
current: WindowState.first, current: WindowState.first,
); );
windowB = SpriteAnimationGroupComponent( windowB = SpriteAnimationGroupComponent(
animations: { animations: {
WindowState.first: first, WindowState.first: firstWindow,
WindowState.second: second, WindowState.second: secondWindow,
WindowState.third: third, WindowState.third: thirdWindow,
WindowState.fourth: fourth, WindowState.fourth: fourthWindow,
WindowState.fifth: fifth, WindowState.fifth: fifthWindow,
WindowState.sixth: sixth, WindowState.sixth: sixthWindow,
WindowState.seventh: seventh, WindowState.seventh: seventhWindow,
}, },
current: WindowState.first, current: WindowState.first,
); );
@ -140,12 +255,16 @@ class CircuitBackground extends MovingObject {
void setUp() { void setUp() {
windowA.current = WindowState.first; windowA.current = WindowState.first;
windowB.current = WindowState.first; windowB.current = WindowState.first;
overlayA.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.size = background1Size;
background2Position = background2Position =
Vector2(background1Position.x + background1Size.x - 1, 0); Vector2(background1Position.x + background1Size.x - 1, 0);
@ -154,42 +273,72 @@ class CircuitBackground extends MovingObject {
gameRef.viewport.canvasSize.y); gameRef.viewport.canvasSize.y);
windowB.position = background2Position; windowB.position = background2Position;
windowB.size = background2Size; windowB.size = background2Size;
overlayB.position = background2Position;
overlayB.size = background2Size;
} }
@override @override
void update(double dt) { 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: case 7:
gameRef.circuitBackground.windowA.current = WindowState.seventh; overlayA.current = OverlayState.fifth;
gameRef.circuitBackground.windowB.current = WindowState.seventh; overlayB.current = OverlayState.fifth;
break; break;
case 6: case 6:
gameRef.circuitBackground.windowA.current = WindowState.sixth; windowA.current = WindowState.fourth;
gameRef.circuitBackground.windowB.current = WindowState.sixth; windowB.current = WindowState.fourth;
break; break;
case 5: case 5:
gameRef.circuitBackground.windowA.current = WindowState.fifth; overlayA.current = OverlayState.fourth;
gameRef.circuitBackground.windowB.current = WindowState.fifth; overlayB.current = OverlayState.fourth;
break; break;
case 4: case 4:
gameRef.circuitBackground.windowA.current = WindowState.fourth; windowA.current = WindowState.third;
gameRef.circuitBackground.windowB.current = WindowState.fourth; windowB.current = WindowState.third;
break; break;
case 3: case 3:
gameRef.circuitBackground.windowA.current = WindowState.third; overlayA.current = OverlayState.third;
gameRef.circuitBackground.windowB.current = WindowState.third; overlayB.current = OverlayState.third;
break; break;
case 2: case 2:
gameRef.circuitBackground.windowA.current = WindowState.second; windowA.current = WindowState.second;
gameRef.circuitBackground.windowB.current = WindowState.second; windowB.current = WindowState.second;
break;
case 1:
overlayA.current = OverlayState.second;
overlayB.current = OverlayState.second;
break; break;
default: default:
gameRef.circuitBackground.windowA.current = WindowState.first; windowA.current = WindowState.first;
gameRef.circuitBackground.windowB.current = WindowState.first; windowB.current = WindowState.first;
overlayA.current = OverlayState.first;
overlayB.current = OverlayState.first;
break; break;
} }
windowA.update(dt); windowA.update(dt);
windowB.update(dt); windowB.update(dt);
overlayA.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);
@ -201,19 +350,27 @@ class CircuitBackground extends MovingObject {
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;
background2Position = background2Position - Vector2(velocity * dt, 0); background2Position = background2Position - Vector2(velocity * dt, 0);
windowB.position = background2Position; windowB.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);
canvas.restore();
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);
canvas.restore();
canvas.save();
windowB.render(canvas); windowB.render(canvas);
canvas.restore(); canvas.restore();
} }
@ -224,6 +381,8 @@ class CircuitBackground extends MovingObject {
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.size = background1Size;
background2Position = background2Position =
Vector2(background1Position.x + background1Size.x - 1, 0); Vector2(background1Position.x + background1Size.x - 1, 0);
@ -231,5 +390,7 @@ class CircuitBackground extends MovingObject {
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.size = background2Size;
} }
} }

View File

@ -93,7 +93,8 @@ class Firework extends Component {
} }
void reset() { void reset() {
message = gameRef.gameState.numCoins.toString(); // message = gameRef.gameState.numCoins.toString();
message = "Speed Up!";
sprite1.animation!.reset(); sprite1.animation!.reset();
sprite2.animation!.reset(); sprite2.animation!.reset();
} }

View File

@ -7,12 +7,17 @@ class GameState extends Component {
int numCoins = 0; int numCoins = 0;
int distance = 0; int distance = 0;
late MyGame gameRef; late MyGame gameRef;
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()) {
previousLevel = getLevel();
gameRef.fireworks.reset();
}
} }
} }
@ -24,6 +29,7 @@ class GameState extends Component {
this.gameRef = gameRef; this.gameRef = gameRef;
numCoins = 0; numCoins = 0;
distance = 0; distance = 0;
previousLevel = 1;
start = DateTime.now().microsecondsSinceEpoch; start = DateTime.now().microsecondsSinceEpoch;
isPaused = false; 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() { double getVelocity() {
if (!isPaused) { if (!isPaused) {
switch (getLevel()) { switch (getLevel()) {

View File

@ -357,9 +357,6 @@ class Runner extends Component with HasGameRef<MyGame> {
for (int i = 0; i < coinLevel.length;) { for (int i = 0; i < coinLevel.length;) {
if (coinLevel[i].intersect(runnerRect) != "none") { if (coinLevel[i].intersect(runnerRect) != "none") {
gameRef.gameState.numCoins++; gameRef.gameState.numCoins++;
if (gameRef.gameState.numCoins % 5 == 0) {
gameRef.fireworks.reset();
}
gameRef.coinHolder.remove(coinLevel, i); gameRef.coinHolder.remove(coinLevel, i);
continue; continue;
} }