diff --git a/assets/images/p1-frames.png b/assets/images/p1-frames.png deleted file mode 100644 index 551945d..0000000 Binary files a/assets/images/p1-frames.png and /dev/null differ diff --git a/assets/images/p2-frames.png b/assets/images/p2-frames.png deleted file mode 100644 index 0710d46..0000000 Binary files a/assets/images/p2-frames.png and /dev/null differ diff --git a/assets/images/p3-frames.png b/assets/images/p3-frames.png deleted file mode 100644 index b2a2f39..0000000 Binary files a/assets/images/p3-frames.png and /dev/null differ diff --git a/assets/images/platform-left-nowire-frames.png b/assets/images/platform-left-nowire-frames.png new file mode 100644 index 0000000..356b3a3 Binary files /dev/null and b/assets/images/platform-left-nowire-frames.png differ diff --git a/assets/images/platform-left-wire-frames.png b/assets/images/platform-left-wire-frames.png new file mode 100644 index 0000000..c2828c3 Binary files /dev/null and b/assets/images/platform-left-wire-frames.png differ diff --git a/assets/images/platform-mid-nowire-frames.png b/assets/images/platform-mid-nowire-frames.png new file mode 100644 index 0000000..948b896 Binary files /dev/null and b/assets/images/platform-mid-nowire-frames.png differ diff --git a/assets/images/platform-mid-wire-frames.png b/assets/images/platform-mid-wire-frames.png new file mode 100644 index 0000000..1295a90 Binary files /dev/null and b/assets/images/platform-mid-wire-frames.png differ diff --git a/assets/images/platform-right-nowire-frames.png b/assets/images/platform-right-nowire-frames.png new file mode 100644 index 0000000..86b0020 Binary files /dev/null and b/assets/images/platform-right-nowire-frames.png differ diff --git a/assets/images/platform-right-wire-frames.png b/assets/images/platform-right-wire-frames.png new file mode 100644 index 0000000..0883f18 Binary files /dev/null and b/assets/images/platform-right-wire-frames.png differ diff --git a/assets/images/platform-single-nowire-frames.png b/assets/images/platform-single-nowire-frames.png new file mode 100644 index 0000000..094d768 Binary files /dev/null and b/assets/images/platform-single-nowire-frames.png differ diff --git a/assets/images/platform-single-wire-frames.png b/assets/images/platform-single-wire-frames.png new file mode 100644 index 0000000..4875eff Binary files /dev/null and b/assets/images/platform-single-wire-frames.png differ diff --git a/lib/Coin.dart b/lib/Coin.dart index 5adaab4..755e934 100644 --- a/lib/Coin.dart +++ b/lib/Coin.dart @@ -25,7 +25,7 @@ class Coin extends MovingObject { sprite.changePriorityWithoutResorting(COIN_PRIORITY); - var platform = gameRef.platformHolder.getPlatform(0); + var platform = gameRef.platformHolder.l1; setSize( gameRef.blockSize * (platform!.width / platform!.height / 14), diff --git a/lib/Platform.dart b/lib/Platform.dart index 9e1e8be..1cc9973 100644 --- a/lib/Platform.dart +++ b/lib/Platform.dart @@ -4,35 +4,75 @@ import 'package:firo_runner/MovingObject.dart'; import 'package:firo_runner/main.dart'; import 'package:flame/components.dart'; -enum PlatformState { normal } +enum PlatformState { + left, + mid, + right, + single, +} class Platform extends MovingObject { + int row = 0; List removeChildren = []; Platform(MyGame gameRef) : super(gameRef) { var random = Random(); - int version = random.nextInt(3) + 1; - var platform = gameRef.platformHolder.getPlatform(version); - SpriteAnimation normal = SpriteAnimation.fromFrameData( - platform, + + int version = random.nextInt(2); + + SpriteAnimation left = SpriteAnimation.fromFrameData( + version == 0 ? gameRef.platformHolder.l1 : gameRef.platformHolder.l2, SpriteAnimationData.sequenced( - amount: 7, - stepTime: 0.1, - textureSize: Vector2(800, 510), + amount: 5, + stepTime: 0.12, + textureSize: Vector2(1000, 807), + ), + ); + + SpriteAnimation mid = SpriteAnimation.fromFrameData( + version == 0 ? gameRef.platformHolder.m1 : gameRef.platformHolder.m2, + SpriteAnimationData.sequenced( + amount: 5, + stepTime: 0.12, + textureSize: Vector2(1000, 807), + ), + ); + + SpriteAnimation right = SpriteAnimation.fromFrameData( + version == 0 ? gameRef.platformHolder.r1 : gameRef.platformHolder.r2, + SpriteAnimationData.sequenced( + amount: 5, + stepTime: 0.12, + textureSize: Vector2(1000, 807), + ), + ); + + SpriteAnimation single = SpriteAnimation.fromFrameData( + version == 0 ? gameRef.platformHolder.o1 : gameRef.platformHolder.o2, + SpriteAnimationData.sequenced( + amount: 5, + stepTime: 0.12, + textureSize: Vector2(1000, 807), ), ); sprite = SpriteAnimationGroupComponent( animations: { - PlatformState.normal: normal, + PlatformState.left: left, + PlatformState.mid: mid, + PlatformState.right: right, + PlatformState.single: single, }, - current: PlatformState.normal, + current: PlatformState.single, ); sprite.changePriorityWithoutResorting(PLATFORM_PRIORITY); setSize( - gameRef.blockSize * (platform!.width / platform!.height / 7), + gameRef.blockSize * + (gameRef.platformHolder.l1!.width / + gameRef.platformHolder.l1!.height / + 5), gameRef.blockSize, ); } @@ -48,4 +88,35 @@ class Platform extends MovingObject { } } } + + @override + void update(double dt) { + List platformLevel = gameRef.platformHolder.platforms[row]; + int index = platformLevel.indexOf(this); + Vector2 right = Vector2(-200, -200); + if (index + 1 < platformLevel.length) { + right = platformLevel.elementAt(index + 1).sprite.position; + } + super.update(dt); + if (index == -1 || sprite.position.x <= 0) { + return; + } + Vector2 left = Vector2(-200, -200); + if (index - 1 >= 0) { + left = platformLevel.elementAt(index - 1).sprite.position; + } + + 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; + + if (hasLeft && hasRight) { + sprite.current = PlatformState.mid; + } else if (hasLeft && !hasRight) { + sprite.current = PlatformState.right; + } else if (!hasLeft && hasRight) { + sprite.current = PlatformState.left; + } else { + sprite.current = PlatformState.single; + } + } } diff --git a/lib/PlatformHolder.dart b/lib/PlatformHolder.dart index 33aec47..a57c410 100644 --- a/lib/PlatformHolder.dart +++ b/lib/PlatformHolder.dart @@ -5,16 +5,26 @@ import 'package:flame/flame.dart'; import 'Platform.dart'; class PlatformHolder { - var platform1; - var platform2; - var platform3; + var l1; + var l2; + var m1; + var m2; + var r1; + var r2; + var o1; + var o2; late List> platforms = []; Random random = Random(); Future loadPlatforms() async { - platform1 = await Flame.images.load('p1-frames.png'); - platform2 = await Flame.images.load('p2-frames.png'); - platform3 = await Flame.images.load('p3-frames.png'); + l1 = await Flame.images.load('platform-left-nowire-frames.png'); + l2 = await Flame.images.load('platform-left-wire-frames.png'); + m1 = await Flame.images.load('platform-mid-nowire-frames.png'); + m2 = await Flame.images.load('platform-mid-wire-frames.png'); + r1 = await Flame.images.load('platform-right-nowire-frames.png'); + r2 = await Flame.images.load('platform-right-wire-frames.png'); + o1 = await Flame.images.load('platform-single-nowire-frames.png'); + o2 = await Flame.images.load('platform-single-wire-frames.png'); } void setUp() { @@ -29,17 +39,6 @@ class PlatformHolder { } } - getPlatform(int imageNumber) { - switch (imageNumber) { - case 1: - return platform1; - case 2: - return platform2; - default: - return platform3; - } - } - bool generatePlatform(MyGame gameRef, int level, bool force) { double xCoordinate = 0; if (platforms[level].isNotEmpty) { @@ -51,6 +50,7 @@ class PlatformHolder { } else { Platform platform = Platform(gameRef); platform.setPosition(xCoordinate, gameRef.blockSize * level); + platform.row = level; gameRef.add(platform.sprite); platforms[level].add(platform); return false; diff --git a/lib/Runner.dart b/lib/Runner.dart index 2ea257d..002a08c 100644 --- a/lib/Runner.dart +++ b/lib/Runner.dart @@ -41,7 +41,7 @@ class Runner extends Component with HasGameRef { ); setSize(runnerSize, gameRef.blockSize); - runnerPosition = Vector2(gameRef.blockSize, gameRef.blockSize * 4); + runnerPosition = Vector2(gameRef.blockSize * 2, gameRef.blockSize * 4); setPosition(runnerPosition); } diff --git a/lib/WireHolder.dart b/lib/WireHolder.dart index c4adb35..ad8153a 100644 --- a/lib/WireHolder.dart +++ b/lib/WireHolder.dart @@ -65,7 +65,7 @@ class WireHolder { if (level % 3 == 0) { wire.sprite.renderFlipY = true; wire.setPosition( - xCoordinate, gameRef.blockSize * level - gameRef.blockSize / 6); + xCoordinate, gameRef.blockSize * level - 2 * gameRef.blockSize / 7); } else { wire.setPosition( xCoordinate, gameRef.blockSize * level + gameRef.blockSize / 10);