Added the full background and the changing windows with each speed level

This commit is contained in:
Marco Salazar 2021-09-07 14:45:42 -06:00
parent f4274e7207
commit adf2831f42
14 changed files with 199 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 881 KiB

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
assets/images/windows-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

BIN
assets/images/windows-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

BIN
assets/images/windows-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

BIN
assets/images/windows-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

BIN
assets/images/windows-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 KiB

BIN
assets/images/windows-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 KiB

BIN
assets/images/windows-6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 KiB

After

Width:  |  Height:  |  Size: 310 KiB

View File

@ -4,10 +4,30 @@ import 'package:flame/components.dart';
import 'package:flame/flame.dart';
import 'package:flutter/material.dart';
enum WindowState {
first,
second,
third,
fourth,
fifth,
sixth,
seventh,
}
class CircuitBackground extends MovingObject {
late var background;
late var windows0;
late var windows1;
late var windows2;
late var windows3;
late var windows4;
late var windows5;
late var windows6;
late Sprite background1;
late Sprite background2;
late SpriteAnimationGroupComponent windowA;
late SpriteAnimationGroupComponent windowB;
Vector2 background1Size = Vector2(0, 0);
Vector2 background2Size = Vector2(0, 0);
Vector2 background1Position = Vector2(0, 0);
@ -19,23 +39,155 @@ class CircuitBackground extends MovingObject {
background = await Flame.images.load("bg.png");
background1 = Sprite(background);
background2 = Sprite(background);
windows0 = await Flame.images.load("windows-0.png");
windows1 = await Flame.images.load("windows-1.png");
windows2 = await Flame.images.load("windows-2.png");
windows3 = await Flame.images.load("windows-3.png");
windows4 = await Flame.images.load("windows-4.png");
windows5 = await Flame.images.load("windows-5.png");
windows6 = await Flame.images.load("windows-6.png");
SpriteAnimation first = SpriteAnimation.fromFrameData(
windows0,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
SpriteAnimation second = SpriteAnimation.fromFrameData(
windows1,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
SpriteAnimation third = SpriteAnimation.fromFrameData(
windows2,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
SpriteAnimation fourth = SpriteAnimation.fromFrameData(
windows3,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
SpriteAnimation fifth = SpriteAnimation.fromFrameData(
windows4,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
SpriteAnimation sixth = SpriteAnimation.fromFrameData(
windows5,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
SpriteAnimation seventh = SpriteAnimation.fromFrameData(
windows6,
SpriteAnimationData.sequenced(
amount: 1,
stepTime: 1,
textureSize: Vector2(6000, 2000),
loop: false));
windowA = SpriteAnimationGroupComponent(
animations: {
WindowState.first: first,
WindowState.second: second,
WindowState.third: third,
WindowState.fourth: fourth,
WindowState.fifth: fifth,
WindowState.sixth: sixth,
WindowState.seventh: seventh,
},
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,
},
current: WindowState.first,
);
setUp();
}
void setUp() {
windowA.current = WindowState.first;
windowB.current = WindowState.first;
gameRef.add(windowA);
gameRef.add(windowB);
background1Position = Vector2(0, 0);
background1Size = Vector2(
gameRef.size.y * (background!.width / background!.height),
gameRef.size.y);
windowA.position = background1Position;
windowA.size = background1Size;
background2Position =
Vector2(background1Position.x + background1Size.x - 1, 0);
background2Size = Vector2(
gameRef.size.y * (background!.width / background!.height),
gameRef.size.y);
windowB.position = background2Position;
windowB.size = background2Size;
}
@override
void update(double dt) {
switch (gameRef.gameState.getLevel()) {
case 7:
gameRef.circuitBackground.windowA.current = WindowState.seventh;
gameRef.circuitBackground.windowB.current = WindowState.seventh;
break;
case 6:
gameRef.circuitBackground.windowA.current = WindowState.sixth;
gameRef.circuitBackground.windowB.current = WindowState.sixth;
break;
case 5:
gameRef.circuitBackground.windowA.current = WindowState.fifth;
gameRef.circuitBackground.windowB.current = WindowState.fifth;
break;
case 4:
gameRef.circuitBackground.windowA.current = WindowState.fourth;
gameRef.circuitBackground.windowB.current = WindowState.fourth;
break;
case 3:
gameRef.circuitBackground.windowA.current = WindowState.third;
gameRef.circuitBackground.windowB.current = WindowState.third;
break;
case 2:
gameRef.circuitBackground.windowA.current = WindowState.second;
gameRef.circuitBackground.windowB.current = WindowState.second;
break;
default:
gameRef.circuitBackground.windowA.current = WindowState.first;
gameRef.circuitBackground.windowB.current = WindowState.first;
break;
}
windowA.update(dt);
windowB.update(dt);
if (background1Position.x + background1Size.x < 0) {
double newPosition = background2Position.x + background2Size.x;
background1Position = Vector2(newPosition - 1, 0);
@ -46,13 +198,17 @@ class CircuitBackground extends MovingObject {
double velocity = gameRef.gameState.getVelocity() / 10.0;
background1Position = background1Position - Vector2(velocity * dt, 0);
windowA.position = background1Position;
background2Position = background2Position - Vector2(velocity * dt, 0);
windowB.position = background2Position;
}
void render(Canvas canvas) {
background1.render(canvas,
size: background1Size, position: background1Position);
// windowA.render(canvas);
background2.render(canvas,
size: background2Size, position: background2Position);
// windowB.render(canvas);
}
}

View File

@ -1,14 +1,7 @@
import 'dart:math';
import 'package:firo_runner/main.dart';
import 'package:flame/components.dart';
import 'package:flutter/material.dart';
class GameState extends Component {
static const int CIRCUIT_PERIOD = 500000;
late Rect square;
late Color color = Colors.white;
late ColorTween tween;
int start = 0;
bool isPaused = false;
int numCoins = 0;
@ -19,7 +12,6 @@ class GameState extends Component {
super.update(dt);
if (!isPaused) {
distance = DateTime.now().microsecondsSinceEpoch - start;
color = tween.lerp(sin(distance.toDouble() / CIRCUIT_PERIOD))!;
}
}
@ -27,25 +19,10 @@ class GameState extends Component {
numCoins++;
}
@override
void render(Canvas c) {
super.render(c);
c.drawRect(square, Paint()..color = color);
}
Future load(Vector2 size) async {
square = Rect.fromLTWH(0, 0, size.x, size.y);
}
void setSize(Vector2 size) {
square = Rect.fromLTWH(0, 0, size.x, size.y);
}
void setUp() {
numCoins = 0;
distance = 0;
start = DateTime.now().microsecondsSinceEpoch;
tween = ColorTween(begin: Colors.yellow, end: Colors.yellowAccent);
isPaused = false;
}
@ -53,14 +30,41 @@ class GameState extends Component {
isPaused = true;
}
int getLevel() {
if (distance > LEVEL7) {
return 7;
} else if (distance > LEVEL6) {
return 6;
} else if (distance > LEVEL5) {
return 5;
} else if (distance > LEVEL4) {
return 4;
} else if (distance > LEVEL3) {
return 3;
} else if (distance > LEVEL2) {
return 2;
} else {
return 1;
}
}
double getVelocity() {
if (!isPaused) {
if (distance > 50000000) {
return 250.0;
} else if (distance > 10000000)
return 175.0;
else {
return 100.0;
switch (getLevel()) {
case 7:
return 250.0;
case 6:
return 200.0;
case 5:
return 180.0;
case 4:
return 160.0;
case 3:
return 140.0;
case 2:
return 120.0;
default:
return 100.0;
}
} else {
return 0;

View File

@ -69,7 +69,6 @@ class PlatformHolder {
levelHolder[j].remove();
levelHolder[j].sprite.remove();
levelHolder.removeAt(j);
print("removed platform");
}
void removePast(MyGame gameRef) {

View File

@ -10,8 +10,8 @@ class Wire extends MovingObject {
SpriteAnimation normal = SpriteAnimation.fromFrameData(
wire,
SpriteAnimationData.sequenced(
amount: 6,
stepTime: 0.1,
amount: 12,
stepTime: 0.05,
textureSize: Vector2(512, 512),
),
);

View File

@ -23,6 +23,13 @@ import 'package:flutter/foundation.dart' show kIsWeb;
const COLOR = const Color(0xFFDDC0A3);
const LEVEL2 = 10000000;
const LEVEL3 = 20000000;
const LEVEL4 = 30000000;
const LEVEL5 = 40000000;
const LEVEL6 = 50000000;
const LEVEL7 = 60000000;
const RUNNER_PRIORITY = 100;
const PLATFORM_PRIORITY = 50;
const WIRE_PRIORITY = 25;
@ -74,7 +81,6 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
await bugHolder.loadBugs();
gameState = GameState();
await gameState.load(size);
runner = Runner();
await runner.load(loadSpriteAnimation);
@ -187,7 +193,6 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
@override
void render(Canvas canvas) {
gameState.render(canvas);
circuitBackground.render(canvas);
super.render(canvas);
final fpsCount = fps(1);
@ -222,10 +227,6 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
void onResize(Vector2 size) {
super.onResize(size);
blockSize = size.y / 9;
if (loaded) {
gameState.setSize(size);
}
}
// Mobile controls