diff --git a/assets/images/bg.png b/assets/images/bg.png index 9d9278b..0c3b3a4 100644 Binary files a/assets/images/bg.png and b/assets/images/bg.png differ diff --git a/assets/images/windows-0.png b/assets/images/windows-0.png new file mode 100644 index 0000000..466477a Binary files /dev/null and b/assets/images/windows-0.png differ diff --git a/assets/images/windows-1.png b/assets/images/windows-1.png new file mode 100644 index 0000000..8243c0f Binary files /dev/null and b/assets/images/windows-1.png differ diff --git a/assets/images/windows-2.png b/assets/images/windows-2.png new file mode 100644 index 0000000..43c7da9 Binary files /dev/null and b/assets/images/windows-2.png differ diff --git a/assets/images/windows-3.png b/assets/images/windows-3.png new file mode 100644 index 0000000..8df6bae Binary files /dev/null and b/assets/images/windows-3.png differ diff --git a/assets/images/windows-4.png b/assets/images/windows-4.png new file mode 100644 index 0000000..6328ac4 Binary files /dev/null and b/assets/images/windows-4.png differ diff --git a/assets/images/windows-5.png b/assets/images/windows-5.png new file mode 100644 index 0000000..9414cc4 Binary files /dev/null and b/assets/images/windows-5.png differ diff --git a/assets/images/windows-6.png b/assets/images/windows-6.png new file mode 100644 index 0000000..77d16e7 Binary files /dev/null and b/assets/images/windows-6.png differ diff --git a/assets/images/wire-frames.png b/assets/images/wire-frames.png index 66fc018..14e1425 100644 Binary files a/assets/images/wire-frames.png and b/assets/images/wire-frames.png differ diff --git a/lib/CircuitBackground.dart b/lib/CircuitBackground.dart index a86a864..b157faf 100644 --- a/lib/CircuitBackground.dart +++ b/lib/CircuitBackground.dart @@ -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); } } diff --git a/lib/GameState.dart b/lib/GameState.dart index 13e7b83..c88003c 100644 --- a/lib/GameState.dart +++ b/lib/GameState.dart @@ -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; diff --git a/lib/PlatformHolder.dart b/lib/PlatformHolder.dart index 2a12580..33aec47 100644 --- a/lib/PlatformHolder.dart +++ b/lib/PlatformHolder.dart @@ -69,7 +69,6 @@ class PlatformHolder { levelHolder[j].remove(); levelHolder[j].sprite.remove(); levelHolder.removeAt(j); - print("removed platform"); } void removePast(MyGame gameRef) { diff --git a/lib/Wire.dart b/lib/Wire.dart index 5de2fe2..59e1244 100644 --- a/lib/Wire.dart +++ b/lib/Wire.dart @@ -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), ), ); diff --git a/lib/main.dart b/lib/main.dart index d5d9ec5..736cc51 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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