Added the finished platforms and updated how to decide which version is used.
Before Width: | Height: | Size: 372 KiB |
Before Width: | Height: | Size: 395 KiB |
Before Width: | Height: | Size: 397 KiB |
BIN
assets/images/platform-left-nowire-frames.png
Normal file
After Width: | Height: | Size: 264 KiB |
BIN
assets/images/platform-left-wire-frames.png
Normal file
After Width: | Height: | Size: 331 KiB |
BIN
assets/images/platform-mid-nowire-frames.png
Normal file
After Width: | Height: | Size: 333 KiB |
BIN
assets/images/platform-mid-wire-frames.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
assets/images/platform-right-nowire-frames.png
Normal file
After Width: | Height: | Size: 297 KiB |
BIN
assets/images/platform-right-wire-frames.png
Normal file
After Width: | Height: | Size: 365 KiB |
BIN
assets/images/platform-single-nowire-frames.png
Normal file
After Width: | Height: | Size: 365 KiB |
BIN
assets/images/platform-single-wire-frames.png
Normal file
After Width: | Height: | Size: 444 KiB |
@ -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),
|
||||
|
@ -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<Function> 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<Platform> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<List<Platform>> 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;
|
||||
|
@ -41,7 +41,7 @@ class Runner extends Component with HasGameRef<MyGame> {
|
||||
);
|
||||
|
||||
setSize(runnerSize, gameRef.blockSize);
|
||||
runnerPosition = Vector2(gameRef.blockSize, gameRef.blockSize * 4);
|
||||
runnerPosition = Vector2(gameRef.blockSize * 2, gameRef.blockSize * 4);
|
||||
setPosition(runnerPosition);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|